Union on Graph Data in Mathematica
$begingroup$
I have begun working with Mathematica for some Graph Theory, and I want to compute the number of spanning trees of all cubic graphs up to 12 vertices. I have found that
GraphData["Cubic", 12]
will give me the cubic graphs with 12 vertices. But how do I compute the number of spanning trees in each of these graphs. A good tutorial for Graph Theory with Mathematica seems impossible to find (I have found many, but none are actually readable). I can find this:
GraphData[8];
Union[GraphData[#, "VertexCount"] & /@ %%]
to compute the number of vertices in all graphs on 8 vertices, but the #-tag is not defined, and &/@%% seems pretty magical.
graph-theory mathematica
$endgroup$
add a comment |
$begingroup$
I have begun working with Mathematica for some Graph Theory, and I want to compute the number of spanning trees of all cubic graphs up to 12 vertices. I have found that
GraphData["Cubic", 12]
will give me the cubic graphs with 12 vertices. But how do I compute the number of spanning trees in each of these graphs. A good tutorial for Graph Theory with Mathematica seems impossible to find (I have found many, but none are actually readable). I can find this:
GraphData[8];
Union[GraphData[#, "VertexCount"] & /@ %%]
to compute the number of vertices in all graphs on 8 vertices, but the #-tag is not defined, and &/@%% seems pretty magical.
graph-theory mathematica
$endgroup$
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00
add a comment |
$begingroup$
I have begun working with Mathematica for some Graph Theory, and I want to compute the number of spanning trees of all cubic graphs up to 12 vertices. I have found that
GraphData["Cubic", 12]
will give me the cubic graphs with 12 vertices. But how do I compute the number of spanning trees in each of these graphs. A good tutorial for Graph Theory with Mathematica seems impossible to find (I have found many, but none are actually readable). I can find this:
GraphData[8];
Union[GraphData[#, "VertexCount"] & /@ %%]
to compute the number of vertices in all graphs on 8 vertices, but the #-tag is not defined, and &/@%% seems pretty magical.
graph-theory mathematica
$endgroup$
I have begun working with Mathematica for some Graph Theory, and I want to compute the number of spanning trees of all cubic graphs up to 12 vertices. I have found that
GraphData["Cubic", 12]
will give me the cubic graphs with 12 vertices. But how do I compute the number of spanning trees in each of these graphs. A good tutorial for Graph Theory with Mathematica seems impossible to find (I have found many, but none are actually readable). I can find this:
GraphData[8];
Union[GraphData[#, "VertexCount"] & /@ %%]
to compute the number of vertices in all graphs on 8 vertices, but the #-tag is not defined, and &/@%% seems pretty magical.
graph-theory mathematica
graph-theory mathematica
asked Mar 17 '11 at 21:57
utdiscantutdiscant
2,24112132
2,24112132
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00
add a comment |
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
To help figure out a Mathematica expression, following is useful
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%] // Hold // TreeForm
Also, try FullForm
instead of TreeForm
Since GraphData
has property SpanningTreeCount
, you could do
graphs = GraphData[{"Cubic", "Connected"}, 12];
counts = GraphData[#, "SpanningTreeCount"] & /@ graphs;
Column@Thread@{counts, graphs}
Alternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
kirk[L_] := Det@Drop[L, {1}, {1}];
counts = kirk[GraphData[#, "LaplacianMatrix"]] & /@ graphs;
The Drop
command drops 1st row and 1st column of the matrix, but you could drop any other row/column.
To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
count[name_] := GraphData[name, "SpanningTreeCount"];
showCount[name_] := Show[GraphData@name, PlotLabel -> count@name];
showLabeledCount[name_] := Tooltip[showCount@name, name];
graphs = GraphData["Cubic", 12];
pics = showLabeledCount /@ Sort[graphs, count[#1] < count[#2] &];
pics = ArrayPad[pics, {0, 2}, Graphics];
GraphicsGrid@Partition[pics, 10]
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do GraphData[{"Cubic", "Connected"}, ;; 12]
If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with showGraphs
package, you could display all Cubic graphs over 12 vertices that are not connected with showGraphs[12,"Cubic",!"Connected"]
$endgroup$
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
add a comment |
$begingroup$
First, let's pick apart the command you mention.
Union[GraphData[#, "VertexCount"] & /@ %%]
GraphData[#, "VertexCount"]&
is the same as Function[x, GraphData[x, "VertexCount"]]
. That is, the #
is an input parameter and the &
terminates the expression of the #
parameter to be considered a function. %%
is the result-before-last (%
is the most recent result, %%
is the one before that, %%%
is the one before that one, etc.). /@
applies a function to each item of a list. So, GraphData[#, "VertexCount"] & /@ %%
returns the list that results from applying the function GraphData[#, "VertexCount"]&
to each element of the list in %%
. Because of the %%
, the line
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
is probably out of context (since %%
should refer to the result of the statement before GraphData[8]
), and beyond saying that Union
gives the union of sets, I can't tell what it's doing here because I don't know to what %%
refers.
Now, back to what you're trying to do. GraphData[some_graph, "SpanningTreeCount"]
will give the number of spanning trees for *some_graph* (I think, based on the documentation for GraphData
), so GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]
will give a list containing the number of spanning trees for each of the cubic graphs with 12 vertices, and
Total[GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]]
will give the total of the numbers in that list.
Also, since GraphData[#, "Connected"]&
is a function that returns True
for connected graphs and False
otherwise,
Select[GraphData["Cubic", 12], GraphData[#, "Connected"] &]
will give you a list of only the connected cubic graphs with 12 vertices.
$endgroup$
add a comment |
$begingroup$
You can use IGSpanningTreeCount
from the IGraph/M package to count spanning trees in a graph using Mathematica.
IGSpanningTreeCount /@ GraphData /@ GraphData["Cubic", 12]
(* {0, 0, 0, 2112, 2640, 2520, 2808, 3584, 4360, 4080, 4608,
4096, 3840, 5184, 5104, 5544, 4720, 3072, 4480, 5016, 5368, 5632,
4992, 5824, 5712, 5250, 4875, 5535, 4500, 5130, 6580, 6555, 6435,
7050, 6240, 6885, 6875, 7003, 7344, 6320, 7520, 7485, 6765, 7392,
7569, 7467, 7280, 7797, 8165, 7840, 6771, 8131, 6720, 7424, 8323,
8284, 7300, 8100, 7140, 7280, 8256, 6912, 5832, 7560, 7938, 8103,
8736, 8901, 8580, 8820, 8950, 9000, 9170, 8960, 9291, 9240, 9464,
9568, 9800, 9747, 0, 0, 0, 8640, 7350, 9216, 6235, 0, 8112, 8100, 0,
8640, 6000, 0} *)
You may also find IGKRegularGame
useful which can be used to generate random cubic graphs (note that the sampling is not uniform, but the function is quite fast).
Here's a 100-node one:
IGKRegularGame[100, 3]
IGSpanningTreeCount[%]
(* 91662961107198066022274092725381107 *)
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f27683%2funion-on-graph-data-in-mathematica%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
To help figure out a Mathematica expression, following is useful
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%] // Hold // TreeForm
Also, try FullForm
instead of TreeForm
Since GraphData
has property SpanningTreeCount
, you could do
graphs = GraphData[{"Cubic", "Connected"}, 12];
counts = GraphData[#, "SpanningTreeCount"] & /@ graphs;
Column@Thread@{counts, graphs}
Alternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
kirk[L_] := Det@Drop[L, {1}, {1}];
counts = kirk[GraphData[#, "LaplacianMatrix"]] & /@ graphs;
The Drop
command drops 1st row and 1st column of the matrix, but you could drop any other row/column.
To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
count[name_] := GraphData[name, "SpanningTreeCount"];
showCount[name_] := Show[GraphData@name, PlotLabel -> count@name];
showLabeledCount[name_] := Tooltip[showCount@name, name];
graphs = GraphData["Cubic", 12];
pics = showLabeledCount /@ Sort[graphs, count[#1] < count[#2] &];
pics = ArrayPad[pics, {0, 2}, Graphics];
GraphicsGrid@Partition[pics, 10]
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do GraphData[{"Cubic", "Connected"}, ;; 12]
If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with showGraphs
package, you could display all Cubic graphs over 12 vertices that are not connected with showGraphs[12,"Cubic",!"Connected"]
$endgroup$
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
add a comment |
$begingroup$
To help figure out a Mathematica expression, following is useful
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%] // Hold // TreeForm
Also, try FullForm
instead of TreeForm
Since GraphData
has property SpanningTreeCount
, you could do
graphs = GraphData[{"Cubic", "Connected"}, 12];
counts = GraphData[#, "SpanningTreeCount"] & /@ graphs;
Column@Thread@{counts, graphs}
Alternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
kirk[L_] := Det@Drop[L, {1}, {1}];
counts = kirk[GraphData[#, "LaplacianMatrix"]] & /@ graphs;
The Drop
command drops 1st row and 1st column of the matrix, but you could drop any other row/column.
To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
count[name_] := GraphData[name, "SpanningTreeCount"];
showCount[name_] := Show[GraphData@name, PlotLabel -> count@name];
showLabeledCount[name_] := Tooltip[showCount@name, name];
graphs = GraphData["Cubic", 12];
pics = showLabeledCount /@ Sort[graphs, count[#1] < count[#2] &];
pics = ArrayPad[pics, {0, 2}, Graphics];
GraphicsGrid@Partition[pics, 10]
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do GraphData[{"Cubic", "Connected"}, ;; 12]
If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with showGraphs
package, you could display all Cubic graphs over 12 vertices that are not connected with showGraphs[12,"Cubic",!"Connected"]
$endgroup$
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
add a comment |
$begingroup$
To help figure out a Mathematica expression, following is useful
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%] // Hold // TreeForm
Also, try FullForm
instead of TreeForm
Since GraphData
has property SpanningTreeCount
, you could do
graphs = GraphData[{"Cubic", "Connected"}, 12];
counts = GraphData[#, "SpanningTreeCount"] & /@ graphs;
Column@Thread@{counts, graphs}
Alternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
kirk[L_] := Det@Drop[L, {1}, {1}];
counts = kirk[GraphData[#, "LaplacianMatrix"]] & /@ graphs;
The Drop
command drops 1st row and 1st column of the matrix, but you could drop any other row/column.
To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
count[name_] := GraphData[name, "SpanningTreeCount"];
showCount[name_] := Show[GraphData@name, PlotLabel -> count@name];
showLabeledCount[name_] := Tooltip[showCount@name, name];
graphs = GraphData["Cubic", 12];
pics = showLabeledCount /@ Sort[graphs, count[#1] < count[#2] &];
pics = ArrayPad[pics, {0, 2}, Graphics];
GraphicsGrid@Partition[pics, 10]
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do GraphData[{"Cubic", "Connected"}, ;; 12]
If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with showGraphs
package, you could display all Cubic graphs over 12 vertices that are not connected with showGraphs[12,"Cubic",!"Connected"]
$endgroup$
To help figure out a Mathematica expression, following is useful
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%] // Hold // TreeForm
Also, try FullForm
instead of TreeForm
Since GraphData
has property SpanningTreeCount
, you could do
graphs = GraphData[{"Cubic", "Connected"}, 12];
counts = GraphData[#, "SpanningTreeCount"] & /@ graphs;
Column@Thread@{counts, graphs}
Alternatively, you could get number of spanning trees from Laplacian matrix of the graph using Kirchoff's matrix tree theorem.
kirk[L_] := Det@Drop[L, {1}, {1}];
counts = kirk[GraphData[#, "LaplacianMatrix"]] & /@ graphs;
The Drop
command drops 1st row and 1st column of the matrix, but you could drop any other row/column.
To display 12 vertex cubic graphs nicely, with graph name in tooltip and sorted by number of spanning trees, you could do something like this
count[name_] := GraphData[name, "SpanningTreeCount"];
showCount[name_] := Show[GraphData@name, PlotLabel -> count@name];
showLabeledCount[name_] := Tooltip[showCount@name, name];
graphs = GraphData["Cubic", 12];
pics = showLabeledCount /@ Sort[graphs, count[#1] < count[#2] &];
pics = ArrayPad[pics, {0, 2}, Graphics];
GraphicsGrid@Partition[pics, 10]
To get all cubic, connected graphs with up to 12 vertices (disconnected graphs are not interesting since they have 0 spanning trees), do GraphData[{"Cubic", "Connected"}, ;; 12]
If you are doing graph theory with Mathematica, you could find my graph utilities packages helpful, documented here, here, and here. For instance, with showGraphs
package, you could display all Cubic graphs over 12 vertices that are not connected with showGraphs[12,"Cubic",!"Connected"]
edited Dec 29 '18 at 18:54
Glorfindel
3,41981830
3,41981830
answered Mar 18 '11 at 11:05
Yaroslav BulatovYaroslav Bulatov
1,87411526
1,87411526
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
add a comment |
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
$begingroup$
markdown doesn't recognize link to wikipedia's Kirkhoff's theorem because it has an apostrophe in it, any idea how to make the link work?
$endgroup$
– Yaroslav Bulatov
Mar 18 '11 at 11:08
add a comment |
$begingroup$
First, let's pick apart the command you mention.
Union[GraphData[#, "VertexCount"] & /@ %%]
GraphData[#, "VertexCount"]&
is the same as Function[x, GraphData[x, "VertexCount"]]
. That is, the #
is an input parameter and the &
terminates the expression of the #
parameter to be considered a function. %%
is the result-before-last (%
is the most recent result, %%
is the one before that, %%%
is the one before that one, etc.). /@
applies a function to each item of a list. So, GraphData[#, "VertexCount"] & /@ %%
returns the list that results from applying the function GraphData[#, "VertexCount"]&
to each element of the list in %%
. Because of the %%
, the line
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
is probably out of context (since %%
should refer to the result of the statement before GraphData[8]
), and beyond saying that Union
gives the union of sets, I can't tell what it's doing here because I don't know to what %%
refers.
Now, back to what you're trying to do. GraphData[some_graph, "SpanningTreeCount"]
will give the number of spanning trees for *some_graph* (I think, based on the documentation for GraphData
), so GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]
will give a list containing the number of spanning trees for each of the cubic graphs with 12 vertices, and
Total[GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]]
will give the total of the numbers in that list.
Also, since GraphData[#, "Connected"]&
is a function that returns True
for connected graphs and False
otherwise,
Select[GraphData["Cubic", 12], GraphData[#, "Connected"] &]
will give you a list of only the connected cubic graphs with 12 vertices.
$endgroup$
add a comment |
$begingroup$
First, let's pick apart the command you mention.
Union[GraphData[#, "VertexCount"] & /@ %%]
GraphData[#, "VertexCount"]&
is the same as Function[x, GraphData[x, "VertexCount"]]
. That is, the #
is an input parameter and the &
terminates the expression of the #
parameter to be considered a function. %%
is the result-before-last (%
is the most recent result, %%
is the one before that, %%%
is the one before that one, etc.). /@
applies a function to each item of a list. So, GraphData[#, "VertexCount"] & /@ %%
returns the list that results from applying the function GraphData[#, "VertexCount"]&
to each element of the list in %%
. Because of the %%
, the line
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
is probably out of context (since %%
should refer to the result of the statement before GraphData[8]
), and beyond saying that Union
gives the union of sets, I can't tell what it's doing here because I don't know to what %%
refers.
Now, back to what you're trying to do. GraphData[some_graph, "SpanningTreeCount"]
will give the number of spanning trees for *some_graph* (I think, based on the documentation for GraphData
), so GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]
will give a list containing the number of spanning trees for each of the cubic graphs with 12 vertices, and
Total[GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]]
will give the total of the numbers in that list.
Also, since GraphData[#, "Connected"]&
is a function that returns True
for connected graphs and False
otherwise,
Select[GraphData["Cubic", 12], GraphData[#, "Connected"] &]
will give you a list of only the connected cubic graphs with 12 vertices.
$endgroup$
add a comment |
$begingroup$
First, let's pick apart the command you mention.
Union[GraphData[#, "VertexCount"] & /@ %%]
GraphData[#, "VertexCount"]&
is the same as Function[x, GraphData[x, "VertexCount"]]
. That is, the #
is an input parameter and the &
terminates the expression of the #
parameter to be considered a function. %%
is the result-before-last (%
is the most recent result, %%
is the one before that, %%%
is the one before that one, etc.). /@
applies a function to each item of a list. So, GraphData[#, "VertexCount"] & /@ %%
returns the list that results from applying the function GraphData[#, "VertexCount"]&
to each element of the list in %%
. Because of the %%
, the line
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
is probably out of context (since %%
should refer to the result of the statement before GraphData[8]
), and beyond saying that Union
gives the union of sets, I can't tell what it's doing here because I don't know to what %%
refers.
Now, back to what you're trying to do. GraphData[some_graph, "SpanningTreeCount"]
will give the number of spanning trees for *some_graph* (I think, based on the documentation for GraphData
), so GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]
will give a list containing the number of spanning trees for each of the cubic graphs with 12 vertices, and
Total[GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]]
will give the total of the numbers in that list.
Also, since GraphData[#, "Connected"]&
is a function that returns True
for connected graphs and False
otherwise,
Select[GraphData["Cubic", 12], GraphData[#, "Connected"] &]
will give you a list of only the connected cubic graphs with 12 vertices.
$endgroup$
First, let's pick apart the command you mention.
Union[GraphData[#, "VertexCount"] & /@ %%]
GraphData[#, "VertexCount"]&
is the same as Function[x, GraphData[x, "VertexCount"]]
. That is, the #
is an input parameter and the &
terminates the expression of the #
parameter to be considered a function. %%
is the result-before-last (%
is the most recent result, %%
is the one before that, %%%
is the one before that one, etc.). /@
applies a function to each item of a list. So, GraphData[#, "VertexCount"] & /@ %%
returns the list that results from applying the function GraphData[#, "VertexCount"]&
to each element of the list in %%
. Because of the %%
, the line
GraphData[8]; Union[GraphData[#, "VertexCount"] & /@ %%]
is probably out of context (since %%
should refer to the result of the statement before GraphData[8]
), and beyond saying that Union
gives the union of sets, I can't tell what it's doing here because I don't know to what %%
refers.
Now, back to what you're trying to do. GraphData[some_graph, "SpanningTreeCount"]
will give the number of spanning trees for *some_graph* (I think, based on the documentation for GraphData
), so GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]
will give a list containing the number of spanning trees for each of the cubic graphs with 12 vertices, and
Total[GraphData[#, "SpanningTreeCount"] & /@ GraphData["Cubic", 12]]
will give the total of the numbers in that list.
Also, since GraphData[#, "Connected"]&
is a function that returns True
for connected graphs and False
otherwise,
Select[GraphData["Cubic", 12], GraphData[#, "Connected"] &]
will give you a list of only the connected cubic graphs with 12 vertices.
answered Mar 18 '11 at 2:50
IsaacIsaac
30k1285128
30k1285128
add a comment |
add a comment |
$begingroup$
You can use IGSpanningTreeCount
from the IGraph/M package to count spanning trees in a graph using Mathematica.
IGSpanningTreeCount /@ GraphData /@ GraphData["Cubic", 12]
(* {0, 0, 0, 2112, 2640, 2520, 2808, 3584, 4360, 4080, 4608,
4096, 3840, 5184, 5104, 5544, 4720, 3072, 4480, 5016, 5368, 5632,
4992, 5824, 5712, 5250, 4875, 5535, 4500, 5130, 6580, 6555, 6435,
7050, 6240, 6885, 6875, 7003, 7344, 6320, 7520, 7485, 6765, 7392,
7569, 7467, 7280, 7797, 8165, 7840, 6771, 8131, 6720, 7424, 8323,
8284, 7300, 8100, 7140, 7280, 8256, 6912, 5832, 7560, 7938, 8103,
8736, 8901, 8580, 8820, 8950, 9000, 9170, 8960, 9291, 9240, 9464,
9568, 9800, 9747, 0, 0, 0, 8640, 7350, 9216, 6235, 0, 8112, 8100, 0,
8640, 6000, 0} *)
You may also find IGKRegularGame
useful which can be used to generate random cubic graphs (note that the sampling is not uniform, but the function is quite fast).
Here's a 100-node one:
IGKRegularGame[100, 3]
IGSpanningTreeCount[%]
(* 91662961107198066022274092725381107 *)
$endgroup$
add a comment |
$begingroup$
You can use IGSpanningTreeCount
from the IGraph/M package to count spanning trees in a graph using Mathematica.
IGSpanningTreeCount /@ GraphData /@ GraphData["Cubic", 12]
(* {0, 0, 0, 2112, 2640, 2520, 2808, 3584, 4360, 4080, 4608,
4096, 3840, 5184, 5104, 5544, 4720, 3072, 4480, 5016, 5368, 5632,
4992, 5824, 5712, 5250, 4875, 5535, 4500, 5130, 6580, 6555, 6435,
7050, 6240, 6885, 6875, 7003, 7344, 6320, 7520, 7485, 6765, 7392,
7569, 7467, 7280, 7797, 8165, 7840, 6771, 8131, 6720, 7424, 8323,
8284, 7300, 8100, 7140, 7280, 8256, 6912, 5832, 7560, 7938, 8103,
8736, 8901, 8580, 8820, 8950, 9000, 9170, 8960, 9291, 9240, 9464,
9568, 9800, 9747, 0, 0, 0, 8640, 7350, 9216, 6235, 0, 8112, 8100, 0,
8640, 6000, 0} *)
You may also find IGKRegularGame
useful which can be used to generate random cubic graphs (note that the sampling is not uniform, but the function is quite fast).
Here's a 100-node one:
IGKRegularGame[100, 3]
IGSpanningTreeCount[%]
(* 91662961107198066022274092725381107 *)
$endgroup$
add a comment |
$begingroup$
You can use IGSpanningTreeCount
from the IGraph/M package to count spanning trees in a graph using Mathematica.
IGSpanningTreeCount /@ GraphData /@ GraphData["Cubic", 12]
(* {0, 0, 0, 2112, 2640, 2520, 2808, 3584, 4360, 4080, 4608,
4096, 3840, 5184, 5104, 5544, 4720, 3072, 4480, 5016, 5368, 5632,
4992, 5824, 5712, 5250, 4875, 5535, 4500, 5130, 6580, 6555, 6435,
7050, 6240, 6885, 6875, 7003, 7344, 6320, 7520, 7485, 6765, 7392,
7569, 7467, 7280, 7797, 8165, 7840, 6771, 8131, 6720, 7424, 8323,
8284, 7300, 8100, 7140, 7280, 8256, 6912, 5832, 7560, 7938, 8103,
8736, 8901, 8580, 8820, 8950, 9000, 9170, 8960, 9291, 9240, 9464,
9568, 9800, 9747, 0, 0, 0, 8640, 7350, 9216, 6235, 0, 8112, 8100, 0,
8640, 6000, 0} *)
You may also find IGKRegularGame
useful which can be used to generate random cubic graphs (note that the sampling is not uniform, but the function is quite fast).
Here's a 100-node one:
IGKRegularGame[100, 3]
IGSpanningTreeCount[%]
(* 91662961107198066022274092725381107 *)
$endgroup$
You can use IGSpanningTreeCount
from the IGraph/M package to count spanning trees in a graph using Mathematica.
IGSpanningTreeCount /@ GraphData /@ GraphData["Cubic", 12]
(* {0, 0, 0, 2112, 2640, 2520, 2808, 3584, 4360, 4080, 4608,
4096, 3840, 5184, 5104, 5544, 4720, 3072, 4480, 5016, 5368, 5632,
4992, 5824, 5712, 5250, 4875, 5535, 4500, 5130, 6580, 6555, 6435,
7050, 6240, 6885, 6875, 7003, 7344, 6320, 7520, 7485, 6765, 7392,
7569, 7467, 7280, 7797, 8165, 7840, 6771, 8131, 6720, 7424, 8323,
8284, 7300, 8100, 7140, 7280, 8256, 6912, 5832, 7560, 7938, 8103,
8736, 8901, 8580, 8820, 8950, 9000, 9170, 8960, 9291, 9240, 9464,
9568, 9800, 9747, 0, 0, 0, 8640, 7350, 9216, 6235, 0, 8112, 8100, 0,
8640, 6000, 0} *)
You may also find IGKRegularGame
useful which can be used to generate random cubic graphs (note that the sampling is not uniform, but the function is quite fast).
Here's a 100-node one:
IGKRegularGame[100, 3]
IGSpanningTreeCount[%]
(* 91662961107198066022274092725381107 *)
answered May 2 '18 at 10:26
SzabolcsSzabolcs
463421
463421
add a comment |
add a comment |
Thanks for contributing an answer to Mathematics Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f27683%2funion-on-graph-data-in-mathematica%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Also, it would be nice to be able to exclude graphs which are not connected.
$endgroup$
– utdiscant
Mar 17 '11 at 22:00