Hot answers tagged graphs-and-networks
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 ...
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_] :=
...
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 ...
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 ...
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,
...
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.
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[#] &)]
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]];
...
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}, ...
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 : ...
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", ...
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___] :>
...
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 ...
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, ...
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]]]
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:
...
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 <- ...
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}]
...
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" -> ...
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 ...
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
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 ...
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 = ...
Only top voted, non community-wiki answers of a minimum length are eligible
