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(int max_sel, Param rule) {
63 typedef GrossoLocatelliPullanMc<GR> McAlg;
64 typedef McAlg::CliqueNodeIt CliqueIt;
69 GR::NodeMap<bool> map(g);
71 check(mc.run(max_sel, rule) == 0, "Wrong clique size");
72 check(mc.cliqueSize() == 0, "Wrong clique size");
73 check(CliqueIt(mc) == INVALID, "Wrong CliqueNodeIt");
75 GR::Node u = g.addNode();
76 check(mc.run(max_sel, rule) == 1, "Wrong clique size");
77 check(mc.cliqueSize() == 1, "Wrong clique size");
79 check(map[u], "Wrong clique map");
81 check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID,
82 "Wrong CliqueNodeIt");
84 GR::Node v = g.addNode();
85 check(mc.run(max_sel, rule) == 1, "Wrong clique size");
86 check(mc.cliqueSize() == 1, "Wrong clique size");
88 check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map");
90 check(it2 != INVALID && ++it2 == INVALID, "Wrong CliqueNodeIt");
93 check(mc.run(max_sel, rule) == 2, "Wrong clique size");
94 check(mc.cliqueSize() == 2, "Wrong clique size");
96 check(map[u] && map[v], "Wrong clique map");
98 check(it3 != INVALID && ++it3 != INVALID && ++it3 == INVALID,
99 "Wrong CliqueNodeIt");
105 GR::NodeMap<bool> max_clique(g);
106 GR::NodeMap<bool> map(g);
107 std::istringstream input(test_lgf);
108 graphReader(g, input)
109 .nodeMap("max_clique", max_clique)
113 check(mc.run(max_sel, rule) == 4, "Wrong clique size");
114 check(mc.cliqueSize() == 4, "Wrong clique size");
116 for (GR::NodeIt n(g); n != INVALID; ++n) {
117 check(map[n] == max_clique[n], "Wrong clique map");
120 for (CliqueIt n(mc); n != INVALID; ++n) {
122 check(map[n] && max_clique[n], "Wrong CliqueNodeIt");
124 check(cnt == 4, "Wrong CliqueNodeIt");
128 // Check with full graphs
129 template <typename Param>
130 void checkMaxCliqueFullGraph(int max_sel, Param rule) {
131 typedef FullGraph GR;
132 typedef GrossoLocatelliPullanMc<FullGraph> McAlg;
133 typedef McAlg::CliqueNodeIt CliqueIt;
135 for (int size = 0; size <= 40; size = size * 3 + 1) {
137 GR::NodeMap<bool> map(g);
139 check(mc.run(max_sel, rule) == size, "Wrong clique size");
140 check(mc.cliqueSize() == size, "Wrong clique size");
142 for (GR::NodeIt n(g); n != INVALID; ++n) {
143 check(map[n], "Wrong clique map");
146 for (CliqueIt n(mc); n != INVALID; ++n) cnt++;
147 check(cnt == size, "Wrong CliqueNodeIt");
151 // Check with grid graphs
152 template <typename Param>
153 void checkMaxCliqueGridGraph(int max_sel, Param rule) {
155 GridGraph::NodeMap<char> map(g);
156 GrossoLocatelliPullanMc<GridGraph> mc(g);
157 check(mc.run(max_sel, rule) == 2, "Wrong clique size");
158 check(mc.cliqueSize() == 2, "Wrong clique size");
163 checkMaxCliqueGeneral(50, GrossoLocatelliPullanMc<ListGraph>::RANDOM);
164 checkMaxCliqueGeneral(50, GrossoLocatelliPullanMc<ListGraph>::DEGREE_BASED);
165 checkMaxCliqueGeneral(50, GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED);
167 checkMaxCliqueFullGraph(50, GrossoLocatelliPullanMc<FullGraph>::RANDOM);
168 checkMaxCliqueFullGraph(50, GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED);
169 checkMaxCliqueFullGraph(50, GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED);
171 checkMaxCliqueGridGraph(50, GrossoLocatelliPullanMc<GridGraph>::RANDOM);
172 checkMaxCliqueGridGraph(50, GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED);
173 checkMaxCliqueGridGraph(50, GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED);