Backport relevant parts of bugfixes [ad22262328b3], [61fdd06833a6] and [4add05447ca0] to branch 1.2 (#623)
1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2010
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 #include <lemon/smart_graph.h>
22 #include <lemon/adaptors.h>
23 #include <lemon/concepts/digraph.h>
24 #include <lemon/concepts/maps.h>
25 #include <lemon/lgf_reader.h>
26 #include <lemon/hao_orlin.h>
28 #include "test_tools.h"
30 using namespace lemon;
33 const std::string lgf =
54 void checkHaoOrlinCompile()
57 typedef concepts::Digraph Digraph;
59 typedef Digraph::Node Node;
60 typedef Digraph::Arc Arc;
61 typedef concepts::ReadMap<Arc, Value> CapMap;
62 typedef concepts::WriteMap<Node, bool> CutMap;
69 ::lemon::ignore_unused_variable_warning(v);
71 HaoOrlin<Digraph, CapMap> ho_test(g, cap);
72 const HaoOrlin<Digraph, CapMap>&
73 const_ho_test = ho_test;
77 ho_test.calculateOut();
78 ho_test.calculateIn();
82 v = const_ho_test.minCutValue();
83 v = const_ho_test.minCutMap(cut);
86 template <typename Graph, typename CapMap, typename CutMap>
87 typename CapMap::Value
88 cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
90 typename CapMap::Value sum = 0;
91 for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
92 if (cut[graph.source(a)] && !cut[graph.target(a)])
100 SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
101 SmartDigraph::NodeMap<bool> cut(graph);
103 istringstream input(lgf);
104 digraphReader(graph, input)
105 .arcMap("cap1", cap1)
106 .arcMap("cap2", cap2)
107 .arcMap("cap3", cap3)
111 HaoOrlin<SmartDigraph> ho(graph, cap1);
115 check(ho.minCutValue() == 1, "Wrong cut value");
116 check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
119 HaoOrlin<SmartDigraph> ho(graph, cap2);
123 check(ho.minCutValue() == 1, "Wrong cut value");
124 check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
127 HaoOrlin<SmartDigraph> ho(graph, cap3);
131 check(ho.minCutValue() == 1, "Wrong cut value");
132 check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
135 typedef Undirector<SmartDigraph> UGraph;
136 UGraph ugraph(graph);
139 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
143 check(ho.minCutValue() == 2, "Wrong cut value");
144 check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
147 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
151 check(ho.minCutValue() == 5, "Wrong cut value");
152 check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
155 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
159 check(ho.minCutValue() == 5, "Wrong cut value");
160 check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");