/* -*- 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/smart_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/concepts/digraph.h>
#include <lemon/concept_check.h>
#include <lemon/karp_mmc.h>
#include <lemon/hartmann_orlin_mmc.h>
#include <lemon/howard_mmc.h>
" len1 len2 len3 len4 c1 c2 c3 c4\n"
"3 7 -4 -4 -4 -4 0 0 0 0\n"
"6 4 -1 -1 -1 -1 0 0 0 0\n"
"7 7 4 4 4 -1 0 0 0 1\n";
// Check the interface of an MMC algorithm
template <typename GR, typename Cost>
const Constraints& me = *this;
::template SetPath<ListPath<GR> >
::template SetLargeCost<Cost>
MmcAlg mmc(me.g, me.cost);
const MmcAlg& const_mmc = mmc;
typename MmcAlg::Tolerance tol = const_mmc.tolerance();
v = const_mmc.cycleCost();
i = const_mmc.cycleSize();
d = const_mmc.cycleMean();
typedef concepts::ReadMap<typename GR::Arc, Cost> CM;
// Perform a test with the given parameters
void checkMmcAlg(const SmartDigraph& gr,
const SmartDigraph::ArcMap<int>& lm,
const SmartDigraph::ArcMap<int>& cm,
check(alg.cycleMean() == static_cast<double>(cost) / size,
check(alg.cycleCost() == cost && alg.cycleSize() == size,
SmartDigraph::ArcMap<int> cycle(gr, 0);
for (typename MMC::Path::ArcIt a(alg.cycle()); a != INVALID; ++a) {
for (SmartDigraph::ArcIt a(gr); a != INVALID; ++a) {
check(cm[a] == cycle[a], "Wrong path");
// Class for comparing types
template <typename T1, typename T2>
static const int result = 0;
static const int result = 1;
#ifdef LEMON_HAVE_LONG_LONG
typedef long long long_int;
typedef concepts::Digraph GR;
checkConcept< MmcClassConcept<GR, int>,
KarpMmc<GR, concepts::ReadMap<GR::Arc, int> > >();
checkConcept< MmcClassConcept<GR, float>,
KarpMmc<GR, concepts::ReadMap<GR::Arc, float> > >();
checkConcept< MmcClassConcept<GR, int>,
HartmannOrlinMmc<GR, concepts::ReadMap<GR::Arc, int> > >();
checkConcept< MmcClassConcept<GR, float>,
HartmannOrlinMmc<GR, concepts::ReadMap<GR::Arc, float> > >();
checkConcept< MmcClassConcept<GR, int>,
HowardMmc<GR, concepts::ReadMap<GR::Arc, int> > >();
checkConcept< MmcClassConcept<GR, float>,
HowardMmc<GR, concepts::ReadMap<GR::Arc, float> > >();
check((IsSameType<HowardMmc<GR, concepts::ReadMap<GR::Arc, int> >
::LargeCost, long_int>::result == 1), "Wrong LargeCost type");
check((IsSameType<HowardMmc<GR, concepts::ReadMap<GR::Arc, float> >
::LargeCost, double>::result == 1), "Wrong LargeCost type");
IntArcMap l1(gr), l2(gr), l3(gr), l4(gr);
IntArcMap c1(gr), c2(gr), c3(gr), c4(gr);
std::istringstream input(test_lgf);
digraphReader(gr, input).
checkMmcAlg<KarpMmc<GR, IntArcMap> >(gr, l1, c1, 6, 3);
checkMmcAlg<KarpMmc<GR, IntArcMap> >(gr, l2, c2, 5, 2);
checkMmcAlg<KarpMmc<GR, IntArcMap> >(gr, l3, c3, 0, 1);
checkMmcAlg<KarpMmc<GR, IntArcMap> >(gr, l4, c4, -1, 1);
checkMmcAlg<HartmannOrlinMmc<GR, IntArcMap> >(gr, l1, c1, 6, 3);
checkMmcAlg<HartmannOrlinMmc<GR, IntArcMap> >(gr, l2, c2, 5, 2);
checkMmcAlg<HartmannOrlinMmc<GR, IntArcMap> >(gr, l3, c3, 0, 1);
checkMmcAlg<HartmannOrlinMmc<GR, IntArcMap> >(gr, l4, c4, -1, 1);
checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l1, c1, 6, 3);
checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l2, c2, 5, 2);
checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l3, c3, 0, 1);
checkMmcAlg<HowardMmc<GR, IntArcMap> >(gr, l4, c4, -1, 1);