test/min_cost_arborescence_test.cc
changeset 672 029a48052c67
parent 522 7f8560cb9d65
child 956 141f9c0db4a3
child 1081 f1398882a928
child 1171 7e368d9b67f7
     1.1 --- a/test/min_cost_arborescence_test.cc	Fri Apr 24 12:12:14 2009 +0100
     1.2 +++ b/test/min_cost_arborescence_test.cc	Sun Apr 26 16:44:53 2009 +0200
     1.3 @@ -24,6 +24,7 @@
     1.4  #include <lemon/smart_graph.h>
     1.5  #include <lemon/min_cost_arborescence.h>
     1.6  #include <lemon/lgf_reader.h>
     1.7 +#include <lemon/concepts/digraph.h>
     1.8  
     1.9  #include "test_tools.h"
    1.10  
    1.11 @@ -70,6 +71,65 @@
    1.12    "@attributes\n"
    1.13    "source 0\n";
    1.14  
    1.15 +
    1.16 +void checkMinCostArborescenceCompile()
    1.17 +{
    1.18 +  typedef double VType;
    1.19 +  typedef concepts::Digraph Digraph;
    1.20 +  typedef concepts::ReadMap<Digraph::Arc, VType> CostMap;
    1.21 +  typedef Digraph::Node Node;
    1.22 +  typedef Digraph::Arc Arc;
    1.23 +  typedef concepts::WriteMap<Digraph::Arc, bool> ArbMap;
    1.24 +  typedef concepts::ReadWriteMap<Digraph::Node, Digraph::Arc> PredMap;
    1.25 +
    1.26 +  typedef MinCostArborescence<Digraph, CostMap>::
    1.27 +            SetArborescenceMap<ArbMap>::
    1.28 +            SetPredMap<PredMap>::Create MinCostArbType;
    1.29 +
    1.30 +  Digraph g;
    1.31 +  Node s, n;
    1.32 +  Arc e;
    1.33 +  VType c;
    1.34 +  bool b;
    1.35 +  int i;
    1.36 +  CostMap cost;
    1.37 +  ArbMap arb;
    1.38 +  PredMap pred;
    1.39 +
    1.40 +  MinCostArbType mcarb_test(g, cost);
    1.41 +  const MinCostArbType& const_mcarb_test = mcarb_test;
    1.42 +
    1.43 +  mcarb_test
    1.44 +    .arborescenceMap(arb)
    1.45 +    .predMap(pred)
    1.46 +    .run(s);
    1.47 +
    1.48 +  mcarb_test.init();
    1.49 +  mcarb_test.addSource(s);
    1.50 +  mcarb_test.start();
    1.51 +  n = mcarb_test.processNextNode();
    1.52 +  b = const_mcarb_test.emptyQueue();
    1.53 +  i = const_mcarb_test.queueSize();
    1.54 +  
    1.55 +  c = const_mcarb_test.arborescenceCost();
    1.56 +  b = const_mcarb_test.arborescence(e);
    1.57 +  e = const_mcarb_test.pred(n);
    1.58 +  const MinCostArbType::ArborescenceMap &am =
    1.59 +    const_mcarb_test.arborescenceMap();
    1.60 +  const MinCostArbType::PredMap &pm =
    1.61 +    const_mcarb_test.predMap();
    1.62 +  b = const_mcarb_test.reached(n);
    1.63 +  b = const_mcarb_test.processed(n);
    1.64 +  
    1.65 +  i = const_mcarb_test.dualNum();
    1.66 +  c = const_mcarb_test.dualValue();
    1.67 +  i = const_mcarb_test.dualSize(i);
    1.68 +  c = const_mcarb_test.dualValue(i);
    1.69 +  
    1.70 +  ignore_unused_variable_warning(am);
    1.71 +  ignore_unused_variable_warning(pm);
    1.72 +}
    1.73 +
    1.74  int main() {
    1.75    typedef SmartDigraph Digraph;
    1.76    DIGRAPH_TYPEDEFS(Digraph);
    1.77 @@ -110,19 +170,19 @@
    1.78          }
    1.79        }
    1.80        if (mca.arborescence(it)) {
    1.81 -        check(sum == cost[it], "INVALID DUAL");
    1.82 +        check(sum == cost[it], "Invalid dual solution");
    1.83        }
    1.84 -      check(sum <= cost[it], "INVALID DUAL");
    1.85 +      check(sum <= cost[it], "Invalid dual solution");
    1.86      }
    1.87    }
    1.88  
    1.89  
    1.90 -  check(mca.dualValue() == mca.arborescenceValue(), "INVALID DUAL");
    1.91 +  check(mca.dualValue() == mca.arborescenceCost(), "Invalid dual solution");
    1.92  
    1.93 -  check(mca.reached(source), "INVALID ARBORESCENCE");
    1.94 +  check(mca.reached(source), "Invalid arborescence");
    1.95    for (ArcIt a(digraph); a != INVALID; ++a) {
    1.96      check(!mca.reached(digraph.source(a)) ||
    1.97 -          mca.reached(digraph.target(a)), "INVALID ARBORESCENCE");
    1.98 +          mca.reached(digraph.target(a)), "Invalid arborescence");
    1.99    }
   1.100  
   1.101    for (NodeIt n(digraph); n != INVALID; ++n) {
   1.102 @@ -130,17 +190,17 @@
   1.103      int cnt = 0;
   1.104      for (InArcIt a(digraph, n); a != INVALID; ++a) {
   1.105        if (mca.arborescence(a)) {
   1.106 -        check(mca.pred(n) == a, "INVALID ARBORESCENCE");
   1.107 +        check(mca.pred(n) == a, "Invalid arborescence");
   1.108          ++cnt;
   1.109        }
   1.110      }
   1.111 -    check((n == source ? cnt == 0 : cnt == 1), "INVALID ARBORESCENCE");
   1.112 +    check((n == source ? cnt == 0 : cnt == 1), "Invalid arborescence");
   1.113    }
   1.114  
   1.115    Digraph::ArcMap<bool> arborescence(digraph);
   1.116 -  check(mca.arborescenceValue() ==
   1.117 +  check(mca.arborescenceCost() ==
   1.118          minCostArborescence(digraph, cost, source, arborescence),
   1.119 -        "WRONG FUNCTION");
   1.120 +        "Wrong result of the function interface");
   1.121  
   1.122    return 0;
   1.123  }