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;
69 NagamochiIbaraki<Graph, CapMap> ni_test(g, cap);
70 const NagamochiIbaraki<Graph, CapMap>& const_ni_test = ni_test;
74 b = ni_test.processNextPhase();
77 v = const_ni_test.minCutValue();
78 v = const_ni_test.minCutMap(cut);
81 template <typename Graph, typename CapMap, typename CutMap>
82 typename CapMap::Value
83 cutValue(const Graph& graph, const CapMap& cap, const CutMap& cut)
85 typename CapMap::Value sum = 0;
86 for (typename Graph::EdgeIt e(graph); e != INVALID; ++e) {
87 if (cut[graph.u(e)] != cut[graph.v(e)]) {
96 SmartGraph::EdgeMap<int> cap1(graph), cap2(graph), cap3(graph);
97 SmartGraph::NodeMap<bool> cut(graph);
99 istringstream input(lgf);
100 graphReader(graph, input)
101 .edgeMap("cap1", cap1)
102 .edgeMap("cap2", cap2)
103 .edgeMap("cap3", cap3)
107 NagamochiIbaraki<SmartGraph> ni(graph, cap1);
111 check(ni.minCutValue() == 1, "Wrong cut value");
112 check(ni.minCutValue() == cutValue(graph, cap1, cut), "Wrong cut value");
115 NagamochiIbaraki<SmartGraph> ni(graph, cap2);
119 check(ni.minCutValue() == 3, "Wrong cut value");
120 check(ni.minCutValue() == cutValue(graph, cap2, cut), "Wrong cut value");
123 NagamochiIbaraki<SmartGraph> ni(graph, cap3);
127 check(ni.minCutValue() == 5, "Wrong cut value");
128 check(ni.minCutValue() == cutValue(graph, cap3, cut), "Wrong cut value");
131 NagamochiIbaraki<SmartGraph>::SetUnitCapacity::Create ni(graph);
135 ConstMap<SmartGraph::Edge, int> cap4(1);
136 check(ni.minCutValue() == 1, "Wrong cut value");
137 check(ni.minCutValue() == cutValue(graph, cap4, cut), "Wrong cut value");