/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2011
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
#include <lemon/smart_graph.h>
#include <lemon/min_cost_arborescence.h>
#include <lemon/lgf_reader.h>
#include <lemon/concepts/digraph.h>
void checkMinCostArborescenceCompile()
typedef concepts::Digraph Digraph;
typedef concepts::ReadMap<Digraph::Arc, VType> CostMap;
typedef Digraph::Node Node;
typedef Digraph::Arc Arc;
typedef concepts::WriteMap<Digraph::Arc, bool> ArbMap;
typedef concepts::ReadWriteMap<Digraph::Node, Digraph::Arc> PredMap;
typedef MinCostArborescence<Digraph, CostMap>::
SetArborescenceMap<ArbMap>::
SetPredMap<PredMap>::Create MinCostArbType;
MinCostArbType mcarb_test(g, cost);
const MinCostArbType& const_mcarb_test = mcarb_test;
n = mcarb_test.processNextNode();
b = const_mcarb_test.emptyQueue();
i = const_mcarb_test.queueSize();
c = const_mcarb_test.arborescenceCost();
b = const_mcarb_test.arborescence(e);
e = const_mcarb_test.pred(n);
const MinCostArbType::ArborescenceMap &am =
const_mcarb_test.arborescenceMap();
const MinCostArbType::PredMap &pm =
const_mcarb_test.predMap();
b = const_mcarb_test.reached(n);
b = const_mcarb_test.processed(n);
i = const_mcarb_test.dualNum();
c = const_mcarb_test.dualValue();
i = const_mcarb_test.dualSize(i);
c = const_mcarb_test.dualValue(i);
ignore_unused_variable_warning(am);
ignore_unused_variable_warning(pm);
typedef SmartDigraph Digraph;
DIGRAPH_TYPEDEFS(Digraph);
typedef Digraph::ArcMap<double> CostMap;
std::istringstream is(test_lgf);
digraphReader(digraph, is).
node("source", source).run();
MinCostArborescence<Digraph, CostMap> mca(digraph, cost);
vector<pair<double, set<Node> > > dualSolution(mca.dualNum());
for (int i = 0; i < mca.dualNum(); ++i) {
dualSolution[i].first = mca.dualValue(i);
for (MinCostArborescence<Digraph, CostMap>::DualIt it(mca, i);
dualSolution[i].second.insert(it);
for (ArcIt it(digraph); it != INVALID; ++it) {
if (mca.reached(digraph.source(it))) {
for (int i = 0; i < int(dualSolution.size()); ++i) {
if (dualSolution[i].second.find(digraph.target(it))
!= dualSolution[i].second.end() &&
dualSolution[i].second.find(digraph.source(it))
== dualSolution[i].second.end()) {
sum += dualSolution[i].first;
if (mca.arborescence(it)) {
check(sum == cost[it], "Invalid dual solution");
check(sum <= cost[it], "Invalid dual solution");
check(mca.dualValue() == mca.arborescenceCost(), "Invalid dual solution");
check(mca.reached(source), "Invalid arborescence");
for (ArcIt a(digraph); a != INVALID; ++a) {
check(!mca.reached(digraph.source(a)) ||
mca.reached(digraph.target(a)), "Invalid arborescence");
for (NodeIt n(digraph); n != INVALID; ++n) {
if (!mca.reached(n)) continue;
for (InArcIt a(digraph, n); a != INVALID; ++a) {
if (mca.arborescence(a)) {
check(mca.pred(n) == a, "Invalid arborescence");
check((n == source ? cnt == 0 : cnt == 1), "Invalid arborescence");
Digraph::ArcMap<bool> arborescence(digraph);
check(mca.arborescenceCost() ==
minCostArborescence(digraph, cost, source, arborescence),
"Wrong result of the function interface");