COIN-OR::LEMON - Graph Library

Ticket #596: main.cpp

File main.cpp, 1.2 KB (added by Robert Lieck, 9 years ago)

source code

Line 
1#include <iostream>
2#include <vector>
3
4#include <lemon/list_graph.h>
5#include <lemon/dfs.h>
6
7using std::vector;
8using std::cout;
9using std::endl;
10
11int main(int,char**) {
12
13    typedef lemon::ListDigraph graph_t;
14    typedef graph_t::Node Node;
15    typedef graph_t::NodeIt NodeIt;
16
17    // define a simple graph
18    graph_t graph;
19    Node n0 = graph.addNode();
20    Node n1 = graph.addNode();
21    Node n2 = graph.addNode();
22    Node n3 = graph.addNode();
23    graph.addArc(n0, n3);
24    graph.addArc(n1, n2);
25
26    // add the same two nodes to DFS but in different order
27    vector<Node> list_1({n1,n0});
28    vector<Node> list_2({n0,n1});
29    for(auto list : {list_1,list_2}) {
30        lemon::Dfs<graph_t> search(graph);
31        search.init();
32        for(Node node : list) {
33            cout << "add node " << graph.id(node) << endl;
34            search.addSource(node);
35        }
36        search.start();
37        for(NodeIt node(graph); node!=lemon::INVALID; ++node) {
38            if(search.reached(node)) {
39                cout << "node " << graph.id(node) << ": reached" << endl;
40            } else {
41                cout << "node " << graph.id(node) << ": NOT reached" << endl;
42            }
43        }
44        cout << endl;
45    }
46}