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;
70 HaoOrlin<Digraph, CapMap> ho_test(g, cap);
71 const HaoOrlin<Digraph, CapMap>&
72 const_ho_test = ho_test;
76 ho_test.calculateOut();
77 ho_test.calculateIn();
81 v = const_ho_test.minCutValue();
82 v = const_ho_test.minCutMap(cut);
85 template <typename Graph, typename CapMap, typename CutMap>
86 typename CapMap::Value
87 cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
89 typename CapMap::Value sum = 0;
90 for (typename Graph::ArcIt a(graph); a != INVALID; ++a) {
91 if (cut[graph.source(a)] && !cut[graph.target(a)])
99 SmartDigraph::ArcMap<int> cap1(graph), cap2(graph), cap3(graph);
100 SmartDigraph::NodeMap<bool> cut(graph);
102 istringstream input(lgf);
103 digraphReader(graph, input)
104 .arcMap("cap1", cap1)
105 .arcMap("cap2", cap2)
106 .arcMap("cap3", cap3)
110 HaoOrlin<SmartDigraph> ho(graph, cap1);
114 check(ho.minCutValue() == 1, "Wrong cut value");
115 check(ho.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
118 HaoOrlin<SmartDigraph> ho(graph, cap2);
122 check(ho.minCutValue() == 1, "Wrong cut value");
123 check(ho.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
126 HaoOrlin<SmartDigraph> ho(graph, cap3);
130 check(ho.minCutValue() == 1, "Wrong cut value");
131 check(ho.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
134 typedef Undirector<SmartDigraph> UGraph;
135 UGraph ugraph(graph);
138 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap1);
142 check(ho.minCutValue() == 2, "Wrong cut value");
143 check(ho.minCutValue() == cutValue(ugraph, cap1, cut), "Wrong cut value");
146 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap2);
150 check(ho.minCutValue() == 5, "Wrong cut value");
151 check(ho.minCutValue() == cutValue(ugraph, cap2, cut), "Wrong cut value");
154 HaoOrlin<UGraph, SmartDigraph::ArcMap<int> > ho(ugraph, cap3);
158 check(ho.minCutValue() == 5, "Wrong cut value");
159 check(ho.minCutValue() == cutValue(ugraph, cap3, cut), "Wrong cut value");