New answers tagged

1

framedWithColor[color_] := Function[{position, label}, {Text[Framed[label, Background -> color], position]} ]; TreeForm[ {{1, 2}, {3, 4}}, VertexRenderingFunction -> framedWithColor[Pink] ]


7

i = RemoveAlphaChannel@Import@"http://i.stack.imgur.com/k8KCQ.png"; cs = ColorSeparate@i; vxs = Binarize@ImageSubtract[cs[[1]], cs[[2]]]; vxPos = ComponentMeasurements[vxs, "Centroid"][[All, 2]]; rad = ComponentMeasurements[vxs, "EquivalentDiskRadius"][[All, 2]] // Mean // Ceiling; graph = SelectComponents[ColorNegate@Binarize@i, "Area", ...


1

This might be deprecated functionality, but it used to work: << GraphUtilities` GraphEdit[]


1

This is a bit extra as there is the sidebar having the commented urls linked but they may get deleted if the comments deleted so gathering all useful material in comments below. Relevant topics Generating graphs interactively with GUI in Mathematica How to add new nodes to an existing graph with fixed (coordinates) nodes? Dupes Possible to manipulate ...


0

Trials Trial 1. Failures in trying to remove vertices fom HararyGraph. The structure is not preserved for which SetProperty (?) and the repetitive assignment after each removal failing -- the table below removes the other vertex from new graph not from the one where one vertex was already removed. Trial 2. Failure in trying to remove vertices ...


1

A possible solution: RandomBipartiteGraph[m_, n_, e_] := Graph[Range[m + n], RandomSample[Flatten@Table[i <-> j, {i, m}, {j, m + 1, m + n}], e]] But I wonder if I can do it with some of Mathematica built-in graph generator functions?


6

No, this is not a bug in VertexDelete. Some background first: TreePlot, along with GraphPlot, is an old function that predates the introduction of Graph objects. Consider it deprecated that is only kept for backwards compatibility. The proper way to display vertex labels for a Graph object is g = CompleteKaryTree[5, DirectedEdges -> True, ...


2

There is no bug. Vertices 11 and 12 were indeed deleted from a. a = CompleteKaryTree[5, DirectedEdges -> True]; VertexList@a {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31} c = VertexDelete[a, {11, 12}]; VertexList@c {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, ...


6

You can also use FindHamiltonianCycle. To convert Hamiltonian path problem to Hamiltonian cycle problem, just add one vertex and connect it to all other vertices. After that just run FindHamiltonianCycle[g, All] For example, countHamiltonianPaths[g_] := Length[ FindHamiltonianCycle[ AdjacencyGraph[PadRight[AdjacencyMatrix[g], (VertexCount[g] + ...


2

This is the same basic algorithm but in my own style. It runs only about twice as fast as yours, but hopefully it will be of interest anyway. The recursive function count maintains the current vertex, the adjacency list $a$ and a counter $i$. At each call the current vertex is removed from the adjacency list and the function recursively scanned over the ...


8

Normal[# /. a : Arrow[{__List}, Except[_List]] :> Thread @ a] gives a quick fix for these examples.


4

Set a graph with properties: g = Graph[{Property[1, "Custom" -> {3700, "h1"}], Property[2, "Custom" -> {3700, "h2"}], Property[3, "Custom" -> {3700, "h2"}]}, {1 <-> 2, 2 <-> 3, 3 <-> 1}]; Define labels: labels = # -> Placed[ToString[PropertyValue[{g, #}, "Custom"], InputForm], StatusArea] & /@ ...


3

Check GraphData. Get a list of names with this command: Intersection[ GraphData["Planar"], GraphData["Traceable"] ] Apply GraphData to a name to get the graph.


16

Edit: getting rid of FilledCurve to speed things up. Here's something fun: g = Normal @ Show @ CommunityGraphPlot[ ExampleData[{"NetworkGraph", "DolphinSocialNetwork"}] ]; dist = Normalize[#] (2./Pi ArcTan[Norm[5 #]]) &; DynamicModule[{drag,pts,prims} , pts = Union@Cases[g, {_?NumericQ, _?NumericQ}, \[Infinity]]; prims = ( First[g] ...


17

You can do this using Show and PlotRange which can be used in combination with graphs. To determine the full PlotRange of the original Graph you could use AbsoluteOptions to determine the values of the VertexCoordinates of the graph. The function CoordinateBoundingBox, introduced in V10.1, is helpful here: SeedRandom[1110]; g = RandomGraph[{70, 200}] ...


3

For example (Partial order here is vertex reachability) SeedRandom@42; << Combinatorica` g = System`RandomGraph[{9, 7}, VertexLabels -> "Name"]; g1 = System`Graph[VertexList@g, DirectedEdge @@@ EdgeList@g]; ShowGraph[ HasseDiagram[ MakeGraph[VertexList[g1], GraphDistance[g1, #1, #2] =!= Infinity &]], VertexNumber -> ...


18

Here is a solution I can think of. Idea is to take the FullPolygon of a given country and then triangulate the region. Once that is done take the underlying Graph and do a FindShortestPath. Result will not be too bad. fullPoly = CountryData["Vietnam", "FullPolygon"]; pts = Flatten[fullPoly[[1, 1]], 1]; line = Polygon[Range[##]] & @@@ Partition[{1}~Join~ ...



Top 50 recent answers are included