# Tag Info

9

This answer is a modification of my answer given in the discussion Creating Identification/Classification trees. With this solution I am trying to achieve the simplification by using the impurity function applied to the data (the truth table in this case). Make the truth table from the linked Wikipedia article (Binary Decision Diagram): truthTable = {{0, ...

8

Perhaps it's a nuisance (bug?) of RandomGraph[ ]. Here is a way to force it: g = Graph[VertexList@#, EdgeList@#] &@RandomGraph[{1, 0}]; g1 = VertexAdd[g, 2]; g2 = EdgeAdd[g1, UndirectedEdge[1, 2]]

8

The idea is simple: we take the graph made by TreePlot and we change (the coordinates of) the points for the graph nodes into more regularly spaced points. The solution below attempts to be somewhat robust. The arguments and options taken by TreePlot can be used. There is a check for can the symmetric layout of the binary tree be done in a such a way ...

7

The following changes to your code will produce the desired graph: Change GraphLayout to "SpringElectricalEmbedding" instead of Automatic Instead of using a list of symbols like {A, C, G, T}, use strings and concatenate them for the labels. VertexSize with a single value uses the same size for all vertices. Instead, use VertexShapeFunction with a random ...

6

There are several Graph-related bugs that show up only for certain graphs, most likely due to how these graphs are stores internally. There are several possible internal graph representations used by Mathematica. When you find that something like this happens, try recreating the graph in one of several possible ways: g = Uncompress@Compress[g] will ...

5

Graph[Range@10, {1 -> 2, 2 -> 3, 3 -> 1}]

5

The problem of finding the variable order that minimizes the number of nodes in a given reduced ordered binary decision diagram is NP-hard. So, it is typically not used very much. It is implemented in CUDD as CUDD_REORDER_EXACT. Rudell's sifting is the algorithm most frequently used. In both a brute force computation of the optimal order, as well as ...

5

You can first define a function that translates your edge label into a color. You can then use this function with Style to plot the colored graph. d = Import["..\\sample_el.txt", "Table"]; EdgeStyleColor[c_] := Switch[c, 1, Red, 2, Blue, 3, Green]; Graph[Style[#1 <-> #2, EdgeStyleColor[#3]] & @@@ d]

4

Belisarius already showed how to build a graph with unconnected vertices, and you asked about their positioning. If you prefer a different arrangement of the unconnected vertices (or the connected components in general), take a look at the "PackingLayout" suboption of GraphLayout. The documentation has examples. Mathematica is smart about graph layouts: it ...

4

You can use the CanonicalGraph function in concert with DeleteDuplicatesBy: DeleteIso[gs_List] := DeleteDuplicatesBy[gs, CanonicalGraph]

3

edgetypelist = {{1, 2, Red}, {1, 3, Green}, {2, 3, Red}, {2, 4, Blue}} myedgelist = Style[UndirectedEdge[#[[1]], #[[2]]], #[[3]]] & /@ edgetypelist Graph[Range[4], myedgelist] If your edge type is an integer (1,2,3), then proceed as follows: rawedgelist = Table[{RandomInteger[15], ...

3

Further to Szabolcs's post, EdgeWeight with SpringElectricalEmbedding works the opposite way to what you might expect. A weight of 2 results in an edge that is twice as long as for a weight of 1. In other words, the higher the weight, the weaker the spring and the more separation between the nodes. If you want a higher value to represent a stronger, shorter ...

3

One (not particularly efficient) way that occurs to me is to first find the biconnected components of a graph g, for which there is a built-in function (KVertexConnectedComponents). Then, use the fact that a vertex is a cut vertex if and only if it appears in two biconnected components. components = KVertexConnectedComponents[g, 2]; cutVertices = ...

2

IGraph/M has the function IGArticulationPoints. g = PathGraph[{1, 2, 3, 4}, VertexLabels -> "Name"] IGArticulationPoints[g] (* {3, 2} *) Speed comparison with KVertexConnectedComponents[g,2] for tiny and huge graphs. The timings are for IGraph/M 0.1.5. g = ExampleData[{"NetworkGraph", "CondensedMatterCollaborations2005"}]; {VertexCount[g], ...

2

If it's only for visualization, you can set GraphHighlightStyle -> "DehighlightHide" : HighlightGraph[gr, Graph[sub], GraphHighlightStyle -> "DehighlightHide"]

2

This is a great question, and surely a function that should be implemented in Mathematica already. To solve the problem, let us proceed in two phases: Compute the chromatic number $\chi(G)$ of the graph $G$. Iterate over all possible $\chi(G)$-colorings, and choose the first valid one. From this answer, we know how to compute the chromatic number: ...

2

Generate all possible adjacency matrices: n = 4; adjmat = Table[Partition[IntegerDigits[i, 2, n^2], 4], {i, 0, 2^(n^2) - 1}]; Remove ones containing self-loops: adjmat = Select[adjmat, Diagonal[#] == ConstantArray[0, n] &]; Make graph list: glist = AdjacencyGraph[#, DirectedEdges -> True] & /@ adjmat; Remove isomorphic duplicates: glist ...

2

This is a well-known NP-hard problem known as Steiner tree. The problem is computationally difficult from many viewpoints. So, it is good to remember that it is highly unlikely to get a fast algorithm to handle every case. Let me present a brute-force method with one small heuristic. The algorithm is an exact one, i.e., it is guaranteed to find the optimal ...

2

The problem in your code is that you have imported the data as a single String, not as table of rules as you expected. See that by evaluating StringQ[friends]. One solution is this: friends = Import[ "https://www.dropbox.com/s/hq8twoz2ct99kzr/friends.txt?dl=1" ,"Table" ] CommunityGraphPlot[Rule[#1, #3] & @@@ friends]

2

You could use SetProperty[{g, (11 -> 23)}, EdgeStyle -> {Arrowheads[{{-.05, .2}, {.05, .8}}]}] but since the offset is scaled relative to the line length, it's not possible in general to point the edge of the disk: You can create custom EdgeShapeFunction to replace automatic: arrow[pts : {p1_, p2_}, offset_, arrowheads_: {}] := With[{m = ...

2

Probably a bug. You may use this alternative syntax: g = Graph[{{1, 2} <-> {3, 4}}]; SetProperty[{g, {{1, 2}}}, GraphHighlight -> True]

1

I think this can be just simplified. You could relabel vertices if you wish (and make into function): tab = Import["http://algs4.cs.princeton.edu/44sp/mediumEWD.txt", "Table"]; gd = Drop[tab, 2]; g = Graph[DirectedEdge @@@ gd[[All, {1, 2}]], EdgeWeight -> gd[[All, 3]]] Checking weights: (# -> PropertyValue[{g, #}, EdgeWeight] & /@ ...

1

TreeGraph[ {11 -> 23, 11 -> 24, 23 -> 40, 23 -> 39, 24 -> 30, 24 -> 50, 40 -> 55, 40 -> 45}, VertexShapeFunction -> ({EdgeForm[White], RGBColor[113/255, 190/255, 236/255], Disk[#1, 0.2], White, Text[Style[#2, 22, Red], #1]} &)]

1

Perhaps, you can use Graph and the first (largest) element of WeaklyConnectedComponents: g1 = Graph[{1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2, 4 -> 4, 5 -> 6}, VertexShapeFunction -> "Name"] wcc = WeaklyConnectedComponents[g1] {{4, 1, 2, 3}, {5, 6}} Subgraph[g1, wcc[[1]], VertexShapeFunction -> "Name"]

1

Here's a slight refactoring of the OP's code, but the original code worked just as well. In particular I used Set (=) instead of SetDelayed (:=) for the graphs so they do not have to be recomputed each time they are used. mm[n_] := SparseArray[{k_, kk_} /; LCM[k, kk] > n -> 1, {n, n}]; g = AdjacencyGraph[Range[20], mm[20]]; gw = Graph[g, ...

1

You can also consider HighlightGraph data = Import["~/Downloads/sample_el.txt", "Table"]; edges = UndirectedEdge @@@ data[[All, {1, 2}]]; markers = data[[All, 3]]; HighlightGraph[ Graph[edges, VertexSize -> Scaled[0.003], VertexStyle -> Black], Style[Pick[edges, markers, #], ColorData[81][#]] & /@ {1, 2, 3} ] Alternatively: ...

Only top voted, non community-wiki answers of a minimum length are eligible