demo/hello_lemon.cc
author ladanyi
Wed, 17 Aug 2005 12:35:43 +0000
changeset 1634 910b1bcb7d05
parent 1530 d99c3c84f797
child 1636 260ac104190f
permissions -rw-r--r--
Toolbar has custom icons now. Works only when installed.
     1 /* -*- C++ -*-
     2  * demo/lp_maxflow_demo.cc - Part of LEMON, a generic C++ optimization library
     3  *
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     6  *
     7  * Permission to use, modify and distribute this software is granted
     8  * provided that this copyright notice appears in all copies. For
     9  * precise terms see the accompanying LICENSE file.
    10  *
    11  * This software is provided "AS IS" with no warranty of any kind,
    12  * express or implied, and with no claim as to its suitability for any
    13  * purpose.
    14  *
    15  */
    16 
    17 ///\ingroup demos
    18 ///\file
    19 ///\brief LEMON style "Hello World!" program
    20 ///
    21 /// This program is intended to be a "Hello World!" program that shows
    22 /// the very basic notions of the LEMON library: \ref graphs "graphs" and
    23 /// \ref maps-page "maps". Click on the links to read more about these.
    24 
    25 #include <iostream>
    26 #include <lemon/list_graph.h>
    27 
    28 int main()
    29 {
    30   typedef lemon::ListGraph Graph;
    31   typedef Graph::EdgeIt EdgeIt;
    32   typedef Graph::Edge Edge;
    33   typedef Graph::NodeIt NodeIt;
    34   typedef Graph::Node Node;
    35   typedef Graph::EdgeMap<int> LengthMap;
    36   using lemon::INVALID;
    37 
    38   Graph g;
    39   
    40   Node s=g.addNode();
    41   Node v2=g.addNode();
    42   Node v3=g.addNode();
    43   Node v4=g.addNode();
    44   Node v5=g.addNode();
    45   Node t=g.addNode();
    46 
    47   Edge s_v2=g.addEdge(s, v2);
    48   Edge s_v3=g.addEdge(s, v3);
    49   Edge v2_v4=g.addEdge(v2, v4);
    50   Edge v2_v5=g.addEdge(v2, v5);
    51   Edge v3_v5=g.addEdge(v3, v5);
    52   Edge v4_t=g.addEdge(v4, t);
    53   Edge v5_t=g.addEdge(v5, t);
    54   
    55   LengthMap length(g);
    56 
    57   length.set(s_v2, 10);
    58   length.set(s_v3, 10);
    59   length.set(v2_v4, 5);
    60   length.set(v2_v5, 8);
    61   length.set(v3_v5, 5);
    62   length.set(v4_t, 8);
    63   length.set(v5_t, 8);
    64 
    65   std::cout << "Hello World!" << std::endl;
    66   std::cout <<  std::endl;
    67   std::cout << "This is library LEMON here! We have a graph!" << std::endl;
    68   std::cout <<  std::endl;
    69 
    70   std::cout << "Nodes:";
    71   for (NodeIt i(g); i!=INVALID; ++i)
    72     std::cout << " " << g.id(i);
    73   std::cout << std::endl;
    74 
    75   std::cout << "Edges:";
    76   for (EdgeIt i(g); i!=INVALID; ++i)
    77     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
    78   std::cout << std::endl;
    79   std::cout <<  std::endl;
    80 
    81   std::cout << "There is a map on the edges (length)!" << std::endl;
    82   std::cout <<  std::endl;
    83   for (EdgeIt i(g); i!=INVALID; ++i)
    84     std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
    85 
    86   std::cout << std::endl;
    87 
    88 }