Tag Info

Hot answers tagged

7

The FullForm of "Rose" <-> "Nora" is: UndirectedEdge["Rose", "Nora"] and the FullForm of the list {"Rose", "Nora"} is: List["Rose", "Nora"] What you want therefore is to replace the Head of the UndirectedEdge expression with List. You can do this with Apply (shorthand: @@) List @@ UndirectedEdge["Rose", "Nora"] (* {"Rose", "Nora"} *) So you ...


6

Let me know if this doesn't cut as an answer. If your goal is a visual programming language with flow-chart paradigm - it doesn't have to be a Graph that Wolfram Language (WL) uses, but could be another dedicated flow-language that can drive WL computations. Mohamed Zaghloul is developing Mantis add-on tools for Grasshopper to link it with the Mathematica ...


5

I was surprised that Graph supports 3D coordinates at all (!!). Layout algorithms supported in Graph are 2D only. The problem doesn't seem to be with Graph itself but the Graphics3D object it translates to. Here's a smaller example of the same: Show@Graph[{1 -> 2}, VertexCoordinates -> {1 -> {0, 0, 0}, 2 -> {1, 0, 0}}] Show converts it to a ...


5

Graph and friends don't handle the case where VertexStyle has more entries than there are vertices. For some reason, you're using 27 as the upper limit of your Tables when defining input and iterating through input when providing VertexStyle, but you only have 26 vertices. The best way to avoid these kinds of problems is to avoid indexing into graphs at ...


4

