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 "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;
72 GomoryHu<Graph, CapMap> gh_test(g, cap);
73 const GomoryHu<Graph, CapMap>&
74 const_gh_test = gh_test;
78 n = const_gh_test.predNode(n);
79 v = const_gh_test.predValue(n);
80 d = const_gh_test.rootDist(n);
81 v = const_gh_test.minCutValue(n, n);
82 v = const_gh_test.minCutMap(n, n, cut);
85 GRAPH_TYPEDEFS(Graph);
86 typedef Graph::EdgeMap<int> IntEdgeMap;
87 typedef Graph::NodeMap<bool> BoolNodeMap;
89 int cutValue(const Graph& graph, const BoolNodeMap& cut,
90 const IntEdgeMap& capacity) {
93 for (EdgeIt e(graph); e != INVALID; ++e) {
97 if (cut[s] != cut[t]) {
107 IntEdgeMap capacity(graph);
109 std::istringstream input(test_lgf);
110 GraphReader<Graph>(graph, input).
111 edgeMap("capacity", capacity).run();
113 GomoryHu<Graph> ght(graph, capacity);
116 for (NodeIt u(graph); u != INVALID; ++u) {
117 for (NodeIt v(graph); v != u; ++v) {
118 Preflow<Graph, IntEdgeMap> pf(graph, capacity, u, v);
120 BoolNodeMap cm(graph);
121 ght.minCutMap(u, v, cm);
122 check(pf.flowValue() == ght.minCutValue(u, v), "Wrong cut 1");
123 check(cm[u] != cm[v], "Wrong cut 2");
124 check(pf.flowValue() == cutValue(graph, cm, capacity), "Wrong cut 3");
127 for(GomoryHu<Graph>::MinCutEdgeIt a(ght, u, v);a!=INVALID;++a)
129 check(sum == ght.minCutValue(u, v), "Problem with MinCutEdgeIt");
132 for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,true);n!=INVALID;++n)
134 for(GomoryHu<Graph>::MinCutNodeIt n(ght, u, v,false);n!=INVALID;++n)
136 check(sum == countNodes(graph), "Problem with MinCutNodeIt");