Dear Polymake Team,
I'm struggling with creating an EdgeMap for a directed graph in my script. Could you give me a small example on how to create and modify those objects?
Kind Regards,
JR
Code: Select all
# this is your graph, can be created in any possible way:
my $G=new common::Graph<Directed>(number_or_nodes);
# this is the edge map:
my $M=new EdgeMap<Directed, MyDataType>($G);
# manipulate mapped values for single edges; non-existing edges are created automatically:
my $value = $M->edge($from_node, $to_node);
$M->edge($from_node, $to_node)=$new_value;
# iterate over all existing edges and use the mapped values:
for (my $edge_it=entire(edges($G)); $edge_it; ++$edge_it) {
my $from_node=$edge_it->from_node;
my $to_node=$edge_it->to_node;
my $value=$M->[$$edge_it];
$M->[$$edge_it]=$new_value;
}
# the same for edges starting or ending in a given node:
entire($G->out_edges($from_node)); ... entire($G->in_edges($to_node)); ...