COIN-OR::LEMON - Graph Library

Ticket #81: port_hello_lemon_9309a3751e39.patch

File port_hello_lemon_9309a3751e39.patch, 4.1 KB (added by Peter Kovacs, 15 years ago)

Port demo/hello_lemon.cc

  • demo/CMakeLists.txt

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1215441554 -7200
    # Node ID 9309a3751e39419bc6664a9ac4122558493c0205
    # Parent  65cba1032f90cd157a56b911b4917920b07fc546
    Port demo/hello_lemon.cc from SVN -r3501
    
    diff -r 65cba1032f90 -r 9309a3751e39 demo/CMakeLists.txt
    a b  
    55set (DEMOS
    66  arg_parser_demo
    77  graph_to_eps_demo
     8  hello_lemon
    89  lgf_demo)
    910
    1011foreach (DEMO_NAME ${DEMOS})
  • demo/Makefile.am

    diff -r 65cba1032f90 -r 9309a3751e39 demo/Makefile.am
    a b  
    77noinst_PROGRAMS += \
    88        demo/arg_parser_demo \
    99        demo/graph_to_eps_demo \
     10        demo/hello_lemon \
    1011        demo/lgf_demo
    1112
    1213endif WANT_DEMO
    1314
    1415demo_arg_parser_demo_SOURCES = demo/arg_parser_demo.cc
    1516demo_graph_to_eps_demo_SOURCES = demo/graph_to_eps_demo.cc
     17demo_hello_lemon_SOURCES = demo/hello_lemon.cc
    1618demo_lgf_demo_SOURCES = demo/lgf_demo.cc
  • new file demo/hello_lemon.cc

    diff -r 65cba1032f90 -r 9309a3751e39 demo/hello_lemon.cc
    - +  
     1/* -*- C++ -*-
     2 *
     3 * This file is a part of LEMON, a generic C++ optimization library
     4 *
     5 * Copyright (C) 2003-2008
     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 Demonstrating the very basic notions of LEMON
     22///
     23/// This program is intended to be a "Hello World!" program that shows
     24/// the very basic notions of LEMON: \ref graphs "graphs" and
     25/// \ref maps-page "maps".
     26///
     27/// \include hello_lemon.cc
     28
     29#include <iostream>
     30#include <lemon/list_graph.h>
     31
     32int main()
     33{
     34  // Convenient type definitions
     35  typedef lemon::ListDigraph Digraph;
     36  typedef Digraph::Node Node;
     37  typedef Digraph::Arc Arc;
     38  typedef Digraph::NodeIt NodeIt;
     39  typedef Digraph::ArcIt ArcIt;
     40  typedef Digraph::ArcMap<int> LengthMap;
     41  using lemon::INVALID;
     42
     43  // Create a directed graph
     44  Digraph g;
     45 
     46  // Add nodes to the digraph
     47  Node s  = g.addNode();
     48  Node v2 = g.addNode();
     49  Node v3 = g.addNode();
     50  Node v4 = g.addNode();
     51  Node v5 = g.addNode();
     52  Node t  = g.addNode();
     53
     54  // Add arcs to the digraph
     55  Arc s_v2  = g.addArc(s, v2);
     56  Arc s_v3  = g.addArc(s, v3);
     57  Arc v2_v4 = g.addArc(v2, v4);
     58  Arc v2_v5 = g.addArc(v2, v5);
     59  Arc v3_v5 = g.addArc(v3, v5);
     60  Arc v4_t  = g.addArc(v4, t);
     61  Arc v5_t  = g.addArc(v5, t);
     62 
     63  // Create an arc map (length)
     64  LengthMap length(g);
     65 
     66  // Set the length of each arc
     67  length[s_v2]  = 10;
     68  length[s_v3]  = 10;
     69  length[v2_v4] = 5;
     70  length[v2_v5] = 8;
     71  length[v3_v5] = 5;
     72  length[v4_t]  = 8;
     73  length[v5_t]  = 8;
     74
     75  std::cout << "Hello World!" << std::endl;
     76  std::cout << std::endl;
     77  std::cout << "This is library LEMON here. We have a direceted graph.";
     78  std::cout << std::endl << std::endl;
     79
     80  // Iterate through the nodes and print their IDs
     81  std::cout << "Nodes:";
     82  for (NodeIt n(g); n != INVALID; ++n)
     83    std::cout << " " << g.id(n);
     84  std::cout << std::endl;
     85
     86  // Iterate through the arcs and print the IDs of their
     87  // source and target nodes
     88  std::cout << "Arcs:";
     89  for (ArcIt a(g); a != INVALID; ++a)
     90    std::cout << " (" << g.id(g.source(a)) << ","
     91              << g.id(g.target(a)) << ")";
     92  std::cout << std::endl << std::endl;
     93
     94  // Iterate through the arcs and print their length
     95  std::cout << "There is a map on the arcs (length):" << std::endl;
     96  std::cout << std::endl;
     97  for (ArcIt a(g); a != INVALID; ++a)
     98    std::cout << "length(" << g.id(g.source(a)) << ","
     99              << g.id(g.target(a)) << ")=" << length[a] << std::endl;
     100  std::cout << std::endl;
     101 
     102  return 0;
     103}