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;








5












$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.










share|improve this question











$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

















5












$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.










share|improve this question











$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













5












5








5





$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.










share|improve this question











$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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










3 Answers
3






active

oldest

votes


















7












$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]


Mathematica graphics



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
*)





share|improve this answer











$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 try Max[pair[[All, 1]]]
    $endgroup$
    – Jack LaVigne
    Aug 1 at 0:38


















5












$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.






share|improve this answer











$endgroup$














  • $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


















5












$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]


enter image description here



mapleEdgesToGraph[data, 
GraphStyle -> "IndexLabeled",
EdgeStyle -> Blue,
GraphLayout -> "CircularEmbedding",
ImageSize -> Large]


enter image description here






share|improve this answer











$endgroup$

















    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
    );



    );













    draft saved

    draft discarded


















    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









    7












    $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]


    Mathematica graphics



    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
    *)





    share|improve this answer











    $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 try Max[pair[[All, 1]]]
      $endgroup$
      – Jack LaVigne
      Aug 1 at 0:38















    7












    $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]


    Mathematica graphics



    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
    *)





    share|improve this answer











    $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 try Max[pair[[All, 1]]]
      $endgroup$
      – Jack LaVigne
      Aug 1 at 0:38













    7












    7








    7





    $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]


    Mathematica graphics



    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
    *)





    share|improve this answer











    $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]


    Mathematica graphics



    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
    *)






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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 try Max[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 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 try Max[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













    5












    $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.






    share|improve this answer











    $endgroup$














    • $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















    5












    $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.






    share|improve this answer











    $endgroup$














    • $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













    5












    5








    5





    $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.






    share|improve this answer











    $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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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] 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















    $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











    5












    $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]


    enter image description here



    mapleEdgesToGraph[data, 
    GraphStyle -> "IndexLabeled",
    EdgeStyle -> Blue,
    GraphLayout -> "CircularEmbedding",
    ImageSize -> Large]


    enter image description here






    share|improve this answer











    $endgroup$



















      5












      $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]


      enter image description here



      mapleEdgesToGraph[data, 
      GraphStyle -> "IndexLabeled",
      EdgeStyle -> Blue,
      GraphLayout -> "CircularEmbedding",
      ImageSize -> Large]


      enter image description here






      share|improve this answer











      $endgroup$

















        5












        5








        5





        $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]


        enter image description here



        mapleEdgesToGraph[data, 
        GraphStyle -> "IndexLabeled",
        EdgeStyle -> Blue,
        GraphLayout -> "CircularEmbedding",
        ImageSize -> Large]


        enter image description here






        share|improve this answer











        $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]


        enter image description here



        mapleEdgesToGraph[data, 
        GraphStyle -> "IndexLabeled",
        EdgeStyle -> Blue,
        GraphLayout -> "CircularEmbedding",
        ImageSize -> Large]


        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        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






























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?