athos@1583: /* -*- C++ -*- ladanyi@1636: * demo/hello_lemon.cc - Part of LEMON, a generic C++ optimization library athos@1583: * alpar@1875: * Copyright (C) 2006 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport athos@1583: * (Egervary Research Group on Combinatorial Optimization, EGRES). athos@1583: * athos@1583: * Permission to use, modify and distribute this software is granted athos@1583: * provided that this copyright notice appears in all copies. For athos@1583: * precise terms see the accompanying LICENSE file. athos@1583: * athos@1583: * This software is provided "AS IS" with no warranty of any kind, athos@1583: * express or implied, and with no claim as to its suitability for any athos@1583: * purpose. athos@1583: * athos@1583: */ athos@1583: athos@1583: ///\ingroup demos athos@1583: ///\file athos@1583: ///\brief LEMON style "Hello World!" program athos@1583: /// athos@1583: /// This program is intended to be a "Hello World!" program that shows athos@1583: /// the very basic notions of the LEMON library: \ref graphs "graphs" and athos@1583: /// \ref maps-page "maps". Click on the links to read more about these. alpar@1641: /// alpar@1641: /// \include hello_lemon.cc athos@1583: klao@1520: #include klao@1520: #include klao@1520: klao@1520: int main() klao@1520: { klao@1520: typedef lemon::ListGraph Graph; klao@1520: typedef Graph::EdgeIt EdgeIt; athos@1530: typedef Graph::Edge Edge; klao@1520: typedef Graph::NodeIt NodeIt; athos@1530: typedef Graph::Node Node; athos@1530: typedef Graph::EdgeMap LengthMap; klao@1520: using lemon::INVALID; klao@1520: klao@1520: Graph g; klao@1520: athos@1530: Node s=g.addNode(); athos@1530: Node v2=g.addNode(); athos@1530: Node v3=g.addNode(); athos@1530: Node v4=g.addNode(); athos@1530: Node v5=g.addNode(); athos@1530: Node t=g.addNode(); athos@1530: athos@1530: Edge s_v2=g.addEdge(s, v2); athos@1530: Edge s_v3=g.addEdge(s, v3); athos@1530: Edge v2_v4=g.addEdge(v2, v4); athos@1530: Edge v2_v5=g.addEdge(v2, v5); athos@1530: Edge v3_v5=g.addEdge(v3, v5); athos@1530: Edge v4_t=g.addEdge(v4, t); athos@1530: Edge v5_t=g.addEdge(v5, t); klao@1520: athos@1530: LengthMap length(g); athos@1530: athos@1530: length.set(s_v2, 10); athos@1530: length.set(s_v3, 10); athos@1530: length.set(v2_v4, 5); athos@1530: length.set(v2_v5, 8); athos@1530: length.set(v3_v5, 5); athos@1530: length.set(v4_t, 8); athos@1530: length.set(v5_t, 8); klao@1520: athos@1526: std::cout << "Hello World!" << std::endl; athos@1526: std::cout << std::endl; athos@1526: std::cout << "This is library LEMON here! We have a graph!" << std::endl; athos@1526: std::cout << std::endl; athos@1526: klao@1520: std::cout << "Nodes:"; klao@1520: for (NodeIt i(g); i!=INVALID; ++i) klao@1520: std::cout << " " << g.id(i); klao@1520: std::cout << std::endl; klao@1520: klao@1520: std::cout << "Edges:"; klao@1520: for (EdgeIt i(g); i!=INVALID; ++i) klao@1520: std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")"; klao@1520: std::cout << std::endl; athos@1530: std::cout << std::endl; athos@1530: athos@1530: std::cout << "There is a map on the edges (length)!" << std::endl; athos@1530: std::cout << std::endl; athos@1530: for (EdgeIt i(g); i!=INVALID; ++i) alpar@1641: std::cout << "length(" << g.id(g.source(i)) << "," alpar@1641: << g.id(g.target(i)) << ")="<