COIN-OR::LEMON - Graph Library

Changeset 58:10b6a5b7d4c0 in lemon-tutorial for maps.dox


Ignore:
Timestamp:
03/01/10 02:30:00 (14 years ago)
Author:
Peter Kovacs <kpeter@…>
Branch:
default
Phase:
public
Message:

Improve Algorithms section (it is still under construction)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • maps.dox

    r57 r58  
    3636These classes also conform to the map %concepts, thus they can be used
    3737like standard LEMON maps.
    38 
    39 Let us suppose that we have a traffic network stored in a LEMON digraph
    40 structure with two arc maps \c length and \c speed, which
    41 denote the physical length of each arc and the maximum (or average)
    42 speed that can be achieved on the corresponding road-section,
    43 respectively. If we are interested in the best traveling times,
    44 the following code can be used.
    45 
    46 \code
    47   dijkstra(g, divMap(length, speed)).distMap(dist).run(s);
    48 \endcode
    49 
    5038
    5139Maps play a central role in LEMON. As their name suggests, they map a
     
    336324[SEC]sec_algs_with_maps[SEC] Using Algorithms with Special Maps
    337325
     326
    338327The basic functionality of the algorithms can be highly extended using
    339328special purpose map types for their internal data structures.
     
    350339they allow specifying any subset of the parameters and in arbitrary order.
    351340
     341Let us suppose that we have a traffic network stored in a LEMON digraph
     342structure with two arc maps \c length and \c speed, which
     343denote the physical length of each arc and the maximum (or average)
     344speed that can be achieved on the corresponding road-section,
     345respectively. If we are interested in the best traveling times,
     346the following code can be used.
     347
     348\code
     349  dijkstra(g, divMap(length, speed)).distMap(dist).run(s);
     350\endcode
     351
    352352\code
    353353  typedef vector<ListDigraph::Node> Container;
     
    378378    .run(s);
    379379\endcode
     380
     381Let us see a bit more complex example to demonstrate Dfs's capabilities.
     382
     383We will see a program, which solves the problem of <b>topological ordering</b>.
     384We need to know in which order we should put on our clothes. The program will do the following:
     385<ol>
     386<li>We run the dfs algorithm to all nodes.
     387<li>Put every node into a list when processed completely.
     388<li>Write out the list in reverse order.
     389</ol>
     390
     391\dontinclude topological_ordering.cc
     392First of all we will need an own \ref lemon::Dfs::ProcessedMap "ProcessedMap". The ordering
     393will be done through it.
     394\skip MyOrdererMap
     395\until };
     396The class meets the \ref concepts::WriteMap "WriteMap" concept. In it's \c set() method the only thing
     397we need to do is insert the key - that is the node whose processing just finished - into the beginning
     398of the list.<br>
     399Although we implemented this needed helper class ourselves it was not necessary.
     400The \ref lemon::FrontInserterBoolMap "FrontInserterBoolMap" class does exactly
     401what we needed. To be correct it's more general - and it's all in \c LEMON. But
     402we wanted to show you, how easy is to add additional functionality.
     403
     404First we declare the needed data structures: the digraph and a map to store the nodes' label.
     405\skip ListDigraph
     406\until label
     407
     408Now we build a digraph. But keep in mind that it must be DAG because cyclic digraphs has no topological
     409ordering.
     410\skip belt
     411\until trousers
     412We label them...
     413\skip label
     414\until trousers
     415Then add arcs which represent the precedences between those items.
     416\skip trousers, belt
     417\until );
     418
     419See how easy is to access the internal information of this algorithm trough maps.
     420We only need to set our own map as the class's \ref lemon::Dfs::ProcessedMap "ProcessedMap".
     421\skip Dfs
     422\until run
     423
     424And now comes the third part. Write out the list in reverse order. But the list was
     425composed in reverse way (with \c push_front() instead of \c push_back() so we just iterate it.
     426\skip std
     427\until endl
     428
     429The program is to be found in the \ref demo directory: \ref topological_ordering.cc
    380430
    381431LEMON also contains visitor based algorithm classes for
Note: See TracChangeset for help on using the changeset viewer.