1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
20 ///\brief Demonstrating the basic concepts and fetures of LEMON
22 /// This program is intended to be a "Hello World!" program that shows
23 /// the very basic notions of LEMON: \ref graphs "graphs" and
26 /// \include hello_lemon.cc
29 #include <lemon/list_graph.h>
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;
42 // Create a directed graph
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();
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);
58 // Create an arc map (length)
61 // Set the length of each arc
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;
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;
79 // Iterate through the arcs and print the IDs of their
80 // source and target nodes
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;
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;