Tag Info

New answers tagged

1

In Mathematica, however, the search is simple, for instance: GraphData[{"Bicubic", "Asymmetric", "Planar"}] (* {{"Cubic", {24, 3}}, {"Cubic", {54, 1}}, {"CubicPolyhedral", 9}, {"CubicPolyhedral", 18}, {"CubicPolyhedral", 42}, {"CubicPolyhedral", 50}, "GreatRhombicosidodecahedralGraph", \ "GreatRhombicuboctahedralGraph", {"Prism", 6}, {"Prism", ...


1

If you want a purely matrix-based approach, you can try: m = {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}; AdjacencyGraph[m, VertexLabels -> "Name"] ADD = {1, 2}; VADD = 0 Range[Length[m]]; For[i = 1, i <= Length[ADD], i++, VADD[[i]] = 1]; m = Append[m, VADD]; VADD = Append[VADD, 0]; m = Transpose[Append[Transpose[m], VADD]] AdjacencyGraph[m, VertexLabels -> ...


2

Perhaps you can use EdgeAdd and/or VertexAdd. For example: am1 = {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}; ag1 = AdjacencyGraph[am1, VertexLabels -> Placed["Name", Center], VertexSize -> Medium] ag2 = EdgeAdd[ag1, 2 <-> 4] AdjacencyMatrix[ag1] // Normal (* {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}} *) AdjacencyMatrix[ag2] // Normal (* {{0, 1, 1, 0}, ...


1

More is better, other variation: upDateColor[g_] := Block[{color, vlist, c}, color = Association[PropertyValue[g, VertexStyle]]; vlist = VertexList[g]; SetProperty[g, VertexStyle -> Table[v -> If[Length[c = Commonest[color /@ AdjacencyList[g, v]]] == 1, First[c], color[v]], {v, vlist}]] ]


5

Update: The original post below computes the commonest color in the NeighborhoodGraph of a vertex v including the vertex v itself. To exclude a vertex in counting the colors in its neighborhood, we can use the following helper function: ClearAll[newClrF]; newClrF = Module[{nc=#, oc=First@#, c1= Commonest[Rest@#][[1]], c2= Quiet@Commonest[Rest@#, 2]}, ...


4

First, let's whip up a random graph: n = RandomInteger[{10, 15}]; m = RandomInteger[{Floor[n^2/20], n (n - 1)/2}]; G = RandomGraph[{n, m}]; For[i = 1, i <= n, i++, chi[0, i] = {Red, Blue}[[RandomInteger[] + 1]] ]; Graph[G, VertexStyle -> Table[i -> chi[0, i], {i, 1, n}]] The coloring at step k will be denoted chi[k,i], where i indicates a ...


0

With V10, you can use a combination of FindPath and GraphDistance. A (hopefully) self-explanatory example: g = RandomGraph[{15, 44}, VertexLabels -> "Name"]; s = 1; t = 2; FindPath[g, s, t, {GraphDistance[g, s, t]}, All] HighlightGraph[g, %] In short, we find all paths between $s$ and $t$ of distance $d(s,t)$.


6

Update 2: Dealing with the issue raised by @Kuba in the comments: Using the function LineScaledCoordinates from the GraphUtilities package to place the text labels: Needs["GraphUtilities`"] labels ={"A", "B", "C", "D", "E", "F"}; i = 1; Graph[{a -> b, a -> b, a -> b, a -> b, a -> e, e -> b}, EdgeShapeFunction -> ...


5

This ****, and so does my answer, but if it works it's not stupid, right? :) p = Graph[{Labeled[a -> b, "A"], Labeled[a -> b, "B"]}]; grp = GraphComputation`GraphConvertToGraphics[p]; ReplacePart[grp, Position[grp, "A"][[1]] -> "B"]


4

It appears that in Mathematica 10.0.2 Graph does not natively support this by way of wrappers such as Labeled. Note that each of these wrappers is converted to a canonical form that seems to support only one directive for each edge: Table[ InputForm @ Graph[{fn[a -> b, "A"], fn[a -> b, "B"]}], {fn, {Labeled, Annotation, Tooltip, Style, Hyperlink, ...


1

You can do this using GroupMultiplicationTable. For example, take the group: G = AbelianGroup[{2, 3}]; CayleyGraph[G] That will get you two three-cycles, connected by transpositions (hence {2,3}). But this group is cyclic, it should be able to be generated by a single element of order six. To do that, you could either do the obvious: G2 = ...


2

Here is an attempt with roughly $O(n^{1.6})$ runtime complexity. First, let n be the number of nodes, m be the number of out-edges from each node, p the randomness parameter in the paper you linked, and iD be the in-degrees of each node. For initialization, I'll let the first m nodes have in-degree 1: SetSystemOptions["SparseArrayOptions" -> ...


2

The node numbering in the matrix are actually listed as VertexList[r] , which is {1, 2, 4, 3, 5, 6, 7} I am not sure why Mathematica does it this way, it does not seem natural to me. r = Graph[{1 <-> 2, 1 <-> 4, 2 <-> 3, 3 <-> 4, 3 <-> 5, 5 <-> 6, 5 <-> 7}, VertexLabels -> "Name"]; To reorder the ...


0

Yet another way using GraphDistanceMatrix: edges = {1 -> 3, 1 -> 4, 2 -> 4, 2 -> 5, 3 -> 5, 6 -> 7, 7 -> 8, 8 -> 9, 9 -> 10, 6 -> 10, 1 -> 6, 2 -> 7, 3 -> 8, 4 -> 9, 5 -> 10}; If mygraph = Graph@edges; vertex = VertexList@mygraph; graphdist = GraphDistanceMatrix@mygraph; then {vertex, Pick[##, Except[_List ...


0

matrix = {1 <-> 2, 2 <-> 3, 3 <-> 1}; labels = {1 -> "One", 2 -> "Two", 3 -> "Three"}; You can modify labels programmatically using labels1 = (# -> Placed[#2, Tooltip] & @@@ labels); or using labels2 = MapAt[Placed[#, Tooltip] &, labels, {All, -1}]; Alternatively, you can use the function Property to set the ...


0

What if you used the orientation of the triangle as a clue to choosing sides? TriangleOrientation[{x1_, y1_}, {x2_, y2_}, {x3_, y3_}] := Sign[x3 (y1 - y2) + x1 (y2 - y3) + x2 (-y1 + y3)] Any triangle in your mesh has three sides, say vertices U to V, V to W, and W back to U. Say your current midpoint is in side $k$, where $k=1$, $2$, or $3$. If the ...


1

Until this feature is implemented in Mathematica, you can use igraph through my package IGraphR (which is really just relying on the power of RLink). Start by looking up the isomorphism testing function on the igraph documentation page. It is called graph.isomorphic. IGraphR and igraph do support multiple edges, including for isomorphism testing. Then ...


3

VertexOutComponent gives VertexOutComponent[g, b, 1] (* {b, d, e} *) This is precisely what you are looking for, plus the vertex b itself.


3

As halmir commented the documentation of EdgeStyle notes the following possible issue: Thus you should use \[DirectedEdge]: Graph[ {"ftr1" \[DirectedEdge] "ftr2", "ftr2" \[DirectedEdge] "ftr3", "ftr3" \[DirectedEdge] "ftr4"}, EdgeStyle -> {"ftr1" \[DirectedEdge] "ftr2" -> Black, "ftr2" \[DirectedEdge] "ftr3" -> Blue, ...


3

IsomorphicGraphQ and CanonicalGraphQ don't yet support multigraphs (graphs that have more than one edge spanning two nodes). It's a known limitation and I believe it will come in a future release.


3

You can use VertexDelete[g, Pick[VertexList[g], VertexDegree[g], d_ /; d < 2]] which I expect to have better performance, but I haven't benchmarked.


6

g = Graph[{1 -> 2, 2 -> 3, 3 -> 1, 2 -> 4}, VertexShapeFunction -> "Name"] VertexDegree[g] (* {2, 3, 2, 1} *) VertexDelete[g, _?(VertexDegree[g, #] < 2 &)]


1

Check the background section of FindCycle documentation: FindCycle returns simple cycles, while FindHamiltonianCycle, FindEulerianCycle, and FindFundamentalCycles return specific types of cycles.



Top 50 recent answers are included