COIN-OR::LEMON - Graph Library

Changeset 16:ed4c8506e151 in lemon-tutorial for demo/hello_lemon.cc


Ignore:
Timestamp:
11/03/08 23:46:30 (11 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Simplify the first example code + fix toc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • demo/hello_lemon.cc

    r5 r16  
    1818
    1919///\file
    20 ///\brief Demonstrating the basic concepts and fetures of LEMON
     20///\brief Simple "Hello World!" program for LEMON.
    2121///
    22 /// This program is intended to be a "Hello World!" program that shows
    23 /// the very basic notions of LEMON: \ref graphs "graphs" and
    24 /// \ref maps "maps".
    25 ///
     22/// Simple "Hello World!" program for LEMON.
    2623/// \include hello_lemon.cc
    2724
     
    3128int main()
    3229{
    33   // Convenience type definitions
    34   typedef lemon::ListDigraph Digraph;
    35   typedef Digraph::Node Node;
    36   typedef Digraph::Arc Arc;
    37   typedef Digraph::NodeIt NodeIt;
    38   typedef Digraph::ArcIt ArcIt;
    39   typedef Digraph::ArcMap<int> LengthMap;
    40   using lemon::INVALID;
     30  typedef lemon::ListDigraph Graph;
     31  Graph g;
    4132
    42   // Create a directed graph
    43   Digraph g;
     33  Graph::Node u = g.addNode();
     34  Graph::Node v = g.addNode();
     35  Graph::Arc  e = g.addArc(u, v);
    4436
    45   // Add nodes to the digraph
    46   Node v1 = g.addNode();
    47   Node v2 = g.addNode();
    48   Node v3 = g.addNode();
    49   Node v4 = g.addNode();
    50 
    51   // Add arcs to the digraph
    52   Arc v1_v2 = g.addArc(v1, v2);
    53   Arc v1_v3 = g.addArc(v1, v3);
    54   Arc v2_v3 = g.addArc(v2, v3);
    55   Arc v2_v4 = g.addArc(v2, v4);
    56   Arc v3_v4 = g.addArc(v3, v4);
    57 
    58   // Create an arc map (length)
    59   LengthMap length(g);
    60 
    61   // Set the length of each arc
    62   length[v1_v2]  = 10;
    63   length[v1_v3]  = 20;
    64   length[v2_v3] = 5;
    65   length[v2_v4] = 25;
    66   length[v3_v4] = 10;
    67 
    68   // Welcome message
    69   std::cout << "Hello World!" << std::endl;
    70   std::cout << "This is LEMON library here. We have a direceted graph.";
    71   std::cout << std::endl << std::endl;
    72 
    73   // Iterate through the nodes and print their IDs
    74   std::cout << "Nodes:";
    75   for (NodeIt n(g); n != INVALID; ++n)
    76     std::cout << " " << g.id(n);
    77   std::cout << std::endl;
    78 
    79   // Iterate through the arcs and print the IDs of their
    80   // source and target nodes
    81   std::cout << "Arcs:";
    82   for (ArcIt a(g); a != INVALID; ++a)
    83     std::cout << " (" << g.id(g.source(a)) << ","
    84               << g.id(g.target(a)) << ")";
    85   std::cout << std::endl << std::endl;
    86 
    87   // Iterate through the arcs and print their length
    88   std::cout << "There is a map on the arcs (length):" << std::endl;
    89   std::cout << std::endl;
    90   for (ArcIt a(g); a != INVALID; ++a)
    91     std::cout << "length(" << g.id(g.source(a)) << ","
    92               << g.id(g.target(a)) << ")=" << length[a] << std::endl;
    93   std::cout << std::endl;
     37  std::cout << "Hello World! This is LEMON library here." << std::endl;
     38  std::cout << "We have a directed graph with "
     39            << countNodes(g) << " nodes and "
     40            << countArcs(g) << " arc." << std::endl;
    9441
    9542  return 0;
Note: See TracChangeset for help on using the changeset viewer.