# Changeset 16:ed4c8506e151 in lemon-tutorial for demo

Ignore:
Timestamp:
11/03/08 23:46:30 (12 years ago)
Branch:
default
Phase:
public
Message:

Simplify the first example code + fix toc

File:
1 edited

Unmodified
Added
Removed
• ## demo/hello_lemon.cc

 r5 ///\file ///\brief Demonstrating the basic concepts and fetures of LEMON ///\brief Simple "Hello World!" program for LEMON. /// /// This program is intended to be a "Hello World!" program that shows /// the very basic notions of LEMON: \ref graphs "graphs" and /// \ref maps "maps". /// /// Simple "Hello World!" program for LEMON. /// \include hello_lemon.cc int main() { // Convenience type definitions typedef lemon::ListDigraph Digraph; typedef Digraph::Node Node; typedef Digraph::Arc Arc; typedef Digraph::NodeIt NodeIt; typedef Digraph::ArcIt ArcIt; typedef Digraph::ArcMap LengthMap; using lemon::INVALID; typedef lemon::ListDigraph Graph; Graph g; // Create a directed graph Digraph g; Graph::Node u = g.addNode(); Graph::Node v = g.addNode(); Graph::Arc  e = g.addArc(u, v); // Add nodes to the digraph Node v1 = g.addNode(); Node v2 = g.addNode(); Node v3 = g.addNode(); Node v4 = g.addNode(); // Add arcs to the digraph Arc v1_v2 = g.addArc(v1, v2); Arc v1_v3 = g.addArc(v1, v3); Arc v2_v3 = g.addArc(v2, v3); Arc v2_v4 = g.addArc(v2, v4); Arc v3_v4 = g.addArc(v3, v4); // Create an arc map (length) LengthMap length(g); // Set the length of each arc length[v1_v2]  = 10; length[v1_v3]  = 20; length[v2_v3] = 5; length[v2_v4] = 25; length[v3_v4] = 10; // Welcome message std::cout << "Hello World!" << std::endl; std::cout << "This is LEMON library here. We have a direceted graph."; std::cout << std::endl << std::endl; // Iterate through the nodes and print their IDs std::cout << "Nodes:"; for (NodeIt n(g); n != INVALID; ++n) std::cout << " " << g.id(n); std::cout << std::endl; // Iterate through the arcs and print the IDs of their // source and target nodes std::cout << "Arcs:"; for (ArcIt a(g); a != INVALID; ++a) std::cout << " (" << g.id(g.source(a)) << "," << g.id(g.target(a)) << ")"; std::cout << std::endl << std::endl; // Iterate through the arcs and print their length std::cout << "There is a map on the arcs (length):" << std::endl; std::cout << std::endl; for (ArcIt a(g); a != INVALID; ++a) std::cout << "length(" << g.id(g.source(a)) << "," << g.id(g.target(a)) << ")=" << length[a] << std::endl; std::cout << std::endl; std::cout << "Hello World! This is LEMON library here." << std::endl; std::cout << "We have a directed graph with " << countNodes(g) << " nodes and " << countArcs(g) << " arc." << std::endl; return 0;
Note: See TracChangeset for help on using the changeset viewer.