If you have a notebook with the following assignment: g = Graph[{1 \[DirectedEdge] 2, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 1}, EdgeShapeFunction -> "CarvedArcArrow"] And the output is visible (note that Head[g] is Graph not Graphics and then you kill the kernel so that g is no longer assigned, you can retrieve the original graph by doing the ...


4

To answer your main question, I generated the coords as specified: coords = Flatten[ Array[(Characters@"abc")[[#]] <> ToString@#2 -> {#, #2} &, {3, 4} ], 1] {"a1" -> {1, 1}, "a2" -> {1, 2}, "a3" -> {1, 3}, "a4" -> {1, 4}, "b1" -> {2, 1}, "b2" -> {2, 2}, "b3" -> {2, 3}, "b4" -> {2, 4}, "c1" -> {3, 1}, "c2" ...


4

Wrong use of Graph in this case I believe. I think the following does what you're after: Graphics3D[{FaceForm[], EdgeForm[Blue], PolyhedronData["GreatRhombicosidodecahedron", "Faces"], PointSize[Large], Red, Point /@ PolyhedronData["GreatRhombicosidodecahedron", "VertexCoordinates"]}, Boxed -> False]


4

First note, that KatzCentrality seems to use the transpose of the adjacency matrix. KatzCentrality gives a list of centralities c that satisfy c==\[Alpha] a^\[Transpose].c+\[Beta], where a is the adjacency matrix of g. So for comparison you should use kx1 = Inverse[IdentityMatrix[Length[rA]] - 0.01*Transpose@rA].ConstantArray[1,Length[rA]]; With that ...


4

Here is a manual EdgeRenderingFunction that you can start from if you supply your labels as lists. erf = Module[{spacing = .2, transform = Last@FindGeometricTransform[#, {{0, 0}, {1, 0}}]}, {Text[#, transform[{1/2, #2}]], GeometricTransformation[ Arrow[BSplineCurve[{{0, 0}, {1/3, #2}, {2/3, #2}, {1, 0}}, ...


4

I understand that you want the subgraph of g that corresponds to the vertices in one of the w.c.c (say, the first one). How about: Subgraph[g, First@WeaklyConnectedComponents[g]] If you want, say, the 13th connected component, just do Subgraph[g, WeaklyConnectedComponents[g][[13]] ]


3

To simulate the situation, evaluate the following expression and then quit the kernel: $graph = RandomGraph[{50, 50}] We can verify that $graph no longer holds the graph by observing its syntax coloring, or by evaluating it. To recover the graph, enter and evaluate the following expression in a new input cell directly below the output cell that holds ...


2

Not completely sure I'm understanding. Anyway, for Directed Graphs without self loops: randomDegreeGraph[m_List] := Module[{n, t, t1, obj, s, x}, n = Length@m; t = Table[If[i != j, x[i, j], Sequence @@ {}], {i, n}, {j, n}]; t1 = Table[If[i != j, x[i, j], 0], {i, n}, {j, n}]; obj = Transpose[{List /@ m, t}]; t1 /. ...


2

You can use igraph through my RLink-based package IGraphR. mat = Import["https://dl.dropboxusercontent.com/u/62056077/TestMatrix.m", "Package"]; mat == Transpose[mat] (* ==> False *) Your adjacency matrix is not symmetric. Are you looking for directed or undirected graphs? degs = Total[mat]; This degree sequence happens to be graphical, so let's ...


2

This comes with several caveats: (1) It is also often slow. I have reason to believe it gets careless about certain "painted into a corner" situations, and thus might simply fail. (2) It gives results that are in no sense uniformly random, across the range of possible graphs that meet the requirements. (3) I wrote it some time ago and no longer understand ...


2

Here's how to do it: pairs = ImportString[ "A, B A, C B, D C, E C, F C, G D, F", "CSV"] edges = UndirectedEdge @@@ pairs Graph[edges] For information on what each of the pieces does, look them up in the documentation centre. Graph is the new way to represent graphs, introduced in version 8. GraphPlot is older functionality, mostly ...


2

Let me give a short and readable implementation which uses the function nextLevel as its core. It's only three small lines which need to be understood: nextLevel[{v_, _}, n_] := Block[{c = Last[v] + 1, ids, i = 1}, ids = Range[c, c + Length[v]*n - 1]; {ids, Table[UndirectedEdge[k, ids[[i++]]], {k, v}, {n}]} ]; The function nextLevel takes a list of ...


2

First let's take a RandomGraph: SeedRandom@1; g = RandomGraph[BarabasiAlbertGraphDistribution[10, 2], VertexLabels -> "Name", ImagePadding -> 20] list = Reverse@SortBy[ Thread[{Range@VertexCount@g, VertexDegree[g]}], Last@# &] (*{vi, vertexdegree@i}*) {{1, 7}, {2, 6}, {6, 5}, {4, 4}, {10, 2}, {9, 2}, {8, 2}, ...


2

Here's the brute force way: og = CirculantGraph[100, Range[2]]; g = RandomGraph[WattsStrogatzGraphDistribution[100, 0.05]]; oelist = Sort /@ EdgeList[og]; elist = Sort /@ EdgeList[g]; rewired = Complement[oelist, elist] {4 <-> 6, 19 <-> 20, 21 <-> 23, 26 <-> 27, 31 <-> 32, 33 <-> 35, 44 <-> 45, 55 <-> 56, 56 <-> 58, ...


1

From the docs on AdjacencyMatrix: Rows and columns of the adjacency matrix follow the order given by VertexList And from the docs on VertexList: Vertices are taken in the order they appear in the list of edges. Thus, you have {VertexList[g1], VertexList[g2]} (* {{1, 2, 3, 4, 5, 6, 7, 8}, {1, 6, 7, 8, 2, 3, 4, 5}} *) So, you can give an ...


1

<< Combinatorica` g = CompleteGraph[4]; c = EdgeColoring[g]; colors = ColorData[1, "ColorList"] (* say *); ShowGraph[g, VertexLabel -> True, EdgeColor -> colors[[c]]] For graphs in GraphData[], you can use the "MinimumEdgeColoring" property: g2 = GraphData[{"Complete", 4}]; c2 = GraphData[{"Complete", 4}, "MinimumEdgeColoring"]; edges = ...


1

Updated: vList = Map[StringJoin, Tuples[{"0", "1", "2"}, 4]]; testF = EditDistance[#[[1]], #[[2]]] > 3 && StringReverse[#[[1]]] == #[[2]] &; e1 = vList[[#]] & /@ (SparseArray[{{i_, j_} /; (i>j&&testF[{vList[[i]], vList[[j]]}]) -> 1}, Length@vList {1, 1}]["NonzeroPositions"]); (* or *) e2 = Select[Subsets[vList, {2}], ...


1

This does what you want. Not recursive (no real need). maketree[spec_] := Flatten[Function[edg, MapThread[Thread[#1 \[UndirectedEdge] #2] &, {First@edg, Partition[Last@edg, Length@Last@edg/Length@First@edg]}]] /@ Partition[FoldList[Range[Max[#] + 1, Max[#] + 1 + Length@#*#2 - 1] &, {spec[[1]]}, ...



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