Tag Info

New answers tagged

3

This has to be a bug. I think Graph never really associates EdgeWeight with corresponding edges. Here is a simplified example. g = Graph[{1, 2, 3}, { Property[1 <-> 2, EdgeWeight -> x], 1 <-> 3, Property[2 <-> 3, EdgeWeight -> y] }]; gNew = RemoveProperty[{g, ...


1

It just got even more interesting. I tried assigning a list to a VertexWeight and couldn't. I could however assign an EmpiricalDistribution (which is odd as it has a lot of structure inside it). Check this the following timings though: Clear[g] g = CycleGraph[1000]; Timing@Do[ PropertyValue[{g, v}, VertexWeight] = EmpiricalDistribution[RandomReal[{0, ...


4

The information concerning SetProperty and PropertyValue timings aren't the full story! The SetProperty invokes no persistent side-effect (one must assign with it to keep the edited graph!) where as PropertyValue does edit the object (in-place). Given that this performance testing is to create an graph object one wants to do more with I'm going to present ...


1

I have a method to achieve what you want but the procedure is very dirty: We will make two graphs and then Overlay them. The first one is as shown below:- << Combinatorica`; g = MakeGraph[ Subsets[Range[3]], ((Intersection[#2, #1] == #1) && (#1 != #2)) &, VertexLabel -> True]; hdg = HasseDiagram[g]; sgX = ShowGraph[ ...


5

You can add additional graphics (arrow) using Epilog or Prolog: Ex1: HighlightGraph[g, path, Epilog -> {Red, Thickness[.01], Arrowheads[.05], Arrow /@ Partition[GraphEmbedding[g][[path]], 2, 1]}] Ex2: HighlightGraph[g, PathGraph[path], Prolog -> {Orange, Thickness[.005], Arrowheads[Table[.04, 10]], ...


4

This is a V9 answer: g = DirectedGraph[GraphData["DodecahedralGraph"], VertexLabels -> "Name", EdgeStyle -> White]; HighlightGraph[g, FindHamiltonianCycle[g][[1]] // Most] g = DirectedGraph[GraphData["DodecahedralGraph"], VertexLabels -> "Name"]; HighlightGraph[g, FindHamiltonianCycle[g][[1]] // Most]


4

GraphDistance[g, 1, 6] returns 3. I've had this problem in the past, and if you want to fix your original method, you can use Sjoerd C. de Vries's answer there. It's one of the few really annoying behaviours of Mathematica I've come across. Example with a shuffled list of vertices, eleven vertices and ten edges: edges = UndirectedEdge @@@ ...


4

Another trick you can do: Graph[Join[Table[1 -> 2, {10}], Table[2 -> 3, {5}], Table[3 -> 1, {5}]], EdgeShapeFunction -> {1 \[DirectedEdge] 2 -> (a = 0; {a++; ColorData[35, "ColorList"][[a]], Arrow[#]} &), 2 \[DirectedEdge] 3 -> (b = 0; {b++; ColorData[55, "ColorList"][[b]], Arrow[#]} &), 3 ...


2

The trick is to render both a directed and an undirected edge with the same arrow EdgeShapeFunction. Alas, the full graph representation will retain the different classes of edge, so functions such as FindKClan, VertexOutDegree, VertexInDegree, and others that distinguish between different classes of edge will give incorrect answers. Graph[{1, 2}, ...


1

You could add button to copy or print coordinates: Labeled[Manipulate[ Graphics[{Line[v]}, PlotRange -> {-6, 6}], {{v, {{-5, 5}, {5, 5}, {5, -5}, {-5, -5}}}, Locator, LocatorAutoCreate -> True}, Button["Copy Coordinate", CopyToClipboard[v]], Button["Print Coordinate", Print[v]]], "Locator Example"]


7

The problem is that the vertices get numbered by their order of appearance in the graph. This means that what you called vertex "6" is actually considered vertex "5". To see what I mean try the following command: VertexList[g] To set the vertices in the desired order, they should be explicitly listed before the edges: g = Graph[Table[i,{i,1,11}],{1 -> ...


2

g = Graph[{1 <-> 2, 2 <-> 3, 3 <->1}]; init = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates]; (* Rescale to 10% padding *) xyScale = 1.1 # -.1 Mean@# &/@ (Through[{Min,Max}[#]] &/@ Transpose@init); Manipulate[SetProperty[g, {VertexCoordinates -> pt, PlotRange -> xyScale}], {{pt, init}, Locator}]


1

I think the minimal solution to your specific question is: TreeGraph[{1 -> 2, 1 -> 3}, VertexLabels -> {1 -> "a", "b"}] or Graph[{1 -> 2, 1 -> 3}, VertexLabels -> {1 -> "a", "b"}]


5

I have used the functions EdgeDelete and EdgeAdd to expand the graph. The code generates new vertex names by incrementing the largest vertex name in the graph. nextVertexNames[g_] := Max[VertexList[g]] + {{1, 2, 3}, {4, 5, 6}} replaceTripod[g_, v_] := Module[{ oldNeighbors = DeleteCases[VertexComponent[g, v, 1], v], newNeighbors = nextVertexNames[g], ...


1

This may or may not do what you want. I don't know about making the layout nice, I'm afraid. The function newvertex returns n names which are not used as a vertex in the graph. Then expandVertex takes a vertex name and expands about that vertex in the manner stated. Alternatively, supply a list of names to have the expansion done on each in turn, or supply ...


6

Note: The following needs a properly color quantized image as input. Color quantization for general images is a problem on its own that depends on many factors and is not addressed below. First we will go step by step, then wrapping up all of it in a function: Import some discrete-colored image: ii = Import["http://i.stack.imgur.com/9vdgV.png"] Then ...



Top 50 recent answers are included