demo/hello_lemon.cc
changeset 1533 43c7b3085212
parent 1526 8c14aa8f27a2
child 1583 2b329fd595ef
equal deleted inserted replaced
1:458c7f3409ed 2:45829129223c
     3 
     3 
     4 int main()
     4 int main()
     5 {
     5 {
     6   typedef lemon::ListGraph Graph;
     6   typedef lemon::ListGraph Graph;
     7   typedef Graph::EdgeIt EdgeIt;
     7   typedef Graph::EdgeIt EdgeIt;
       
     8   typedef Graph::Edge Edge;
     8   typedef Graph::NodeIt NodeIt;
     9   typedef Graph::NodeIt NodeIt;
       
    10   typedef Graph::Node Node;
       
    11   typedef Graph::EdgeMap<int> LengthMap;
     9   using lemon::INVALID;
    12   using lemon::INVALID;
    10 
    13 
    11   Graph g;
    14   Graph g;
    12   
    15   
    13   for (int i = 0; i < 3; i++)
    16   Node s=g.addNode();
    14     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);
    15   
    30   
    16   for (NodeIt i(g); i!=INVALID; ++i)
    31   LengthMap length(g);
    17     for (NodeIt j(g); j!=INVALID; ++j)
    32 
    18       if (i != j) g.addEdge(i, j);
    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);
    19 
    40 
    20   std::cout << "Hello World!" << std::endl;
    41   std::cout << "Hello World!" << std::endl;
    21   std::cout <<  std::endl;
    42   std::cout <<  std::endl;
    22   std::cout << "This is library LEMON here! We have a graph!" << std::endl;
    43   std::cout << "This is library LEMON here! We have a graph!" << std::endl;
    23   std::cout <<  std::endl;
    44   std::cout <<  std::endl;
    29 
    50 
    30   std::cout << "Edges:";
    51   std::cout << "Edges:";
    31   for (EdgeIt i(g); i!=INVALID; ++i)
    52   for (EdgeIt i(g); i!=INVALID; ++i)
    32     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
    53     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
    33   std::cout << std::endl;
    54   std::cout << std::endl;
       
    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 
    34 }
    64 }