New answers tagged graphs-and-networks
4
With Combinatorica, you should usually use MakeGraph rather than Graph directly. Here are some expressions that create the graph you want and which can be easily adapted for use with any graph that you've defined appropriate vertices and edges symbols for:
Needs["Combinatorica`"]
crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}};
vertices = Range[Length[crds]];
...
0
Needs["Combinatorica`"];
crds = {{1, 10}, {2, 4}, {10, 5}, {20, 10}}
vertices = Range[Length[crds]]; edges =
Thread[vertices -> RotateLeft[vertices]];
GraphPlot[edges]
7
Nice answer by Mohsen, +1. I am continually impressed by the quality of the J/Link and .NET/Link expertise on this site. I have a couple remarks and then an example program.
The question asked about some general tips for getting started with J/Link. This GraphStream library provides a perfect example for the typical workflow of a J/Link project. The ...
8
I am writing this answer for a person who is familiar with Mathematica and has a good understanding of computer programming, but not so familiar with Java programming language.
Using GraphStream is not so different from using any other Java library. You need to download the GraphStream core files from here and extract it.
gs-core-1.1.2.jar is the only file ...
2
I'm not too good at graphs, but this seems straightforward.
myAdjacencyMatrix =
{{0, 3, 1, 3, 3, 8, 0, 0, 3, 4, 2},
{1, 0, 2, 0, 0, 16, 5, 3, 0, 6, 1},
{2, 3, 0, 0, 1, 1, 4, 1, 1, 0, 0},
{5, 3, 3, 0, 5, 0, 2, 2, 2, 2, 1},
{1, 0, 0, 6, 0, 1, 2, 6, 10, 2, 4},
{0, 11, 3, 0, 1, 0, 8, 3, 1, 3, 3},
{2, 4, 1, 7, 6, 7, 0, 6, 0, 8, 2},
{1, 2, 1, 3, 8, 4, 4, ...
8
I think you can regard each one of your edges/vertices as a complex number, so walk along the path given an angle set will be equivalent to adding the corresponding number set successively. And if the total is $0$, it means the path is closed, thus a polytan.
This is a possible implementation:
Clear[polytanPlot]
polytanPlot[angleSet_] :=
...
2
The function to use to set properties on graphs is SetProperty. Sometimes this function can be a bit inconsistent and difficult to figure out, but this time the standard syntax works:
SetProperty[{g, "Uppsala" \[DirectedEdge] "Marsta"}, EdgeWeight -> 15]
You could also use
SetProperty[g, EdgeWeight -> {"Uppsala" \[DirectedEdge] "Marsta" -> 20}]
...
4
I'm not quite sure what exactly you're looking for. However here is a little GUI I wrote that shows the kinds of things you can do:
DynamicModule[{g, toCSV, fromCSV, fromExcel, file, properties},
properties = {EdgeWeight, EdgeLabels};
toCSV[g_Graph] := Module[{edges, props, rows},
edges = List @@@ EdgeList[g];
props = Table[PropertyValue[{g, e}, ...
1
If you own a license of ExcelLink, you can proceed like this:
(*open a blank Excel sheet now*)
Needs@"ExcelLink`";
s = {"Stockholm" -> "Boo", "Boo" -> "Stockholm",
"Stockholm" -> "Lidingo", "Lidingo" -> "Stockholm",
"Stockholm" -> "Sollentuna", "Sollentuna" -> "Stockholm",
"Stockholm" -> "Taby", "Taby" -> ...
6
Contextual menu bindings are defined in the file here:
FileNameJoin[{$InstallationDirectory,
"SystemFiles", "FrontEnd", "TextResources", "ContextMenus.tr"}]
Examining the contents of that file, you can discover that the "Convert to Graphics" contextual menu item maps to the Mathematica command GraphComputation`GraphConvertToGraphics. Thus, for example,
...
11
Well, just after I had posted the question, I found a stupidly simple way to do it:
In[15]:= Show[CompleteGraph[8]] // Head
Out[15]= Graphics
0
You can use this package to call igraph through RLink. igraph can test the isomoprhism of coloured graphs (either edge or vertex colouring).
Let's build the same graphs that @whuber had:
g = CycleGraph[6]
col1 = {1, 2, 3, 1, 2, 3}
col2 = {2, 1, 3, 2, 1, 3}
col3 = {3, 2, 3, 1, 2, 1}
The three vectors col1, col2 and col3 represent the three colourings.
...
1
You can use this package to call igraph through RLink. igraph does support multi-edges. After setting up the package, do
edgelist1 = {{1, 2}, {2, 3}, {3, 4}, {4, 1}, {1, 2}, {1, 4}}
GraphPlot[Rule @@@ edgelist1]
(* see the multiple edges *)
This is a bit more complex than passing a graph object because in Mathematica you can't construct a graph with ...
0
With apologies for the third, yet again independent answer, I recommend calling igraph through RLink using this package (only if you have v9 of Mathematica). Please see the instructions on how to set up the package, then you can do:
graph = AdjacencyGraph[{{1,0},{0,1}}];
res = IGraph["graph.get.isomorphisms.vf2"][graph, graph]
Round[res+1]
This will ...
1
Daniel is completely correct that this is a hard problem and will usually take a very very long time. However, the igraph library does have a function for it and you can call it through this package. Please read the instructions on how to set up the package, then do this:
{g, subG} = {PetersenGraph[5, 2], EdgeAdd[CycleGraph[5], 5 <-> 6]}
res = ...
14
I wrote a small package for this. The main reason why I'm posting it here is to get some feedback on how to improve it. I'm new both R and RLink.
You can get the package here. Please see the installation instructions in README.md, especially if you're a Mac user (important!).
How does it work?
RLink does not play well with igraph objects, so an ...
6
The ordering of the vertices used for AdjacencyMatrix is that given in VertexList[m]:
ordering={1, 3, 2, 4, 5, 6, 7, 8}
Thus, while it looks like the adjacency matrix is saying that 1 and 2 are joined. If you look at the ordering in VertexList You'll see that the second element is actually node number 3.
1
First, I am not a specialist on probability theory and random processes! I will try to address your question from the very limited knowledge I got from the Mathematica documentation. The documentation for DiscreteMarkovProcess tells the following
"A discrete Markov process can be seen as a random walk on a graph, where the probability of ...
2
Here's one possibility, using an undocumented function for the Delaunay triangulation:
BlockRandom[SeedRandom[131, Method -> "MKL"]; (* for reproducibility *)
pts = RandomReal[{0, 10}, {10, 2}]];
Graphics`Mesh`MeshInit[];
dt = Delaunay[pts];
Graph[Range[Length[pts]], UndirectedEdge @@@ dt["Edges"], VertexCoordinates -> pts]
Compare:
...
1
Alternative way to extract vertices:
g = RandomGraph[BarabasiAlbertGraphDistribution[1000, 1]];
d = 5;
Szabolcs suggestion
distances = GraphDistance[g, 300];
set1 = Pick[VertexList[g], distances, d];
using BreadthFirstScan
set2 = Reap[
CheckAbort[
BreadthFirstScan[g, 300, "DiscoverVertex" -> ((If[#3 > 5, Abort[]];
If[#3 == d, Sow[#1]]) ...
1
To extract first coordinates of TerminalsCoordinates for each node:
(PropertyValue[{g,#}, "TerminalsCoordinates"]& /@ VertexList[g])[[All,1]]
2
Start with a graph and a distance d:
g = RandomGraph[BarabasiAlbertGraphDistribution[1000, 1]];
d = 5
Find the distance of a vertex (e.g. vertex 300) to all others:
distances = GraphDistance[g, 300];
Sample k vertices from those with distance d from 300:
RandomSample[
Pick[VertexList[g], distances, d],
k
]
2
Build a graph and see what are the current coordinates:
g = CycleGraph[8, Axes -> True, GraphStyle -> "SmallNetwork"]
Get coordinates via GraphEmbedding, then Rescale and verify:
SetProperty[g, VertexCoordinates -> 100 Rescale[GraphEmbedding[g]]]
3
I guess something like this:
net = {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 1}; gp = GraphPlot[net];
pts = First[Cases[gp, GraphicsComplex[pts_, others___] :> pts, ∞]];
{xb, yb} = Composition[Through, {Min, Max}] /@ Transpose[pts];
Show[gp /.
GraphicsComplex[pts_, others___] :>
...
2
EDIT
An easier way is using this package
IGraph["vertex.connectivity"][CycleGraph[5]]
(* ==> {.2} *)
Old version
As a workaround, you can access igraph through RLink. Once igraph is installed (install.packages(igraph)) and loaded (library(igraph)), do this:
vertexConnectivity[g_?GraphQ] :=
Round@First@RFunction["function (e) {
g <- ...
3
EDIT: Easier version based on this package:
In[23]:= IGraph["graph.subisomorphic.vf2"][GraphData[{"Fullerene", {26, 1}}], CycleGraph[5]]
Out[23]= RObject[{{True},
{1., 2., 0., 0., 0., 0., 5., 3., 0., 0., 0.,
0., 4., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.},
{1., 2., 8., 13., 7.}},
RAttributes["names" :> {"iso", "map12", ...
0
Ideally, it would be possible to fix the coordinates of one vertex, and let the layout algorithm take care of the rest. I couldn't figure out how to do this with Graph, but it is possible with GraphPlot:
GraphPlot[CompleteGraph[10], VertexCoordinateRules -> {1 -> {0, 0}}]
3
---------- Update -------------
Now because of your comment I understand your problem better. Then it is basically a one-liner:
RandomGraph[{11, 25}, GraphLayout -> {"StarEmbedding", "Center" -> 2},
GraphStyle -> "SmallNetwork"]
---------- Older versions -------------
Start from {"BalloonEmbedding", "RootVertex" -> k} or ...
0
nFriends = 10;
coords = Prepend[#, {0, 0}] &[{Sin@#,
Cos@#} & /@ (Range[nFriends]/nFriends*2 Pi)];
CompleteGraph[nFriends+1, VertexCoordinates -> coords]
Will give you the complete graph with a vertex in the center.
func = Function[xxxx, UndirectedEdge[#, Last[xxxx]] & /@ Most[xxxx]];
connections = Array[Sequence @@ func@Range[0, #] ...
5
If you don't mind using undocumented functions, you can do it like this:
Graphics`Mesh`MeshInit[];
mesh = DensityPlot[4 Sin[2 Pi x] Cos[1.5 Pi y] (1 - x^2) (1 - y) y, {x, -1, 1}, {y, 0, 1},
Method -> {"ReturnMeshObject" -> True}];
Graph[mesh["Edges"], VertexCoordinates -> mesh["Coordinates"],
VertexShapeFunction -> (Point[#] &)]
3
My modest attempt:
dp = DensityPlot[4 Sin[2 Pi x] Cos[3 Pi y/2] (1 - x^2) (1 - y) y,
{x, -1, 1}, {y, 0, 1}, Mesh -> All]
{verts, edgs} = List @@ MapAt[Composition[Union, Flatten],
(Most[MapAt[Flatten[Cases[#, _Polygon, ∞]] &,
First[Cases[dp, _GraphicsComplex, ∞]], {2}]] /.
Polygon[p : ...
Top 50 recent answers are included

