/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-2010
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
#include <lemon/list_graph.h>
#include <lemon/full_graph.h>
#include <lemon/grid_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/grosso_locatelli_pullan_mc.h>
// Check with general graphs
template <typename Param>
void checkMaxCliqueGeneral(Param rule) {
typedef GrossoLocatelliPullanMc<GR> McAlg;
typedef McAlg::CliqueNodeIt CliqueIt;
GR::NodeMap<bool> map(g);
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 0, "Wrong clique size");
check(CliqueIt(mc) == INVALID, "Wrong CliqueNodeIt");
GR::Node u = g.addNode();
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 1, "Wrong clique size");
check(map[u], "Wrong clique map");
check(static_cast<GR::Node>(it1) == u && ++it1 == INVALID,
GR::Node v = g.addNode();
check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 1, "Wrong clique size");
check((map[u] && !map[v]) || (map[v] && !map[u]), "Wrong clique map");
check(it2 != INVALID && ++it2 == INVALID, "Wrong CliqueNodeIt");
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 2, "Wrong clique size");
check(map[u] && map[v], "Wrong clique map");
check(it3 != INVALID && ++it3 != INVALID && ++it3 == INVALID,
GR::NodeMap<bool> max_clique(g);
GR::NodeMap<bool> map(g);
std::istringstream input(test_lgf);
.nodeMap("max_clique", max_clique)
check(mc.run(rule) == McAlg::ITERATION_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 4, "Wrong clique size");
for (GR::NodeIt n(g); n != INVALID; ++n) {
check(map[n] == max_clique[n], "Wrong clique map");
for (CliqueIt n(mc); n != INVALID; ++n) {
check(map[n] && max_clique[n], "Wrong CliqueNodeIt");
check(cnt == 4, "Wrong CliqueNodeIt");
// Check with full graphs
template <typename Param>
void checkMaxCliqueFullGraph(Param rule) {
typedef GrossoLocatelliPullanMc<FullGraph> McAlg;
typedef McAlg::CliqueNodeIt CliqueIt;
for (int size = 0; size <= 40; size = size * 3 + 1) {
GR::NodeMap<bool> map(g);
check(mc.run(rule) == McAlg::SIZE_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == size, "Wrong clique size");
for (GR::NodeIt n(g); n != INVALID; ++n) {
check(map[n], "Wrong clique map");
for (CliqueIt n(mc); n != INVALID; ++n) cnt++;
check(cnt == size, "Wrong CliqueNodeIt");
// Check with grid graphs
template <typename Param>
void checkMaxCliqueGridGraph(Param rule) {
GridGraph::NodeMap<char> map(g);
GrossoLocatelliPullanMc<GridGraph> mc(g);
check(mc.run(rule) == mc.ITERATION_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 2, "Wrong clique size");
check(mc.run(rule) == mc.STEP_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 2, "Wrong clique size");
check(mc.run(rule) == mc.SIZE_LIMIT, "Wrong termination cause");
check(mc.cliqueSize() == 2, "Wrong clique size");
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::RANDOM);
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::DEGREE_BASED);
checkMaxCliqueGeneral(GrossoLocatelliPullanMc<ListGraph>::PENALTY_BASED);
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::RANDOM);
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::DEGREE_BASED);
checkMaxCliqueFullGraph(GrossoLocatelliPullanMc<FullGraph>::PENALTY_BASED);
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::RANDOM);
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::DEGREE_BASED);
checkMaxCliqueGridGraph(GrossoLocatelliPullanMc<GridGraph>::PENALTY_BASED);