New answers tagged

7

Alternatively, one can use AbsoluteOptions[] to extract the coordinates: g = RandomGraph[{20, 40}]; coords = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates]; You can verify that coords === GraphEmbedding[g] gives True.


4

Slightly more cumbersome alternative to your sp (hopefully little less tedious to use): ClearAll[mapF] mapF[pr1_ -> pr2_][g_] := SetProperty[g, pr1 -> Cases[Options@g, Rule[a_, {___, Rule[pr2, v_], ___}] :> Rule[a, v], Infinity]]; mapF[r : (_ -> _) ..][g_] := Fold[mapF[#2][#] &, g, {r}]; g3 = g // mapF[VertexLabels -> "name"] g4 ...


0

Oddly, technical support at $Mathematica$ was unable to reproduce the issue, though @Xavier and I were both able. They asked me to try a clean start, but the crash still occurred. I've sent my SystemInformation[], and this issue is being tracked under CASE:3588559. The technician's last comments: I have filed a report with our developers which includes ...


2

Yes, there is EdgeQ: g = Graph[{1 -> 2, 2 -> 3, 3 -> 1}, VertexShapeFunction -> "Name"] {EdgeQ[g, 1 -> 2], EdgeQ[g, DirectedEdge[1, 2]], EdgeQ[g, 1 <-> 2], EdgeQ[g, UndirectedEdge[1, 2]], EdgeQ[g, 2 -> 1], EdgeQ[g, DirectedEdge[2, 1]]} {True, True, False, False, False, False} If you need a function that takes a list of ...


1

plot = Plot[x Sin[1/x], {x, -1/2, 1/2}, PlotStyle -> {Red}, ImageSize -> {500}, Frame -> True, Axes -> None] smallplot = Plot[x Sin[1/x], {x, -1/10, 1/10}, PlotRange -> {{-0.02, 0.02}, {-0.02, 0.02}} , PlotStyle -> {Red}, Frame -> True, Axes -> None] Now you can combine these plot ...


3

You can use GraphDistance to do that: g = Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1, 1 <-> 4}]; GraphDistance[g, 2, 3] GraphDistance[g, 2, 4] (* 1 *) (* 2 *)


3

$Version (* "10.4.1 for Mac OS X x86 (64-bit) (April 11, 2016)" *) Hex[exp_] := FromDigits[exp, 16]; LByte[exp_] := BitAnd[exp, Hex@"00ff"]; HByte[exp_] := BitAnd[exp, Hex@"ff00"]~BitShiftRight~8; PRNG[v_] := Module[{L5, H5, v1, v2, carry}, L5 = LByte@v*5; H5 = HByte@v*5; v1 = LByte@H5 + HByte@L5 + 1; carry = HByte@v1~BitGet~0; v2 = ...


12

Yes, use GraphEmbedding. Graph is atomic and you should not try to extract any information from it by looking at its input form. It is not reliable, can change between versions, undocumented, etc. Nor is the input form directly accessible with things like Part.


7

The following should be fast enough: myList = ReadList["infile.txt", Number, RecordLists -> True]; // AbsoluteTiming {4.64517, Null}


6

Kuba beat me to this, but I'll post it anyway since it's slightly different. This gives control over the initial and final positions within the graph, and attempts to keep some of the styling elements, n = 10; g = SetProperty[GridGraph[{n, n}], VertexCoordinates -> Flatten[Array[{#2, #1} &, {n, n}], 1]]; Manipulate[ g2 = EdgeDelete[g, # ...


10

I have done a similar thing for transport in porous media using the image processing functions. It may be different to what you are after but here's the code: First I create a dictionary of nodes ClearAll[dictionary, im, seep]; dictionary[dimensions_Integer, size_Integer] /; (size < dimensions) := dictionary[dimensions, size] = Module[{cross, ...


8

I've taken Graph based road. Let me leave the styling to you: gr = GridGraph[{10, 10}]; The top row is the one with Range[10]*10 vertices and the bottom one with 10*Range[0,9]+1. Don't know how to shortly transpose this so will leave it so. topRow = 10 Range[10]; bottomRow = 10 Range[0, 9] + 1; Manipulate[ deleted = RandomSample[ (*the top and ...


6

For version 9 ngF = With[{v = #, d = #2}, AdjacencyGraph[v, Outer[Boole[EuclideanDistance@## == d] &, v, v, 1], ##3]] &; Using Martin's example, pts = {{0, 0}, {0, 1}, {4, 4}, {0, 2}, {1, 2}, {1, 1}} ngF[pts, 1, VertexLabels -> "Name", ImagePadding -> 10]


9

I think you're looking for RelationGraph. It takes a list of objects to treat as vertices and a test function which determines whether two given vertices should be connected by an edge: pts = {{0, 0}, {0, 1}, {4, 4}, {0, 2}, {1, 2}, {1, 1}}; d = 1; RelationGraph[EuclideanDistance[#, #2] == 1 &, pts] As of 10.3 a more idiomatic way to implement the ...


2

The answer proposed by halmir is very efficient and will give a list featuring all the internal faces along with one face that represents the outer perimeter, but the outer face is not always at the same point in the list, and plotting the polygons sometimes results in obscuring some internal faces. Consider the following graph, g1 = AdjacencyGraph[{{0, 1, ...


6

This answer is a wild stab in the dark, but here it goes... I assume run times of individual runners to follow normal distribution. Product of all PDFs of individual results is maximized (mean run time of runner at vertex 1 is anchored at 0 to choose a reference point), and resulting distributions are used to compute mean, standard deviation and chance of ...


2

There's (almost certainly) no way to do this efficiently, except for small graphs. According to Wikipedia: The number of matchings in a graph is known as the Hosoya index of the graph. It is #P-complete to compute this quantity, even for bipartite graphs.[13] It is also #P-complete to count perfect matchings, even in bipartite graphs [...] Where ...


7

Below you'll find the method I wrote myself, but it is terribly slow compared to this one, adapted from halmir's code here, so I will give the fast version first and post my own code below. See halmir's post for an explanation, ClearAll@graphToMesh graphToMesh[graph_?PlanarGraphQ] := Module[{nextCandidate, m, orderings, pAdj, rightF, s, t, initial, ...


2

GraphData[{"CubicTransitive", 20}] sets VertexCoordinates and VertexCoordinates has higher priority than GraphLayout (options section in Graph documentation). g = GraphData[{"CubicTransitive", 20}]; Options[g] {VertexCoordinates -> {{1., 0.}, {0.5, 0.866}, {-0.5, 0.866}, {-1., 0.}, {-0.5, -0.866}, {0.5, -0.866}, {1.5, 0.}, {0.75, 1.299}, ...



Top 50 recent answers are included