COIN-OR::LEMON - Graph Library

Changes in / [431:9dfaf6efc36f:432:e9a568cc86e3] in lemon-1.2


Ignore:
Files:
2 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • lemon/bfs.h

    r405 r420  
    17421742    /// \pre Either \ref run(Node) "run()" or \ref init()
    17431743    /// must be called before using this function.
    1744     bool reached(Node v) { return (*_reached)[v]; }
     1744    bool reached(Node v) const { return (*_reached)[v]; }
    17451745
    17461746    ///@}
  • lemon/circulation.h

    r402 r420  
    420420    /// \pre Either \ref run() or \ref init() must be called before
    421421    /// using this function.
    422     const Elevator& elevator() {
     422    const Elevator& elevator() const {
    423423      return *_level;
    424424    }
     
    645645    /// \pre Either \ref run() or \ref init() must be called before
    646646    /// using this function.
    647     const FlowMap& flowMap() {
     647    const FlowMap& flowMap() const {
    648648      return *_flow;
    649649    }
     
    670670       \sa checkBarrier()
    671671    */
    672     bool barrier(const Node& node)
     672    bool barrier(const Node& node) const
    673673    {
    674674      return (*_level)[node] >= _el;
     
    693693    /// \sa checkBarrier()
    694694    template<class BarrierMap>
    695     void barrierMap(BarrierMap &bar)
     695    void barrierMap(BarrierMap &bar) const
    696696    {
    697697      for(NodeIt n(_g);n!=INVALID;++n)
     
    713713    ///Check if the found flow is a feasible circulation,
    714714    ///
    715     bool checkFlow() {
     715    bool checkFlow() const {
    716716      for(ArcIt e(_g);e!=INVALID;++e)
    717717        if((*_flow)[e]<(*_lo)[e]||(*_flow)[e]>(*_up)[e]) return false;
     
    731731    ///\sa barrier()
    732732    ///\sa barrierMap()
    733     bool checkBarrier()
     733    bool checkBarrier() const
    734734    {
    735735      Value delta=0;
  • lemon/connectivity.h

    r417 r425  
    1717 */
    1818
    19 #ifndef LEMON_TOPOLOGY_H
    20 #define LEMON_TOPOLOGY_H
     19#ifndef LEMON_CONNECTIVITY_H
     20#define LEMON_CONNECTIVITY_H
    2121
    2222#include <lemon/dfs.h>
     
    155155  }
    156156
    157   namespace _topology_bits {
     157  namespace _connectivity_bits {
    158158
    159159    template <typename Digraph, typename Iterator >
     
    189189
    190190    template <typename Digraph, typename ArcMap>
    191     struct StronglyConnectedCutEdgesVisitor : public DfsVisitor<Digraph> {
     191    struct StronglyConnectedCutArcsVisitor : public DfsVisitor<Digraph> {
    192192    public:
    193193      typedef typename Digraph::Node Node;
    194194      typedef typename Digraph::Arc Arc;
    195195
    196       StronglyConnectedCutEdgesVisitor(const Digraph& digraph,
    197                                        ArcMap& cutMap,
    198                                        int& cutNum)
     196      StronglyConnectedCutArcsVisitor(const Digraph& digraph,
     197                                      ArcMap& cutMap,
     198                                      int& cutNum)
    199199        : _digraph(digraph), _cutMap(cutMap), _cutNum(cutNum),
    200           _compMap(digraph), _num(0) {
    201       }
    202 
    203       void stop(const Node&) {
     200          _compMap(digraph, -1), _num(-1) {
     201      }
     202
     203      void start(const Node&) {
    204204        ++_num;
    205205      }
     
    249249    if (source == INVALID) return true;
    250250
    251     using namespace _topology_bits;
     251    using namespace _connectivity_bits;
    252252
    253253    typedef DfsVisitor<Digraph> Visitor;
     
    266266
    267267    typedef ReverseDigraph<const Digraph> RDigraph;
     268    typedef typename RDigraph::NodeIt RNodeIt;
    268269    RDigraph rdigraph(digraph);
    269270
     
    276277    rdfs.start();
    277278
    278     for (NodeIt it(rdigraph); it != INVALID; ++it) {
     279    for (RNodeIt it(rdigraph); it != INVALID; ++it) {
    279280      if (!rdfs.reached(it)) {
    280281        return false;
     
    295296  /// direction.
    296297  ///
    297   /// \param graph The graph.
     298  /// \param digraph The graph.
    298299  /// \return The number of components
    299300  /// \note By definition, the empty graph has zero
     
    303304    checkConcept<concepts::Digraph, Digraph>();
    304305
    305     using namespace _topology_bits;
     306    using namespace _connectivity_bits;
    306307
    307308    typedef typename Digraph::Node Node;
     
    375376    checkConcept<concepts::WriteMap<Node, int>, NodeMap>();
    376377
    377     using namespace _topology_bits;
     378    using namespace _connectivity_bits;
    378379
    379380    typedef std::vector<Node> Container;
     
    439440    checkConcept<concepts::WriteMap<Arc, bool>, ArcMap>();
    440441
    441     using namespace _topology_bits;
     442    using namespace _connectivity_bits;
    442443
    443444    typedef std::vector<Node> Container;
     
    464465    int cutNum = 0;
    465466
    466     typedef StronglyConnectedCutEdgesVisitor<RDigraph, ArcMap> RVisitor;
     467    typedef StronglyConnectedCutArcsVisitor<RDigraph, ArcMap> RVisitor;
    467468    RVisitor rvisitor(rgraph, cutMap, cutNum);
    468469
     
    479480  }
    480481
    481   namespace _topology_bits {
     482  namespace _connectivity_bits {
    482483
    483484    template <typename Digraph>
     
    731732    typedef typename Graph::NodeIt NodeIt;
    732733
    733     using namespace _topology_bits;
     734    using namespace _connectivity_bits;
    734735
    735736    typedef CountBiNodeConnectedComponentsVisitor<Graph> Visitor;
     
    774775    checkConcept<concepts::WriteMap<Edge, int>, EdgeMap>();
    775776
    776     using namespace _topology_bits;
     777    using namespace _connectivity_bits;
    777778
    778779    typedef BiNodeConnectedComponentsVisitor<Graph, EdgeMap> Visitor;
     
    814815    checkConcept<concepts::WriteMap<Node, bool>, NodeMap>();
    815816
    816     using namespace _topology_bits;
     817    using namespace _connectivity_bits;
    817818
    818819    typedef BiNodeConnectedCutNodesVisitor<Graph, NodeMap> Visitor;
     
    833834  }
    834835
    835   namespace _topology_bits {
     836  namespace _connectivity_bits {
    836837
    837838    template <typename Digraph>
     
    10541055    typedef typename Graph::NodeIt NodeIt;
    10551056
    1056     using namespace _topology_bits;
     1057    using namespace _connectivity_bits;
    10571058
    10581059    typedef CountBiEdgeConnectedComponentsVisitor<Graph> Visitor;
     
    10961097    checkConcept<concepts::WriteMap<Node, int>, NodeMap>();
    10971098
    1098     using namespace _topology_bits;
     1099    using namespace _connectivity_bits;
    10991100
    11001101    typedef BiEdgeConnectedComponentsVisitor<Graph, NodeMap> Visitor;
     
    11371138    checkConcept<concepts::WriteMap<Edge, bool>, EdgeMap>();
    11381139
    1139     using namespace _topology_bits;
     1140    using namespace _connectivity_bits;
    11401141
    11411142    typedef BiEdgeConnectedCutEdgesVisitor<Graph, EdgeMap> Visitor;
     
    11571158
    11581159
    1159   namespace _topology_bits {
     1160  namespace _connectivity_bits {
    11601161
    11611162    template <typename Digraph, typename IntNodeMap>
     
    11941195  template <typename Digraph, typename NodeMap>
    11951196  void topologicalSort(const Digraph& graph, NodeMap& order) {
    1196     using namespace _topology_bits;
     1197    using namespace _connectivity_bits;
    11971198
    11981199    checkConcept<concepts::Digraph, Digraph>();
     
    12251226  /// that the given graph is DAG.
    12261227  ///
    1227   /// \param graph The graph. It must be directed and acyclic.
     1228  /// \param digraph The graph. It must be directed and acyclic.
    12281229  /// \retval order A readable - writable node map. The values will be set
    12291230  /// from 0 to the number of the nodes in the graph minus one. Each values
     
    12351236  /// \see dag
    12361237  template <typename Digraph, typename NodeMap>
    1237   bool checkedTopologicalSort(const Digraph& graph, NodeMap& order) {
    1238     using namespace _topology_bits;
     1238  bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) {
     1239    using namespace _connectivity_bits;
    12391240
    12401241    checkConcept<concepts::Digraph, Digraph>();
     
    12461247    typedef typename Digraph::Arc Arc;
    12471248
    1248     order = constMap<Node, int, -1>();
     1249    for (NodeIt it(digraph); it != INVALID; ++it) {
     1250      order.set(it, -1);
     1251    }
    12491252
    12501253    TopologicalSortVisitor<Digraph, NodeMap>
    1251       visitor(order, countNodes(graph));
     1254      visitor(order, countNodes(digraph));
    12521255
    12531256    DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> >
    1254       dfs(graph, visitor);
     1257      dfs(digraph, visitor);
    12551258
    12561259    dfs.init();
    1257     for (NodeIt it(graph); it != INVALID; ++it) {
     1260    for (NodeIt it(digraph); it != INVALID; ++it) {
    12581261      if (!dfs.reached(it)) {
    12591262        dfs.addSource(it);
    12601263        while (!dfs.emptyQueue()) {
    1261            Arc edge = dfs.nextArc();
    1262            Node target = graph.target(edge);
     1264           Arc arc = dfs.nextArc();
     1265           Node target = digraph.target(arc);
    12631266           if (dfs.reached(target) && order[target] == -1) {
    12641267             return false;
     
    12801283  /// \see acyclic
    12811284  template <typename Digraph>
    1282   bool dag(const Digraph& graph) {
     1285  bool dag(const Digraph& digraph) {
    12831286
    12841287    checkConcept<concepts::Digraph, Digraph>();
     
    12911294
    12921295    typename Dfs<Digraph>::template SetProcessedMap<ProcessedMap>::
    1293       Create dfs(graph);
    1294 
    1295     ProcessedMap processed(graph);
     1296      Create dfs(digraph);
     1297
     1298    ProcessedMap processed(digraph);
    12961299    dfs.processedMap(processed);
    12971300
    12981301    dfs.init();
    1299     for (NodeIt it(graph); it != INVALID; ++it) {
     1302    for (NodeIt it(digraph); it != INVALID; ++it) {
    13001303      if (!dfs.reached(it)) {
    13011304        dfs.addSource(it);
    13021305        while (!dfs.emptyQueue()) {
    13031306          Arc edge = dfs.nextArc();
    1304           Node target = graph.target(edge);
     1307          Node target = digraph.target(edge);
    13051308          if (dfs.reached(target) && !processed[target]) {
    13061309            return false;
     
    13811384  }
    13821385
    1383   namespace _topology_bits {
     1386  namespace _connectivity_bits {
    13841387
    13851388    template <typename Digraph>
     
    14501453  template<typename Graph>
    14511454  inline bool bipartite(const Graph &graph){
    1452     using namespace _topology_bits;
     1455    using namespace _connectivity_bits;
    14531456
    14541457    checkConcept<concepts::Graph, Graph>();
     
    14901493  template<typename Graph, typename NodeMap>
    14911494  inline bool bipartitePartitions(const Graph &graph, NodeMap &partMap){
    1492     using namespace _topology_bits;
     1495    using namespace _connectivity_bits;
    14931496
    14941497    checkConcept<concepts::Graph, Graph>();
     
    15211524  /// Returns true when there are not loop edges in the graph.
    15221525  template <typename Digraph>
    1523   bool loopFree(const Digraph& graph) {
    1524     for (typename Digraph::ArcIt it(graph); it != INVALID; ++it) {
    1525       if (graph.source(it) == graph.target(it)) return false;
     1526  bool loopFree(const Digraph& digraph) {
     1527    for (typename Digraph::ArcIt it(digraph); it != INVALID; ++it) {
     1528      if (digraph.source(it) == digraph.target(it)) return false;
    15261529    }
    15271530    return true;
     
    15321535  /// Returns true when there are not parallel edges in the graph.
    15331536  template <typename Digraph>
    1534   bool parallelFree(const Digraph& graph) {
    1535     typename Digraph::template NodeMap<bool> reached(graph, false);
    1536     for (typename Digraph::NodeIt n(graph); n != INVALID; ++n) {
    1537       for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {
    1538         if (reached[graph.target(e)]) return false;
    1539         reached.set(graph.target(e), true);
    1540       }
    1541       for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {
    1542         reached.set(graph.target(e), false);
     1537  bool parallelFree(const Digraph& digraph) {
     1538    typename Digraph::template NodeMap<bool> reached(digraph, false);
     1539    for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
     1540      for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) {
     1541        if (reached[digraph.target(a)]) return false;
     1542        reached.set(digraph.target(a), true);
     1543      }
     1544      for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) {
     1545        reached.set(digraph.target(a), false);
    15431546      }
    15441547    }
     
    15521555  /// the graph.
    15531556  template <typename Digraph>
    1554   bool simpleDigraph(const Digraph& graph) {
    1555     typename Digraph::template NodeMap<bool> reached(graph, false);
    1556     for (typename Digraph::NodeIt n(graph); n != INVALID; ++n) {
     1557  bool simpleDigraph(const Digraph& digraph) {
     1558    typename Digraph::template NodeMap<bool> reached(digraph, false);
     1559    for (typename Digraph::NodeIt n(digraph); n != INVALID; ++n) {
    15571560      reached.set(n, true);
    1558       for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {
    1559         if (reached[graph.target(e)]) return false;
    1560         reached.set(graph.target(e), true);
    1561       }
    1562       for (typename Digraph::OutArcIt e(graph, n); e != INVALID; ++e) {
    1563         reached.set(graph.target(e), false);
     1561      for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) {
     1562        if (reached[digraph.target(a)]) return false;
     1563        reached.set(digraph.target(a), true);
     1564      }
     1565      for (typename Digraph::OutArcIt a(digraph, n); a != INVALID; ++a) {
     1566        reached.set(digraph.target(a), false);
    15641567      }
    15651568      reached.set(n, false);
     
    15701573} //namespace lemon
    15711574
    1572 #endif //LEMON_TOPOLOGY_H
     1575#endif //LEMON_CONNECTIVITY_H
  • lemon/dfs.h

    r405 r421  
    14111411          } else {
    14121412            _visitor->leave(s);
     1413            _visitor->stop(s);
    14131414          }
    14141415        }
     
    16261627    /// \pre Either \ref run(Node) "run()" or \ref init()
    16271628    /// must be called before using this function.
    1628     bool reached(Node v) { return (*_reached)[v]; }
     1629    bool reached(Node v) const { return (*_reached)[v]; }
    16291630
    16301631    ///@}
  • lemon/max_matching.h

    r330 r425  
    417417    /// \ref init(), \ref greedyInit() or \ref matchingInit()
    418418    /// functions first, then you can start the algorithm with the \ref
    419     /// startParse() or startDense() functions.
     419    /// startSparse() or startDense() functions.
    420420
    421421    ///@{
  • lemon/preflow.h

    r393 r420  
    367367    /// \pre Either \ref run() or \ref init() must be called before
    368368    /// using this function.
    369     const Elevator& elevator() {
     369    const Elevator& elevator() const {
    370370      return *_level;
    371371    }
     
    919919    /// \pre Either \ref run() or \ref init() must be called before
    920920    /// using this function.
    921     const FlowMap& flowMap() {
     921    const FlowMap& flowMap() const {
    922922      return *_flow;
    923923    }
  • lemon/suurballe.h

    r346 r425  
    5252  ///
    5353  /// \note For finding node-disjoint paths this algorithm can be used
    54   /// with \ref SplitDigraphAdaptor.
     54  /// with \ref SplitNodes.
    5555#ifdef DOXYGEN
    5656  template <typename Digraph, typename LengthMap>
  • scripts/chg-len.py

    r376 r422  
    44
    55from mercurial import ui, hg
     6from mercurial import util
     7
     8util.rcpath = lambda : []
    69
    710if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
  • test/CMakeLists.txt

    r410 r424  
    55SET(TESTS
    66  bfs_test
     7  circulation_test
    78  counter_test
    89  dfs_test
     
    1112  dim_test
    1213  error_test
     14  graph_adaptor_test
    1315  graph_copy_test
    1416  graph_test
     
    1921  maps_test
    2022  max_matching_test
     23  path_test
     24  preflow_test
    2125  random_test
    22   path_test
     26  suurballe_test
    2327  time_measure_test
    2428  unionfind_test)
  • test/Makefile.am

    r418 r424  
    11EXTRA_DIST += \
    2         test/CMakeLists.txt \
    3         test/min_cost_flow_test.lgf \
    4         test/preflow_graph.lgf
     2        test/CMakeLists.txt
    53
    64noinst_HEADERS += \
     
    2119        test/graph_test \
    2220        test/graph_utils_test \
     21        test/hao_orlin_test \
    2322        test/heap_test \
    2423        test/kruskal_test \
    25         test/hao_orlin_test \
    2624        test/maps_test \
    2725        test/max_matching_test \
    28         test/random_test \
    2926        test/path_test \
    3027        test/preflow_test \
     28        test/random_test \
    3129        test/suurballe_test \
    3230        test/test_tools_fail \
  • test/preflow_test.cc

    r394 r423  
    1717 */
    1818
    19 #include <fstream>
    20 #include <string>
     19#include <iostream>
    2120
    2221#include "test_tools.h"
     
    2928
    3029using namespace lemon;
     30
     31char test_lgf[] =
     32  "@nodes\n"
     33  "label\n"
     34  "0\n"
     35  "1\n"
     36  "2\n"
     37  "3\n"
     38  "4\n"
     39  "5\n"
     40  "6\n"
     41  "7\n"
     42  "8\n"
     43  "9\n"
     44  "@arcs\n"
     45  "    label capacity\n"
     46  "0 1 0     20\n"
     47  "0 2 1     0\n"
     48  "1 1 2     3\n"
     49  "1 2 3     8\n"
     50  "1 3 4     8\n"
     51  "2 5 5     5\n"
     52  "3 2 6     5\n"
     53  "3 5 7     5\n"
     54  "3 6 8     5\n"
     55  "4 3 9     3\n"
     56  "5 7 10    3\n"
     57  "5 6 11    10\n"
     58  "5 8 12    10\n"
     59  "6 8 13    8\n"
     60  "8 9 14    20\n"
     61  "8 1 15    5\n"
     62  "9 5 16    5\n"
     63  "@attributes\n"
     64  "source 1\n"
     65  "target 8\n";
    3166
    3267void checkPreflowCompile()
     
    124159  typedef Preflow<Digraph, CapMap> PType;
    125160
    126   std::string f_name;
    127   if( getenv("srcdir") )
    128     f_name = std::string(getenv("srcdir"));
    129   else f_name = ".";
    130   f_name += "/test/preflow_graph.lgf";
    131 
    132   std::ifstream file(f_name.c_str());
    133 
    134   check(file, "Input file '" << f_name << "' not found.");
    135 
    136161  Digraph g;
    137162  Node s, t;
    138163  CapMap cap(g);
    139   DigraphReader<Digraph>(g,file).
     164  std::istringstream input(test_lgf);
     165  DigraphReader<Digraph>(g,input).
    140166    arcMap("capacity", cap).
    141167    node("source",s).
  • test/suurballe_test.cc

    r346 r423  
    1818
    1919#include <iostream>
    20 #include <fstream>
    2120
    2221#include <lemon/list_graph.h>
     
    2827
    2928using namespace lemon;
     29
     30char test_lgf[] =
     31  "@nodes\n"
     32  "label supply1 supply2 supply3\n"
     33  "1     0        20      27\n"
     34  "2     0       -4        0\n"
     35  "3     0        0        0\n"
     36  "4     0        0        0\n"
     37  "5     0        9        0\n"
     38  "6     0       -6        0\n"
     39  "7     0        0        0\n"
     40  "8     0        0        0\n"
     41  "9     0        3        0\n"
     42  "10    0       -2        0\n"
     43  "11    0        0        0\n"
     44  "12    0       -20     -27\n"
     45  "@arcs\n"
     46  "      cost capacity lower1 lower2\n"
     47  " 1  2  70  11       0      8\n"
     48  " 1  3 150   3       0      1\n"
     49  " 1  4  80  15       0      2\n"
     50  " 2  8  80  12       0      0\n"
     51  " 3  5 140   5       0      3\n"
     52  " 4  6  60  10       0      1\n"
     53  " 4  7  80   2       0      0\n"
     54  " 4  8 110   3       0      0\n"
     55  " 5  7  60  14       0      0\n"
     56  " 5 11 120  12       0      0\n"
     57  " 6  3   0   3       0      0\n"
     58  " 6  9 140   4       0      0\n"
     59  " 6 10  90   8       0      0\n"
     60  " 7  1  30   5       0      0\n"
     61  " 8 12  60  16       0      4\n"
     62  " 9 12  50   6       0      0\n"
     63  "10 12  70  13       0      5\n"
     64  "10  2 100   7       0      0\n"
     65  "10  7  60  10       0      0\n"
     66  "11 10  20  14       0      6\n"
     67  "12 11  30  10       0      0\n"
     68  "@attributes\n"
     69  "source  1\n"
     70  "target 12\n"
     71  "@end\n";
    3072
    3173// Check the feasibility of the flow
     
    97139  Node source, target;
    98140
    99   std::string fname;
    100   if(getenv("srcdir"))
    101     fname = std::string(getenv("srcdir"));
    102   else fname = ".";
    103   fname += "/test/min_cost_flow_test.lgf";
    104 
    105   std::ifstream input(fname.c_str());
    106   check(input, "Input file '" << fname << "' not found");
     141  std::istringstream input(test_lgf);
    107142  DigraphReader<ListDigraph>(digraph, input).
    108143    arcMap("cost", length).
     
    110145    node("target", target).
    111146    run();
    112   input.close();
    113147 
    114148  // Find 2 paths
Note: See TracChangeset for help on using the changeset viewer.