4

I am using Yed to paint some graphs as shown in the picture below. Is there a way I can use python to compute a Depth-First exploration on these? I would like the algorithm to protocol the Edges he has traveled and the nodes he visited.

Example graph: example graph

Edit: I would like to use this method to record actions of people in a sports game. At first you start at a base/Root, then you can run or jump (c or d). Running brings you to point 2, jumping to point 5. The result that I need then is:

1. root, ([c,2] ,[b,3]), Descript_3 2. root, ([c,2] ,[a,4]), Descript_4 3. root, ([c,2] ,[b,2], [a,4]), Descript_4 ... 

I am just using yed, so I can use a graphical interface. If there is something better in pure python, I am all up for it. But lets stick to yed for now. Can I get additional attributes to the nodes?

Edit: Since I cannot get this thing to work for myself, I am setting a bounty for an example program. The example program should do the following:

1. Parse the graphml-File and build up the tree 2. Compute all Roundtrip-Path with Node-Coverage 3. write all paths into a table: Name of the node, Text on the arrow 

From there I can figure the rest out myself. If its done by using librarys, then that's cool too, but I need to be able to extend it myself. I would also have it to be able to handle graphs, instead of trees.

1
  • The path is supposed to go from root to 2, from 2 to 4. The edges that lead there are named : c,a. So yes you are right, this is a typo. Thanks Commented Apr 14, 2015 at 12:27

1 Answer 1

3

You can use the networkx module (need to be installed pip install networkx). This module is a powerfull library for working with graphs. It can read the graphml format which yed produces and has algorithems for traversing a graph. Have a look at the documentation of it: networkx

Sign up to request clarification or add additional context in comments.

5 Comments

@Micheled'Amico Wrong, networkx can read the lables. You just have to explisitly ask the edges or nodes methode of the graph object to include the data in the output (call it with data=True).
@Micheled'Amico Can you post the graphml file.
Strange! I can reproduce your observation with your file. On the other hand I have created the same graph with yEd version 3.13 and I can see the node lables in networkx too. The main difference is that the nodetype is <y:ShapeNode> and in your example it is <y:GenericNode configuration="com.yworks.flowchart.terminator">.
Is there also a version for windows?
The module networkx works on windows as well as linux. Installation is described here: networkx.github.io/documentation/networkx-1.9.1/install.html

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.