kpeter@5: /* -*- mode: C++; indent-tabs-mode: nil; -*- kpeter@5: * kpeter@5: * This file is a part of LEMON, a generic C++ optimization library. kpeter@5: * kpeter@5: * Copyright (C) 2003-2008 kpeter@5: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport kpeter@5: * (Egervary Research Group on Combinatorial Optimization, EGRES). kpeter@5: * kpeter@5: * Permission to use, modify and distribute this software is granted kpeter@5: * provided that this copyright notice appears in all copies. For kpeter@5: * precise terms see the accompanying LICENSE file. kpeter@5: * kpeter@5: * This software is provided "AS IS" with no warranty of any kind, kpeter@5: * express or implied, and with no claim as to its suitability for any kpeter@5: * purpose. kpeter@5: * kpeter@5: */ kpeter@5: kpeter@5: ///\file kpeter@5: ///\brief Demonstrating the basic concepts and fetures of LEMON kpeter@5: /// kpeter@5: /// This program is intended to be a "Hello World!" program that shows kpeter@5: /// the very basic notions of LEMON: \ref graphs "graphs" and kpeter@5: /// \ref maps "maps". kpeter@5: /// kpeter@5: /// \include hello_lemon.cc kpeter@5: kpeter@5: #include kpeter@5: #include kpeter@5: kpeter@5: int main() kpeter@5: { kpeter@5: // Convenience type definitions kpeter@5: typedef lemon::ListDigraph Digraph; kpeter@5: typedef Digraph::Node Node; kpeter@5: typedef Digraph::Arc Arc; kpeter@5: typedef Digraph::NodeIt NodeIt; kpeter@5: typedef Digraph::ArcIt ArcIt; kpeter@5: typedef Digraph::ArcMap LengthMap; kpeter@5: using lemon::INVALID; kpeter@5: kpeter@5: // Create a directed graph kpeter@5: Digraph g; kpeter@5: kpeter@5: // Add nodes to the digraph kpeter@5: Node v1 = g.addNode(); kpeter@5: Node v2 = g.addNode(); kpeter@5: Node v3 = g.addNode(); kpeter@5: Node v4 = g.addNode(); kpeter@5: kpeter@5: // Add arcs to the digraph kpeter@5: Arc v1_v2 = g.addArc(v1, v2); kpeter@5: Arc v1_v3 = g.addArc(v1, v3); kpeter@5: Arc v2_v3 = g.addArc(v2, v3); kpeter@5: Arc v2_v4 = g.addArc(v2, v4); kpeter@5: Arc v3_v4 = g.addArc(v3, v4); kpeter@5: kpeter@5: // Create an arc map (length) kpeter@5: LengthMap length(g); kpeter@5: kpeter@5: // Set the length of each arc kpeter@5: length[v1_v2] = 10; kpeter@5: length[v1_v3] = 20; kpeter@5: length[v2_v3] = 5; kpeter@5: length[v2_v4] = 25; kpeter@5: length[v3_v4] = 10; kpeter@5: kpeter@5: // Welcome message kpeter@5: std::cout << "Hello World!" << std::endl; kpeter@5: std::cout << "This is LEMON library here. We have a direceted graph."; kpeter@5: std::cout << std::endl << std::endl; kpeter@5: kpeter@5: // Iterate through the nodes and print their IDs kpeter@5: std::cout << "Nodes:"; kpeter@5: for (NodeIt n(g); n != INVALID; ++n) kpeter@5: std::cout << " " << g.id(n); kpeter@5: std::cout << std::endl; kpeter@5: kpeter@5: // Iterate through the arcs and print the IDs of their kpeter@5: // source and target nodes kpeter@5: std::cout << "Arcs:"; kpeter@5: for (ArcIt a(g); a != INVALID; ++a) kpeter@5: std::cout << " (" << g.id(g.source(a)) << "," kpeter@5: << g.id(g.target(a)) << ")"; kpeter@5: std::cout << std::endl << std::endl; kpeter@5: kpeter@5: // Iterate through the arcs and print their length kpeter@5: std::cout << "There is a map on the arcs (length):" << std::endl; kpeter@5: std::cout << std::endl; kpeter@5: for (ArcIt a(g); a != INVALID; ++a) kpeter@5: std::cout << "length(" << g.id(g.source(a)) << "," kpeter@5: << g.id(g.target(a)) << ")=" << length[a] << std::endl; kpeter@5: std::cout << std::endl; kpeter@5: kpeter@5: return 0; kpeter@5: }