Message Boards Message Boards

Graph and network GUI creation with Yed & Wolfram: importing diagrams

I Have been working in some graph theory practical applications like PERT and Simple Line Assembly Balance Problem (Mainly Industrial Engineering topics) and I reached a workflow pretty replicable and comfortable that reduced my graph creation/edit time more than 30%.

Recommended case of use: When the graph you need to create have more than 6 nodes and more than 10 connections.

The tools we need are just a piece of open source software called Yed, it is free and well designed, basically it is a graph editor and diagram tool that will allow us to create our graphs to the import them into Mathematica.

  1. Open Yed And create a graph. To change the node label press ENTER and write the name, to change the edge weight do the same with the connection of two nodes. For instance, try the following graph:

Example Yed graph

  1. Go to File menu > Save as... and select GML
  2. You can use the import function, however I realized that the weights are not preserved and are turned into edge labels, also the vertex names are not the ones we write in the Yed editor. So I wrote this piece of code to change the properties and match them to the graph editor:

    TransformGML[file_] := Module[
      {g1, rules, vertex, edges, sus},
      g1 = Check[Import[file], Missing];
      vertex = VertexList[g1];
      edges = AnnotationValue[{g1, #}, EdgeLabels] & /@ EdgeRules[g1];
      rules = EdgeRules[g1];
      sus = AnnotationValue[g1, VertexLabels];
      Graph[Replace[#, sus, {1}] & /@ rules, EdgeWeight -> edges, 
       VertexLabels -> Thread[(sus[[All, 1]] /. sus) -> sus[[All, 2]]]]
      ]
    
  3. Run calculations into the new graph to verify that it matches the graphical editor:

    WeightedAdjacencyMatrix[g1] // MatrixForm
    
    0   15    20 0   0
    0   0 0   0 30
    0   0 0   5 0
    0   0 0   0 8
    0   0 0   0 0 
    
    Graph[g1, GraphStyle -> "IndexLabeled", EdgeLabels -> "EdgeWeight"]
    

Resulting into the (equivalent) graph:

Equivalent graph

I hope this may be helpful to someone, also if you have a better way to import external graph created files let me know!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract