demo/hello_lemon.cc
author deba
Mon, 03 Apr 2006 09:45:23 +0000
changeset 2031 080d51024ac5
parent 1928 2e957d67d7b9
child 2391 14a343be7a5a
permissions -rw-r--r--
Correcting the structure of the graph's and adaptor's map.
The template assign operators and map iterators can be used for adaptors also.

Some bugfix in the adaptors

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