COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/hello_lemon.cc @ 1577:15098fb5275c

Last change on this file since 1577:15098fb5275c was 1530:d99c3c84f797, checked in by athos, 15 years ago

Doc.

File size: 1.6 KB
RevLine 
[1520]1#include <iostream>
2#include <lemon/list_graph.h>
3
4int main()
5{
6  typedef lemon::ListGraph Graph;
7  typedef Graph::EdgeIt EdgeIt;
[1530]8  typedef Graph::Edge Edge;
[1520]9  typedef Graph::NodeIt NodeIt;
[1530]10  typedef Graph::Node Node;
11  typedef Graph::EdgeMap<int> LengthMap;
[1520]12  using lemon::INVALID;
13
14  Graph g;
15 
[1530]16  Node s=g.addNode();
17  Node v2=g.addNode();
18  Node v3=g.addNode();
19  Node v4=g.addNode();
20  Node v5=g.addNode();
21  Node t=g.addNode();
22
23  Edge s_v2=g.addEdge(s, v2);
24  Edge s_v3=g.addEdge(s, v3);
25  Edge v2_v4=g.addEdge(v2, v4);
26  Edge v2_v5=g.addEdge(v2, v5);
27  Edge v3_v5=g.addEdge(v3, v5);
28  Edge v4_t=g.addEdge(v4, t);
29  Edge v5_t=g.addEdge(v5, t);
[1520]30 
[1530]31  LengthMap length(g);
32
33  length.set(s_v2, 10);
34  length.set(s_v3, 10);
35  length.set(v2_v4, 5);
36  length.set(v2_v5, 8);
37  length.set(v3_v5, 5);
38  length.set(v4_t, 8);
39  length.set(v5_t, 8);
[1520]40
[1526]41  std::cout << "Hello World!" << std::endl;
42  std::cout <<  std::endl;
43  std::cout << "This is library LEMON here! We have a graph!" << std::endl;
44  std::cout <<  std::endl;
45
[1520]46  std::cout << "Nodes:";
47  for (NodeIt i(g); i!=INVALID; ++i)
48    std::cout << " " << g.id(i);
49  std::cout << std::endl;
50
51  std::cout << "Edges:";
52  for (EdgeIt i(g); i!=INVALID; ++i)
53    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
54  std::cout << std::endl;
[1530]55  std::cout <<  std::endl;
56
57  std::cout << "There is a map on the edges (length)!" << std::endl;
58  std::cout <<  std::endl;
59  for (EdgeIt i(g); i!=INVALID; ++i)
60    std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
61
62  std::cout << std::endl;
63
[1520]64}
Note: See TracBrowser for help on using the repository browser.