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/graph.h>
24 #include <lemon/concepts/maps.h>
25 #include <lemon/lgf_reader.h>
26 #include <lemon/nagamochi_ibaraki.h>
28 #include "test_tools.h"
30 using namespace lemon;
33 const std::string lgf =
52 void checkNagamochiIbarakiCompile()
55 typedef concepts::Graph Graph;
57 typedef Graph::Node Node;
58 typedef Graph::Edge Edge;
59 typedef concepts::ReadMap<Edge, Value> CapMap;
60 typedef concepts::WriteMap<Node, bool> CutMap;
68 ignore_unused_variable_warning(v,b);
70 NagamochiIbaraki<Graph, CapMap> ni_test(g, cap);
71 const NagamochiIbaraki<Graph, CapMap>& const_ni_test = ni_test;
75 b = ni_test.processNextPhase();
78 v = const_ni_test.minCutValue();
79 v = const_ni_test.minCutMap(cut);
82 template <typename Graph, typename CapMap, typename CutMap>
83 typename CapMap::Value
84 cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
86 typename CapMap::Value sum = 0;
87 for (typename Graph::EdgeIt e(graph); e != INVALID; ++e) {
88 if (cut[graph.u(e)] != cut[graph.v(e)]) {
97 SmartGraph::EdgeMap<int> cap1(graph), cap2(graph), cap3(graph);
98 SmartGraph::NodeMap<bool> cut(graph);
100 istringstream input(lgf);
101 graphReader(graph, input)
102 .edgeMap("cap1", cap1)
103 .edgeMap("cap2", cap2)
104 .edgeMap("cap3", cap3)
108 NagamochiIbaraki<SmartGraph> ni(graph, cap1);
112 check(ni.minCutValue() == 1, "Wrong cut value");
113 check(ni.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
116 NagamochiIbaraki<SmartGraph> ni(graph, cap2);
120 check(ni.minCutValue() == 3, "Wrong cut value");
121 check(ni.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
124 NagamochiIbaraki<SmartGraph> ni(graph, cap3);
128 check(ni.minCutValue() == 5, "Wrong cut value");
129 check(ni.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
132 NagamochiIbaraki<SmartGraph>::SetUnitCapacity::Create ni(graph);
136 ConstMap<SmartGraph::Edge, int> cap4(1);
137 check(ni.minCutValue() == 1, "Wrong cut value");
138 check(ni.minCutValue() == cutValue(graph, cap4, cut), "Wrong cut value");