1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2011
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 "test_tools.h"
22 #include <lemon/smart_graph.h>
23 #include <lemon/concepts/graph.h>
24 #include <lemon/concepts/maps.h>
25 #include <lemon/lgf_reader.h>
26 #include <lemon/gomory_hu.h>
30 using namespace lemon;
32 typedef SmartGraph Graph;
55 void checkGomoryHuCompile()
58 typedef concepts::Graph Graph;
60 typedef Graph::Node Node;
61 typedef Graph::Edge Edge;
62 typedef concepts::ReadMap<Edge, Value> CapMap;
63 typedef concepts::ReadWriteMap<Node, bool> CutMap;
71 ignore_unused_variable_warning(v,d);
73 GomoryHu<Graph, CapMap> gh_test(g, cap);
74 const GomoryHu<Graph, CapMap>&
75 const_gh_test = gh_test;
79 n = const_gh_test.predNode(n);
80 v = const_gh_test.predValue(n);
81 d = const_gh_test.rootDist(n);
82 v = const_gh_test.minCutValue(n, n);
83 v = const_gh_test.minCutMap(n, n, cut);
86 GRAPH_TYPEDEFS(Graph);
87 typedef Graph::EdgeMap<int> IntEdgeMap;
88 typedef Graph::NodeMap<bool> BoolNodeMap;
90 int cutValue(const Graph& graph, const BoolNodeMap& cut,
91 const IntEdgeMap& capacity) {
94 for (EdgeIt e(graph); e != INVALID; ++e) {
98 if (cut[s] != cut[t]) {
108 IntEdgeMap capacity(graph);
110 std::istringstream input(test_lgf);
111 GraphReader<Graph>(graph, input).
112 edgeMap("capacity", capacity).run();
114 GomoryHu<Graph> ght(graph, capacity);
117 for (NodeIt u(graph); u != INVALID; ++u) {
118 for (NodeIt v(graph); v != u; ++v) {
119 Preflow<Graph, IntEdgeMap> pf(graph, capacity, u, v);
121 BoolNodeMap cm(graph);
122 ght.minCutMap(u, v, cm);
123 check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
124 check(cm[u] != cm[v], "Wrong cut 2");
125 check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
128 for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
130 check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
133 for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
135 for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
137 check(sum == countNodes(graph), "Problem with MinCutNodeIt");