Add dist target to CMAKE conf. (#434)
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
20 #include <lemon/list_graph.h>
21 #include <lemon/full_graph.h>
22 #include <lemon/grid_graph.h>
23 #include <lemon/lgf_reader.h>
24 #include <lemon/grosso_locatelli_pullan_mc.h>
26 #include "test_tools.h"
28 using namespace lemon;
59 // Check with general graphs
60 template <typename Param>
61 void checkMaxCliqueGeneral(Param rule) {
63 typedef GrossoLocatelliPullanMc<GR> McAlg;
64 typedef McAlg::CliqueNodeIt CliqueIt;
69 GR::NodeMap<bool> map(g);
71 mc.iterationLimit(50);
72 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
73 check(mc.cliqueSize() == 0, "Wrong clique size");
74 check(CliqueIt(mc) == INVALID, "Wrong CliqueNodeIt");
76 GR::Node u = g.addNode();
77 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
78 check(mc.cliqueSize() == 1, "Wrong clique size");
80 check(map[u], "Wrong clique map");
82 check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID,
83 "Wrong CliqueNodeIt");
85 GR::Node v = g.addNode();
86 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause");
87 check(mc.cliqueSize() == 1, "Wrong clique size");
89 check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map");
91 check(it2 != INVALID && ++it2 == INVALID, "Wrong CliqueNodeIt");
94 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
95 check(mc.cliqueSize() == 2, "Wrong clique size");
97 check(map[u] && map[v], "Wrong clique map");
99 check(it3 != INVALID && ++it3 != INVALID && ++it3 == INVALID,
100 "Wrong CliqueNodeIt");
106 GR::NodeMap<bool> max_clique(g);
107 GR::NodeMap<bool> map(g);
108 std::istringstream input(test_lgf);
109 graphReader(g, input)
110 .nodeMap("max_clique", max_clique)
114 mc.iterationLimit(50);
115 check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause");
116 check(mc.cliqueSize() == 4, "Wrong clique size");
118 for (GR::NodeIt n(g); n != INVALID; ++n) {
119 check(map[n] == max_clique[n], "Wrong clique map");
122 for (CliqueIt n(mc); n != INVALID; ++n) {
124 check(map[n] && max_clique[n], "Wrong CliqueNodeIt");
126 check(cnt == 4, "Wrong CliqueNodeIt");
130 // Check with full graphs
131 template <typename Param>
132 void checkMaxCliqueFullGraph(Param rule) {
133 typedef FullGraph GR;
134 typedef GrossoLocatelliPullanMc<FullGraph> McAlg;
135 typedef McAlg::CliqueNodeIt CliqueIt;
137 for (int size = 0; size <= 40; size = size * 3 + 1) {
139 GR::NodeMap<bool> map(g);
141 check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
142 check(mc.cliqueSize() == size, "Wrong clique size");
144 for (GR::NodeIt n(g); n != INVALID; ++n) {
145 check(map[n], "Wrong clique map");
148 for (CliqueIt n(mc); n != INVALID; ++n) cnt++;
149 check(cnt == size, "Wrong CliqueNodeIt");
153 // Check with grid graphs
154 template <typename Param>
155 void checkMaxCliqueGridGraph(Param rule) {
157 GridGraph::NodeMap<char> map(g);
158 GrossoLocatelliPullanMc<GridGraph> mc(g);
160 mc.iterationLimit(100);
161 check(mc.run(rule) == mc.ITERATION_LIMIT, "Wrong termination cause");
162 check(mc.cliqueSize() == 2, "Wrong clique size");
165 check(mc.run(rule) == mc.STEP_LIMIT, "Wrong termination cause");
166 check(mc.cliqueSize() == 2, "Wrong clique size");
169 check(mc.run(rule) == mc.SIZE_LIMIT, "Wrong termination cause");
170 check(mc.cliqueSize() == 2, "Wrong clique size");
175 checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::RANDOM);
176 checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::DEGREE_BASED);
177 checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED);
179 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::RANDOM);
180 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED);
181 checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED);
183 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::RANDOM);
184 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED);
185 checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED);