Page 1 of 1

Creating a graph with edge properties

Posted: 26 Mar 2012, 10:28
by xammy
Hi,

I known how to create a new graph object visible in perl using the following code.

Code: Select all

perl::Object construct_graph(...) { Graph<> g(4); g.edge(0, 1); g.edge(1, 2); g.edge(2, 0); g.edge(0, 3); perl::Object result("graph::Graph<Undirected>"); result.take("ADJACENCY") << g; return result; }
How do I add edge properties (ints in my case) to it? If there are several ways - I'd like to have one such that it is easy to display these ints in a $graph->VISUAL; call.

Does graph::Graph allow parallel edges and loops?

Best regards,

Matthias

Re: Creating a graph with edge properties

Posted: 26 Mar 2012, 11:02
by herr
How do I add edge properties (ints in my case) to it?
It should be possible to add properties to edges by using an EdgeMap, e.g. see polymake/apps/graph/src/edge_lengths.cc.

Re: Creating a graph with edge properties

Posted: 26 Mar 2012, 15:30
by gawrilow
I'd like to have one such that it is easy to display these ints in a $graph->VISUAL; call.
The EdgeMaps (as well as NodeMaps) are not automatically involved in the visualization process. You'll have to find some way to make the values from the map visible, e.g. by using them as EdgeLabels or invent some color scheme based on them.
Does graph::Graph allow parallel edges and loops?
Loops are allowed, but not parallel edges.

Re: Creating a graph with edge properties

Posted: 27 Mar 2012, 09:47
by joswig
You'll have to find some way to make the values from the map visible, e.g. by using them as EdgeLabels or invent some color scheme based on them.
Actually, this will also depend on the visualization backend's capabilities. I am not sure if JReality and JavaView support edge labels at all.

Re: Creating a graph with edge properties

Posted: 28 Mar 2012, 16:58
by xammy
Does graph::Graph allow parallel edges and loops?
Loops are allowed, but not parallel edges.
Then I have a problem indeed - without parallel edges not all matroid decompositions for the TU test extension may be displayed correctly.

Re: Creating a graph with edge properties

Posted: 28 Mar 2012, 19:00
by joswig
Multigraphs do not exits in polymake yet. But they could be modeled as graphs of type props::graph with edge attributes of type int (to count the number of parallel edges). To avoid ambiguity one should probably restrict those attributes to positive integers.

In case that later anyone even needs edge attributes for multigraphs these could be modeled as one Array per edge (representing a parallel class of multiedges).

Re: Creating a graph with edge properties

Posted: 16 Apr 2012, 01:19
by gawrilow
Now multigraphs are implemented; please use the type Graph<DirectedMulti> or Graph<UndirectedMulti> depending on your needs (and, naturally, the same tag for EdgeMaps and other attribute maps attached to your graph). Please refer to the rulefile apps/common/rules/graph_types to get acquainted with new methods introduced for multigraphs.

As the implementation is quite fresh, it could still contain bugs undiscovered by unit tests; please feel free to report any problems or shortcomings immediately.

Re: Creating a graph with edge properties

Posted: 16 Apr 2012, 08:18
by xammy
Now multigraphs are implemented; ...
Very nice - I will start working on them as soon as I'm done with lots of other things! Thank you for the effort.