Convert graph format for Mathematica graph functionsConvert Graph to GraphicsDynamic graph visualisation using JLink/Java and GraphStreamConvert DelaunayTriangulation-> Graph->AdjacencyMatrixExport format for graphs loses type information?Fast way to get edge-list of graph in terms of vertex indices (not vertex names)convert MeijerG to form Standard Functions in MathematicaEfficiently importing data into MathematicaHow to convert the Latex format to Mathematica input?How to convert cdf to stl formatHow to convert DateList format to standard SQL format?
Write an interpreter for *
Why doesn't the "actual" path matter for line integrals?
Who are these characters/superheroes in the posters from Chris's room in Family Guy?
How can I tell if a flight itinerary is fake?
Why is there a need to prevent a racist, sexist, or otherwise bigoted vendor from discriminating who they sell to?
How should an administrative assistant reply to student addressing them as "Professor" or "Doctor"?
Looking for a new job because of relocation - is it okay to tell the real reason?
Converting Piecewise function to C code
Is refreshing multiple times a test case for web applications?
How quickly could a country build a tall concrete wall around a city?
As a 16 year old, how can I keep my money safe from my mother?
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
Was the 2019 Lion King film made through motion capture?
Can I legally make a real mobile app based on a fictional app from a TV show?
Best gun to modify into a monsterhunter weapon?
How to use grep to search through the --help output?
Infeasibility in mathematical optimization models
Does the United States guarantee any unique freedoms?
How can a surrogate pass on genes to a fertilized embryo?
Double blind peer review when paper cites author's GitHub repo for code
How to mark beverage cans in a cooler for a blind person?
How do I calculate the difference in lens reach between a superzoom compact and a DSLR zoom lens?
sed delete all the words before a match
Generator for parity?
Convert graph format for Mathematica graph functions
Convert Graph to GraphicsDynamic graph visualisation using JLink/Java and GraphStreamConvert DelaunayTriangulation-> Graph->AdjacencyMatrixExport format for graphs loses type information?Fast way to get edge-list of graph in terms of vertex indices (not vertex names)convert MeijerG to form Standard Functions in MathematicaEfficiently importing data into MathematicaHow to convert the Latex format to Mathematica input?How to convert cdf to stl formatHow to convert DateList format to standard SQL format?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I have an output of many large graph files, specified by pair of vertices, in a format like
[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],[8,6],[9,4],[10,2],[11,4]
which is like the standard-graph form of Maple.
I would like to use the graph-functions of Mathematica. As far as I understood, Mathematica by default uses a syntax like
Graph[1 -> 2, 2 -> 3, 3 -> 1]
Do you know of a quick way to use/convert/import my graph-format in Mathematica, or do I first need to convert my graph-files with some script to the correct Mathematica-input?
Thanks a lot for any help.
graphs-and-networks conversion
$endgroup$
add a comment |
$begingroup$
I have an output of many large graph files, specified by pair of vertices, in a format like
[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],[8,6],[9,4],[10,2],[11,4]
which is like the standard-graph form of Maple.
I would like to use the graph-functions of Mathematica. As far as I understood, Mathematica by default uses a syntax like
Graph[1 -> 2, 2 -> 3, 3 -> 1]
Do you know of a quick way to use/convert/import my graph-format in Mathematica, or do I first need to convert my graph-files with some script to the correct Mathematica-input?
Thanks a lot for any help.
graphs-and-networks conversion
$endgroup$
4
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (ExportGraph
) and import it in Mathematica (Import
).
$endgroup$
– Szabolcs
Jul 30 at 19:58
1
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30
add a comment |
$begingroup$
I have an output of many large graph files, specified by pair of vertices, in a format like
[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],[8,6],[9,4],[10,2],[11,4]
which is like the standard-graph form of Maple.
I would like to use the graph-functions of Mathematica. As far as I understood, Mathematica by default uses a syntax like
Graph[1 -> 2, 2 -> 3, 3 -> 1]
Do you know of a quick way to use/convert/import my graph-format in Mathematica, or do I first need to convert my graph-files with some script to the correct Mathematica-input?
Thanks a lot for any help.
graphs-and-networks conversion
$endgroup$
I have an output of many large graph files, specified by pair of vertices, in a format like
[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],[8,6],[9,4],[10,2],[11,4]
which is like the standard-graph form of Maple.
I would like to use the graph-functions of Mathematica. As far as I understood, Mathematica by default uses a syntax like
Graph[1 -> 2, 2 -> 3, 3 -> 1]
Do you know of a quick way to use/convert/import my graph-format in Mathematica, or do I first need to convert my graph-files with some script to the correct Mathematica-input?
Thanks a lot for any help.
graphs-and-networks conversion
graphs-and-networks conversion
edited Aug 1 at 12:46
J. M. is away♦
100k10 gold badges315 silver badges473 bronze badges
100k10 gold badges315 silver badges473 bronze badges
asked Jul 30 at 11:29
Guest23232Guest23232
383 bronze badges
383 bronze badges
4
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (ExportGraph
) and import it in Mathematica (Import
).
$endgroup$
– Szabolcs
Jul 30 at 19:58
1
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30
add a comment |
4
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (ExportGraph
) and import it in Mathematica (Import
).
$endgroup$
– Szabolcs
Jul 30 at 19:58
1
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30
4
4
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (
ExportGraph
) and import it in Mathematica (Import
).$endgroup$
– Szabolcs
Jul 30 at 19:58
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (
ExportGraph
) and import it in Mathematica (Import
).$endgroup$
– Szabolcs
Jul 30 at 19:58
1
1
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4 *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0,
6, 1, 7, 2, 7, 7, 8, 6, 9, 4, 10, 2, 11, 4 *)
Use a rule to convert 3,0
to 3->0
and generate a list
list = pairs /. x_, y_ -> (x -> y)
(* 3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4 *)
Then graph it
Graph[list]
Update
In order to create 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. use MapIndexed
with pairs
as the input
MapIndexed[#1[[1]] -> #1[[2]], #2[[1]] &, pairs]
(* 3 -> 0, 1, 3 -> 0, 2, 3 -> 2, 3, 5 -> 1, 4,
5 -> 1, 5, 5 -> 4, 6, 6 -> 0, 7, 6 -> 1, 8, 7 -> 2, 9,
7 -> 7, 10, 8 -> 6, 11, 9 -> 4, 12, 10 -> 2, 13,
11 -> 4, 14
*)
$endgroup$
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number tryMax[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
add a comment |
$begingroup$
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ ""]]
to get the graph.
$endgroup$
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming[0,1]
toRule[0,1]
, so I changed my answer.
$endgroup$
– High Performance Mark
Jul 30 at 16:00
add a comment |
$begingroup$
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
,
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%2fmathematica.stackexchange.com%2fquestions%2f202976%2fconvert-graph-format-for-mathematica-graph-functions%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$
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4 *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0,
6, 1, 7, 2, 7, 7, 8, 6, 9, 4, 10, 2, 11, 4 *)
Use a rule to convert 3,0
to 3->0
and generate a list
list = pairs /. x_, y_ -> (x -> y)
(* 3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4 *)
Then graph it
Graph[list]
Update
In order to create 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. use MapIndexed
with pairs
as the input
MapIndexed[#1[[1]] -> #1[[2]], #2[[1]] &, pairs]
(* 3 -> 0, 1, 3 -> 0, 2, 3 -> 2, 3, 5 -> 1, 4,
5 -> 1, 5, 5 -> 4, 6, 6 -> 0, 7, 6 -> 1, 8, 7 -> 2, 9,
7 -> 7, 10, 8 -> 6, 11, 9 -> 4, 12, 10 -> 2, 13,
11 -> 4, 14
*)
$endgroup$
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number tryMax[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
add a comment |
$begingroup$
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4 *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0,
6, 1, 7, 2, 7, 7, 8, 6, 9, 4, 10, 2, 11, 4 *)
Use a rule to convert 3,0
to 3->0
and generate a list
list = pairs /. x_, y_ -> (x -> y)
(* 3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4 *)
Then graph it
Graph[list]
Update
In order to create 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. use MapIndexed
with pairs
as the input
MapIndexed[#1[[1]] -> #1[[2]], #2[[1]] &, pairs]
(* 3 -> 0, 1, 3 -> 0, 2, 3 -> 2, 3, 5 -> 1, 4,
5 -> 1, 5, 5 -> 4, 6, 6 -> 0, 7, 6 -> 1, 8, 7 -> 2, 9,
7 -> 7, 10, 8 -> 6, 11, 9 -> 4, 12, 10 -> 2, 13,
11 -> 4, 14
*)
$endgroup$
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number tryMax[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
add a comment |
$begingroup$
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4 *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0,
6, 1, 7, 2, 7, 7, 8, 6, 9, 4, 10, 2, 11, 4 *)
Use a rule to convert 3,0
to 3->0
and generate a list
list = pairs /. x_, y_ -> (x -> y)
(* 3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4 *)
Then graph it
Graph[list]
Update
In order to create 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. use MapIndexed
with pairs
as the input
MapIndexed[#1[[1]] -> #1[[2]], #2[[1]] &, pairs]
(* 3 -> 0, 1, 3 -> 0, 2, 3 -> 2, 3, 5 -> 1, 4,
5 -> 1, 5, 5 -> 4, 6, 6 -> 0, 7, 6 -> 1, 8, 7 -> 2, 9,
7 -> 7, 10, 8 -> 6, 11, 9 -> 4, 12, 10 -> 2, 13,
11 -> 4, 14
*)
$endgroup$
I am assuming that you can import the data as a string
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
Given that try these steps
Extract the numbers
digits = ToExpression[StringCases[data, DigitCharacter..]]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0, 6, 1, 7, 2, 7, 7,
8, 6, 9, 4, 10, 2, 11, 4 *)
Use Partition
to create pairs
pairs = Partition[digits, 2]
(* 3, 0, 3, 0, 3, 2, 5, 1, 5, 1, 5, 4, 6, 0,
6, 1, 7, 2, 7, 7, 8, 6, 9, 4, 10, 2, 11, 4 *)
Use a rule to convert 3,0
to 3->0
and generate a list
list = pairs /. x_, y_ -> (x -> y)
(* 3 -> 0, 3 -> 0, 3 -> 2, 5 -> 1, 5 -> 1, 5 -> 4, 6 -> 0,
6 -> 1, 7 -> 2, 7 -> 7, 8 -> 6, 9 -> 4, 10 -> 2, 11 -> 4 *)
Then graph it
Graph[list]
Update
In order to create 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. use MapIndexed
with pairs
as the input
MapIndexed[#1[[1]] -> #1[[2]], #2[[1]] &, pairs]
(* 3 -> 0, 1, 3 -> 0, 2, 3 -> 2, 3, 5 -> 1, 4,
5 -> 1, 5, 5 -> 4, 6, 6 -> 0, 7, 6 -> 1, 8, 7 -> 2, 9,
7 -> 7, 10, 8 -> 6, 11, 9 -> 4, 12, 10 -> 2, 13,
11 -> 4, 14
*)
edited Jul 31 at 12:31
answered Jul 30 at 13:59
Jack LaVigneJack LaVigne
12.5k2 gold badges17 silver badges32 bronze badges
12.5k2 gold badges17 silver badges32 bronze badges
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number tryMax[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
add a comment |
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number tryMax[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks a lot for your answer. It is exactly what I need and also taught me some new Mathematica things. It is not directly related to the initial question, but do you also know of a way how I could get the list in the form 3 -> 0, 1,3 -> 0, 2,3-> 2, 3.. and so on? For some manipulations I need to give the different elements of the graph these "indices", which I add with a "," after the arrow-part.
$endgroup$
– Guest23232
Jul 30 at 16:12
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
$begingroup$
Thanks for your answer, but I need to add these indices ( the "," and then the number of the pair that goes from 1 to total number of pairs) in Mathematica, it is not in my graph data yet. My first thought was something like x_, y_ -> x -> y,1 or so, but even if it worked, I would have a 1 everywhere, and not an index that goes from 1 to the total number of pairs, which I need to number my "edges" ( 1 edge being one pair of vertices in my list).
$endgroup$
– Guest23232
Jul 31 at 7:32
1
1
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
@Guest23232 See the update, sorry I had misread your original comment.
$endgroup$
– Jack LaVigne
Jul 31 at 12:32
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
Thank you a lot again, thats exactly what I needed. It is not directly related to the initial question again, but same within the same problem, so if may ask one last thing: Is there an easy way to find the largest number in the list expression with the "->" arrows ( before I add this additional index). I would like to avoid creating Graph[..] objects for that or many new replacements. So for the example above I would like to get 11. I cant just count the number of elements because I delete edges from time to time, so the highest number can higher than neccessary.
$endgroup$
– Guest23232
Jul 31 at 16:11
$begingroup$
To get the highest number try
Max[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
$begingroup$
To get the highest number try
Max[pair[[All, 1]]]
$endgroup$
– Jack LaVigne
Aug 1 at 0:38
add a comment |
$begingroup$
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ ""]]
to get the graph.
$endgroup$
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming[0,1]
toRule[0,1]
, so I changed my answer.
$endgroup$
– High Performance Mark
Jul 30 at 16:00
add a comment |
$begingroup$
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ ""]]
to get the graph.
$endgroup$
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming[0,1]
toRule[0,1]
, so I changed my answer.
$endgroup$
– High Performance Mark
Jul 30 at 16:00
add a comment |
$begingroup$
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ ""]]
to get the graph.
$endgroup$
Given data
(as defined by @Jack LaVigne),
data = "[3,0],[3,0],[3,2],[5,1],[5,1],[5,4],[6,0],[6,1],[7,2],[7,7],
[8,6],[9,4],[10,2],[11,4]"
I might just have written
Graph[ToExpression["" ~~ StringReplace[data, "[" -> "DirectedEdge["] ~~ ""]]
to get the graph.
edited Jul 30 at 15:59
answered Jul 30 at 15:03
High Performance MarkHigh Performance Mark
9556 silver badges14 bronze badges
9556 silver badges14 bronze badges
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming[0,1]
toRule[0,1]
, so I changed my answer.
$endgroup$
– High Performance Mark
Jul 30 at 16:00
add a comment |
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming[0,1]
toRule[0,1]
, so I changed my answer.
$endgroup$
– High Performance Mark
Jul 30 at 16:00
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming
[0,1]
to Rule[0,1]
, so I changed my answer.$endgroup$
– High Performance Mark
Jul 30 at 16:00
$begingroup$
On reading @kglr's answer I realised mine was deficient, in transforming
[0,1]
to Rule[0,1]
, so I changed my answer.$endgroup$
– High Performance Mark
Jul 30 at 16:00
add a comment |
$begingroup$
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]
$endgroup$
add a comment |
$begingroup$
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]
$endgroup$
add a comment |
$begingroup$
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]
$endgroup$
Stitching several functions together to get a function that takes a string containing edges in Maple format and all the options of Graph
:
ClearAll[mapleEdgesToGraph]
mapleEdgesToGraph = Graph[ToExpression @* ToString @* List @*
StringReplace["[" -> "DirectedEdge["] @ #, ##2]&;
Example: Using data
from Jack's answer:
mapleEdgesToGraph[data]
mapleEdgesToGraph[data,
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]
edited Jul 30 at 22:59
answered Jul 30 at 15:56
kglrkglr
210k10 gold badges241 silver badges480 bronze badges
210k10 gold badges241 silver badges480 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica 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%2fmathematica.stackexchange.com%2fquestions%2f202976%2fconvert-graph-format-for-mathematica-graph-functions%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
4
$begingroup$
Don't try to convert Maple code to Mathematica code. It makes no sense when you can simply export to a standard graph format from Maple (
ExportGraph
) and import it in Mathematica (Import
).$endgroup$
– Szabolcs
Jul 30 at 19:58
1
$begingroup$
I absolutely agree with Szabolcs' comment.
$endgroup$
– Henrik Schumacher
Jul 31 at 0:30