Tag Info

Hot answers tagged

6

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


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

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 ...


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, ...


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.


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 ...


2

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


1

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}]] ]


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 ...


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 = ...


1

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


1

evenCycleTest[g_: Graph] := AnyTrue[Flatten@FindCycle[g, #] & /@ Range[2, VertexCount[g], 2], # != {} &] Examples: g = Graph[RandomGraph[{20, 49}]]; evenCycleTest[g] True h = StarGraph[20]; evenCycleTest[h] False



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