COIN-OR::LEMON - Graph Library

Ignore:
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • lemon/dimacs.h

    r1270 r1375  
    2626#include <lemon/maps.h>
    2727#include <lemon/error.h>
     28
    2829/// \ingroup dimacs_group
    2930/// \file
     
    123124  ///
    124125  /// If the file type was previously evaluated by dimacsType(), then
    125   /// the descriptor struct should be given by the \c dest parameter.
     126  /// the descriptor struct should be given by the \c desc parameter.
    126127  template <typename Digraph, typename LowerMap,
    127128            typename CapacityMap, typename CostMap,
     
    277278  ///
    278279  /// If the file type was previously evaluated by dimacsType(), then
    279   /// the descriptor struct should be given by the \c dest parameter.
     280  /// the descriptor struct should be given by the \c desc parameter.
    280281  template<typename Digraph, typename CapacityMap>
    281282  void readDimacsMax(std::istream& is,
     
    304305  ///
    305306  /// If the file type was previously evaluated by dimacsType(), then
    306   /// the descriptor struct should be given by the \c dest parameter.
     307  /// the descriptor struct should be given by the \c desc parameter.
    307308  template<typename Digraph, typename LengthMap>
    308309  void readDimacsSp(std::istream& is,
     
    335336  ///
    336337  /// If the file type was previously evaluated by dimacsType(), then
    337   /// the descriptor struct should be given by the \c dest parameter.
     338  /// the descriptor struct should be given by the \c desc parameter.
    338339  template<typename Digraph, typename CapacityMap>
    339340  void readDimacsCap(std::istream& is,
     
    344345    typename Digraph::Node u,v;
    345346    if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
    346     if(desc.type!=DimacsDescriptor::MAX || desc.type!=DimacsDescriptor::SP)
     347    if(desc.type!=DimacsDescriptor::MAX && desc.type!=DimacsDescriptor::SP)
    347348      throw FormatError("Problem type mismatch");
    348349    _readDimacs(is, g, capacity, u, v, infty, desc);
     
    375376  ///
    376377  /// If the file type was previously evaluated by dimacsType(), then
    377   /// the descriptor struct should be given by the \c dest parameter.
     378  /// the descriptor struct should be given by the \c desc parameter.
    378379  template<typename Graph>
    379380  void readDimacsMat(std::istream& is, Graph &g,
  • lemon/lgf_reader.h

    r1361 r1377  
    452452  ///
    453453  ///\code
    454   /// DigraphReader<DGR>(digraph, std::cin).
    455   ///   nodeMap("coordinates", coord_map).
    456   ///   arcMap("capacity", cap_map).
    457   ///   node("source", src).
    458   ///   node("target", trg).
    459   ///   attribute("caption", caption).
    460   ///   run();
     454  /// DigraphReader<DGR>(digraph, std::cin)
     455  ///   .nodeMap("coordinates", coord_map)
     456  ///   .arcMap("capacity", cap_map)
     457  ///   .node("source", src)
     458  ///   .node("target", trg)
     459  ///   .attribute("caption", caption)
     460  ///   .run();
    461461  ///\endcode
    462462  ///
     
    12471247  ///ListDigraph::ArcMap<int> cap(digraph);
    12481248  ///ListDigraph::Node src, trg;
    1249   ///digraphReader(digraph, std::cin).
    1250   ///  arcMap("capacity", cap).
    1251   ///  node("source", src).
    1252   ///  node("target", trg).
    1253   ///  run();
     1249  ///digraphReader(digraph, std::cin)
     1250  ///  .arcMap("capacity", cap)
     1251  ///  .node("source", src)
     1252  ///  .node("target", trg)
     1253  ///  .run();
    12541254  ///\endcode
    12551255  ///
     
    21242124  ///ListGraph graph;
    21252125  ///ListGraph::EdgeMap<int> weight(graph);
    2126   ///graphReader(graph, std::cin).
    2127   ///  edgeMap("weight", weight).
    2128   ///  run();
     2126  ///graphReader(graph, std::cin)
     2127  ///  .edgeMap("weight", weight)
     2128  ///  .run();
    21292129  ///\endcode
    21302130  ///
     
    31923192  ///ListBpGraph graph;
    31933193  ///ListBpGraph::EdgeMap<int> weight(graph);
    3194   ///bpGraphReader(graph, std::cin).
    3195   ///  edgeMap("weight", weight).
    3196   ///  run();
     3194  ///bpGraphReader(graph, std::cin)
     3195  ///  .edgeMap("weight", weight)
     3196  ///  .run();
    31973197  ///\endcode
    31983198  ///
  • lemon/lgf_writer.h

    r1270 r1377  
    409409  ///
    410410  ///\code
    411   /// DigraphWriter<DGR>(digraph, std::cout).
    412   ///   nodeMap("coordinates", coord_map).
    413   ///   nodeMap("size", size).
    414   ///   nodeMap("title", title).
    415   ///   arcMap("capacity", cap_map).
    416   ///   node("source", src).
    417   ///   node("target", trg).
    418   ///   attribute("caption", caption).
    419   ///   run();
     411  /// DigraphWriter<DGR>(digraph, std::cout)
     412  ///   .nodeMap("coordinates", coord_map)
     413  ///   .nodeMap("size", size)
     414  ///   .nodeMap("title", title)
     415  ///   .arcMap("capacity", cap_map)
     416  ///   .node("source", src)
     417  ///   .node("target", trg)
     418  ///   .attribute("caption", caption)
     419  ///   .run();
    420420  ///\endcode
    421421  ///
     
    962962  ///ListDigraph::Node src, trg;
    963963  ///  // Setting the capacity map and source and target nodes
    964   ///digraphWriter(digraph, std::cout).
    965   ///  arcMap("capacity", cap).
    966   ///  node("source", src).
    967   ///  node("target", trg).
    968   ///  run();
     964  ///digraphWriter(digraph, std::cout)
     965  ///  .arcMap("capacity", cap)
     966  ///  .node("source", src)
     967  ///  .node("target", trg)
     968  ///  .run();
    969969  ///\endcode
    970970  ///
     
    16001600  ///ListGraph::EdgeMap<int> weight(graph);
    16011601  ///  // Setting the weight map
    1602   ///graphWriter(graph, std::cout).
    1603   ///  edgeMap("weight", weight).
    1604   ///  run();
     1602  ///graphWriter(graph, std::cout)
     1603  ///  .edgeMap("weight", weight)
     1604  ///  .run();
    16051605  ///\endcode
    16061606  ///
     
    24202420  ///ListBpGraph::EdgeMap<int> weight(graph);
    24212421  ///  // Setting the weight map
    2422   ///bpGraphWriter(graph, std::cout).
    2423   ///  edgeMap("weight", weight).
    2424   ///  run();
     2422  ///bpGraphWriter(graph, std::cout)
     2423  ///  .edgeMap("weight", weight)
     2424  ///  .run();
    24252425  ///\endcode
    24262426  ///
  • lemon/preflow.h

    r1270 r1385  
    477477    /// flow to the given \c flowMap. The \c flowMap should contain a
    478478    /// flow or at least a preflow, i.e. at each node excluding the
    479     /// source node the incoming flow should greater or equal to the
     479    /// source node the incoming flow should be greater or equal to the
    480480    /// outgoing flow.
    481481    /// \return \c false if the given \c flowMap is not a preflow.
     
    496496          excess -= (*_flow)[e];
    497497        }
    498         if (excess < 0 && n != _source) return false;
     498        if (_tolerance.negative(excess) && n != _source) return false;
    499499        (*_excess)[n] = excess;
    500500      }
     
    640640          (*_excess)[n] = excess;
    641641
    642           if (excess != 0) {
     642          if (_tolerance.nonZero(excess)) {
    643643            if (new_level + 1 < _level->maxLevel()) {
    644644              _level->liftHighestActive(new_level + 1);
     
    721721          (*_excess)[n] = excess;
    722722
    723           if (excess != 0) {
     723          if (_tolerance.nonZero(excess)) {
    724724            if (new_level + 1 < _level->maxLevel()) {
    725725              _level->liftActiveOn(level, new_level + 1);
     
    792792        if (!reached[n]) {
    793793          _level->dirtyTopButOne(n);
    794         } else if ((*_excess)[n] > 0 && _target != n) {
     794        } else if (_tolerance.positive((*_excess)[n]) && _target != n) {
    795795          _level->activate(n);
    796796        }
     
    853853        (*_excess)[n] = excess;
    854854
    855         if (excess != 0) {
     855        if (_tolerance.nonZero(excess)) {
    856856          if (new_level + 1 < _level->maxLevel()) {
    857857            _level->liftHighestActive(new_level + 1);
  • lemon/static_graph.h

    r1328 r1371  
    3030
    3131  class StaticDigraphBase {
     32
    3233  public:
    3334
     
    297298  /// \sa concepts::Digraph
    298299  class StaticDigraph : public ExtendedStaticDigraphBase {
     300
     301  private:
     302    /// Graphs are \e not copy constructible. Use DigraphCopy instead.
     303    StaticDigraph(const StaticDigraph &) : ExtendedStaticDigraphBase() {};
     304    /// \brief Assignment of a graph to another one is \e not allowed.
     305    /// Use DigraphCopy instead.
     306    void operator=(const StaticDigraph&) {}
     307
    299308  public:
    300309
  • lemon/vf2.h

    r1366 r1370  
    2727#include <lemon/dfs.h>
    2828#include <lemon/bfs.h>
    29 #include <test/test_tools.h>
    3029
    3130#include <vector>
  • test/bellman_ford_test.cc

    r1337 r1378  
    101101    pp = const_bf_test.negativeCycle();
    102102
     103#ifdef LEMON_CXX11
    103104    for (BF::ActiveIt it(const_bf_test); it != INVALID; ++it) {}
    104105    for (auto n: const_bf_test.activeNodes()) { ::lemon::ignore_unused_variable_warning(n); }
     
    106107      ::lemon::ignore_unused_variable_warning(n);
    107108    }
     109#endif
    108110  }
    109111  {
  • test/max_flow_test.cc

    r1270 r1385  
    2727#include <lemon/lgf_reader.h>
    2828#include <lemon/elevator.h>
     29#include <lemon/tolerance.h>
    2930
    3031using namespace lemon;
     
    6667  "target 8\n";
    6768
     69char test_lgf_float[] =
     70  "@nodes\n"
     71  "label\n"
     72  "0\n"
     73  "1\n"
     74  "2\n"
     75  "3\n"
     76  "4\n"
     77  "5\n"
     78  "6\n"
     79  "7\n"
     80  "8\n"
     81  "9\n"
     82  "@arcs\n"
     83  "      capacity\n"
     84  "0 1 0.1\n"
     85  "0 2 0.1\n"
     86  "0 3 0.1\n"
     87  "1 4 0.1\n"
     88  "2 4 0.1\n"
     89  "3 4 0.1\n"
     90  "4 5 0.3\n"
     91  "5 6 0.1\n"
     92  "5 7 0.1\n"
     93  "5 8 0.1\n"
     94  "6 9 0.1\n"
     95  "7 9 0.1\n"
     96  "8 9 0.1\n"
     97  "@attributes\n"
     98  "source 0\n"
     99  "target 9\n";
    68100
    69101// Checks the general interface of a max flow algorithm
     
    166198  typedef concepts::Digraph Digraph;
    167199  typedef concepts::ReadMap<Digraph::Arc, Value> CapMap;
    168   typedef Elevator<Digraph, Digraph::Node> Elev;
    169   typedef LinkedElevator<Digraph, Digraph::Node> LinkedElev;
    170200
    171201  Digraph g;
     
    185215
    186216template <typename T>
    187 T cutValue (const SmartDigraph& g,
    188               const SmartDigraph::NodeMap<bool>& cut,
    189               const SmartDigraph::ArcMap<T>& cap) {
    190 
    191   T c=0;
    192   for(SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {
    193     if (cut[g.source(e)] && !cut[g.target(e)]) c+=cap[e];
     217T cutValue(const SmartDigraph& g,
     218           const SmartDigraph::NodeMap<bool>& cut,
     219           const SmartDigraph::ArcMap<T>& cap) {
     220
     221  T c = 0;
     222  for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
     223    if (cut[g.source(e)] && !cut[g.target(e)]) c += cap[e];
    194224  }
    195225  return c;
     
    200230               const SmartDigraph::ArcMap<T>& flow,
    201231               const SmartDigraph::ArcMap<T>& cap,
    202                SmartDigraph::Node s, SmartDigraph::Node t) {
     232               SmartDigraph::Node s, SmartDigraph::Node t,
     233               const Tolerance<T>& tol) {
    203234
    204235  for (SmartDigraph::ArcIt e(g); e != INVALID; ++e) {
    205     if (flow[e] < 0 || flow[e] > cap[e]) return false;
     236    if (tol.negative(flow[e]) || tol.less(cap[e], flow[e])) return false;
    206237  }
    207238
     
    215246      sum -= flow[e];
    216247    }
    217     if (sum != 0) return false;
     248    if (tol.nonZero(sum)) return false;
    218249  }
    219250  return true;
    220251}
    221252
    222 void initFlowTest()
     253void checkInitPreflow()
    223254{
    224255  DIGRAPH_TYPEDEFS(SmartDigraph);
    225256
    226257  SmartDigraph g;
    227   SmartDigraph::ArcMap<int> cap(g),iflow(g);
    228   Node s=g.addNode(); Node t=g.addNode();
    229   Node n1=g.addNode(); Node n2=g.addNode();
     258  SmartDigraph::ArcMap<int> cap(g), iflow(g);
     259  Node s = g.addNode(); Node t = g.addNode();
     260  Node n1 = g.addNode(); Node n2 = g.addNode();
    230261  Arc a;
    231   a=g.addArc(s,n1); cap[a]=20; iflow[a]=20;
    232   a=g.addArc(n1,n2); cap[a]=10; iflow[a]=0;
    233   a=g.addArc(n2,t); cap[a]=20; iflow[a]=0;
    234 
    235   Preflow<SmartDigraph> pre(g,cap,s,t);
     262  a = g.addArc(s, n1); cap[a] = 20; iflow[a] = 20;
     263  a = g.addArc(n1, n2); cap[a] = 10; iflow[a] = 0;
     264  a = g.addArc(n2, t); cap[a] = 20; iflow[a] = 0;
     265
     266  Preflow<SmartDigraph> pre(g, cap, s, t);
    236267  pre.init(iflow);
    237268  pre.startFirstPhase();
    238   check(pre.flowValue() == 10, "The incorrect max flow value.");
     269
     270  check(pre.flowValue() == 10, "Incorrect max flow value.");
    239271  check(pre.minCut(s), "Wrong min cut (Node s).");
    240272  check(pre.minCut(n1), "Wrong min cut (Node n1).");
     
    244276
    245277template <typename MF, typename SF>
    246 void checkMaxFlowAlg() {
     278void checkMaxFlowAlg(const char *input_lgf,  typename MF::Value expected) {
    247279  typedef SmartDigraph Digraph;
    248280  DIGRAPH_TYPEDEFS(Digraph);
     
    253285  typedef BoolNodeMap CutMap;
    254286
     287  Tolerance<Value> tol;
     288
    255289  Digraph g;
    256290  Node s, t;
    257291  CapMap cap(g);
    258   std::istringstream input(test_lgf);
    259   DigraphReader<Digraph>(g,input)
     292  std::istringstream input(input_lgf);
     293  DigraphReader<Digraph>(g, input)
    260294      .arcMap("capacity", cap)
    261       .node("source",s)
    262       .node("target",t)
     295      .node("source", s)
     296      .node("target", t)
    263297      .run();
    264298
     
    266300  max_flow.run();
    267301
    268   check(checkFlow(g, max_flow.flowMap(), cap, s, t),
     302  check(!tol.different(expected, max_flow.flowValue()),
     303        "Incorrect max flow value.");
     304  check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol),
    269305        "The flow is not feasible.");
    270306
     
    273309  Value min_cut_value = cutValue(g, min_cut, cap);
    274310
    275   check(max_flow.flowValue() == min_cut_value,
    276         "The max flow value is not equal to the min cut value.");
     311  check(!tol.different(expected, min_cut_value),
     312        "Incorrect min cut value.");
    277313
    278314  FlowMap flow(g);
    279   for (ArcIt e(g); e != INVALID; ++e) flow[e] = max_flow.flowMap()[e];
    280 
    281   Value flow_value = max_flow.flowValue();
    282 
    283   for (ArcIt e(g); e != INVALID; ++e) cap[e] = 2 * cap[e];
     315  for (ArcIt e(g); e != INVALID; ++e) flow[e] = 13 * max_flow.flowMap()[e];
     316  for (ArcIt e(g); e != INVALID; ++e) cap[e] = 17 * cap[e];
    284317  max_flow.init(flow);
    285318
     
    290323  min_cut_value = cutValue(g, min_cut1, cap);
    291324
    292   check(max_flow.flowValue() == min_cut_value &&
    293         min_cut_value == 2 * flow_value,
    294         "The max flow value or the min cut value is wrong.");
     325  check(!tol.different(17 * expected, max_flow.flowValue()),
     326        "Incorrect max flow value.");
     327  check(!tol.different(17 * expected, min_cut_value),
     328        "Incorrect min cut value.");
    295329
    296330  SF::startSecondPhase(max_flow);       // start second phase of the algorithm
    297331
    298   check(checkFlow(g, max_flow.flowMap(), cap, s, t),
     332  check(checkFlow(g, max_flow.flowMap(), cap, s, t, tol),
    299333        "The flow is not feasible.");
    300334
     
    303337  min_cut_value = cutValue(g, min_cut2, cap);
    304338
    305   check(max_flow.flowValue() == min_cut_value &&
    306         min_cut_value == 2 * flow_value,
    307         "The max flow value or the min cut value was not doubled");
    308 
     339  check(!tol.different(17 * expected, max_flow.flowValue()),
     340        "Incorrect max flow value.");
     341  check(!tol.different(17 * expected, min_cut_value),
     342        "Incorrect min cut value.");
    309343
    310344  max_flow.flowMap(flow);
     
    325359  CutMap min_cut3(g);
    326360  max_flow.minCutMap(min_cut3);
    327   min_cut_value=cutValue(g, min_cut3, cap);
    328 
    329   check(max_flow.flowValue() == min_cut_value,
     361  min_cut_value = cutValue(g, min_cut3, cap);
     362
     363  check(!tol.different(max_flow.flowValue(), min_cut_value),
    330364        "The max flow value or the min cut value is wrong.");
    331365}
     
    380414  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<int> > PType1;
    381415  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<float> > PType2;
    382   checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >();
    383   checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >();
    384   initFlowTest();
     416  typedef Preflow<SmartDigraph, SmartDigraph::ArcMap<double> > PType3;
     417
     418  checkMaxFlowAlg<PType1, PreflowStartFunctions<PType1> >(test_lgf, 13);
     419  checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(test_lgf, 13);
     420  checkMaxFlowAlg<PType3, PreflowStartFunctions<PType3> >(test_lgf, 13);
     421
     422  checkMaxFlowAlg<PType2, PreflowStartFunctions<PType2> >(test_lgf_float, 0.3);
     423  checkMaxFlowAlg<PType3, PreflowStartFunctions<PType3> >(test_lgf_float, 0.3);
     424
     425  checkInitPreflow();
    385426
    386427  // Check EdmondsKarp
    387428  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<int> > EKType1;
    388429  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<float> > EKType2;
    389   checkMaxFlowAlg<EKType1, GeneralStartFunctions<EKType1> >();
    390   checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >();
    391 
    392   initFlowTest();
     430  typedef EdmondsKarp<SmartDigraph, SmartDigraph::ArcMap<double> > EKType3;
     431
     432  checkMaxFlowAlg<EKType1, GeneralStartFunctions<EKType1> >(test_lgf, 13);
     433  checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(test_lgf, 13);
     434  checkMaxFlowAlg<EKType3, GeneralStartFunctions<EKType3> >(test_lgf, 13);
     435
     436  checkMaxFlowAlg<EKType2, GeneralStartFunctions<EKType2> >(test_lgf_float, 0.3);
     437  checkMaxFlowAlg<EKType3, GeneralStartFunctions<EKType3> >(test_lgf_float, 0.3);
    393438
    394439  return 0;
  • tools/dimacs-solver.cc

    r1271 r1386  
    223223        throw IoError("Cannot open the file for writing", ap.files()[1]);
    224224      }
     225      // fall through
    225226    case 1:
    226227      input.open(ap.files()[0].c_str());
     
    228229        throw IoError("File cannot be found", ap.files()[0]);
    229230      }
     231      // fall through
    230232    case 0:
    231233      break;
     
    252254        case DimacsDescriptor::SP:
    253255          std::cout << "sp";
     256          break;
    254257        case DimacsDescriptor::MAT:
    255258          std::cout << "mat";
Note: See TracChangeset for help on using the changeset viewer.