COIN-OR::LEMON - Graph Library

Changeset 875:fda944f15ca7 in lemon-0.x


Ignore:
Timestamp:
09/16/04 21:51:28 (20 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1178
Message:

Changed to conform to the new iterator style.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/graphs.dox

    r873 r875  
    6161\todo Some cross-refs are wrong.
    6262
    63 \bug This file must be updated accordig to the new style iterators.
    64 
    6563The graph structures itself can not store data attached
    6664to the edges and nodes. However they all provide
     
    9896    g.addNode();
    9997 
    100   for (NodeIt i(g); g.valid(i); g.next(i))
    101     for (NodeIt j(g); g.valid(j); g.next(j))
     98  for (NodeIt i(g); i!=INVALID; ++i)
     99    for (NodeIt j(g); j!=INVALID; ++j)
    102100      if (i != j) g.addEdge(i, j);
    103101\endcode
     
    108106\code
    109107  std::cout << "Nodes:";
    110   for (NodeIt i(g); g.valid(i); g.next(i))
     108  for (NodeIt i(g); i!=INVALID; ++i)
    111109    std::cout << " " << g.id(i);
    112110  std::cout << std::endl;
     
    114112
    115113Here we iterate through all nodes of the graph. We use a constructor of the
    116 node iterator to initialize it to the first node. The next member function is
    117 used to step to the next node, and valid is used to check if we have passed the
    118 last one.
     114node iterator to initialize it to the first node. The operator++ is used to
     115step to the next node. Using operator++ on the iterator pointing to the last
     116node invalidates the iterator i.e. sets its value to
     117\ref hugo::INVALID "INVALID". This is what we exploit in the stop condition.
    119118
    120 \code
    121   std::cout << "Nodes:";
    122   NodeIt n;
    123   for (g.first(n); n != INVALID; g.next(n))
    124     std::cout << " " << g.id(n);
    125   std::cout << std::endl;
    126 \endcode
    127 
    128 Here you can see an alternative way to iterate through all nodes. Here we use a
    129 member function of the graph to initialize the node iterator to the first node
    130 of the graph. Using next on the iterator pointing to the last node invalidates
    131 the iterator i.e. sets its value to INVALID. Checking for this value is
    132 equivalent to using the valid member function.
    133 
    134 Both of the previous code fragments print out the same:
     119The previous code fragment prints out the following:
    135120
    136121\code
     
    140125\code
    141126  std::cout << "Edges:";
    142   for (EdgeIt i(g); g.valid(i); g.next(i))
     127  for (EdgeIt i(g); i!=INVALID; ++i)
    143128    std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")";
    144129  std::cout << std::endl;
     
    156141
    157142  std::cout << "Out-edges of node " << g.id(first_node) << ":";
    158   for (OutEdgeIt i(g, first_node); g.valid(i); g.next(i))
     143  for (OutEdgeIt i(g, first_node); i!=INVALID; ++i)
    159144    std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")";
    160145  std::cout << std::endl;
    161146
    162147  std::cout << "In-edges of node " << g.id(first_node) << ":";
    163   for (InEdgeIt i(g, first_node); g.valid(i); g.next(i))
     148  for (InEdgeIt i(g, first_node); i!=INVALID; ++i)
    164149    std::cout << " (" << g.id(g.tail(i)) << "," << g.id(g.head(i)) << ")";
    165150  std::cout << std::endl;
     
    177162  Graph::EdgeMap<int> m(g);
    178163
    179   for (EdgeIt e(g); g.valid(e); g.next(e))
     164  for (EdgeIt e(g); e!=INVALID; ++e)
    180165    m.set(e, 10 - g.id(e));
    181166 
    182167  std::cout << "Id Edge  Value" << std::endl;
    183   for (EdgeIt e(g); g.valid(e); g.next(e))
     168  for (EdgeIt e(g); e!=INVALID; ++e)
    184169    std::cout << g.id(e) << "  (" << g.id(g.tail(e)) << "," << g.id(g.head(e))
    185170      << ") " << m[e] << std::endl;
Note: See TracChangeset for help on using the changeset viewer.