L E D A Static Graphs

Example: Static Graphs

The simple example illustrates how to create a small graph and to assign some values.
To see how static graphs can be used in a max flow algorithm - please see the source file mfs.c in the directory test/flow.

#include <LEDA/static_graph.h>
#include <LEDA/node_slot.h>
#include <LEDA/edge_slot.h>
#include <LEDA/array.h>

using namespace leda;

struct node_weight:public data_slots<0>
{ int weight; }

struct edge_cap:public data_slots<0>
{ int cap; }

typedef static_graph<opposite_graph, node_weight, edge_cap> st_graph;
typedef st_graph::node st_node;
typedef st_graph::edge st_edge;

int main ()
        st_graph G;
        array<st_node> v(4);
        array<st_edge> e(4);

        for(int i =0; i < 4; i++) v[i] = G.new_node();

        e[0] = G.new_edge(v[0], v[1]);
        e[1] = G.new_edge(v[0], v[2]);
        e[2] = G.new_edge(v[1], v[2]);
        e[3] = G.new_edge(v[3], v[1]);
        st_node v;
        st_edge e;
        forall_nodes(v, G) v->weight = 1;
        forall_edges(e, G) e->cap = 10;

        return 0;



Help   Legal     Copyright 2004 Algorithmic Solutions Software GmbH