convex.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Guido Tack, 2005
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "test/set.hh"
using namespace Gecode;
namespace Test { namespace Set {
namespace Convex {
static IntSet ds_33(-4,4);
class Convex : public SetTest {
public:
Convex(const char* t)
: SetTest(t,1,ds_33,false) {}
virtual bool solution(const SetAssignment& x) const {
CountableSetRanges xr0(x.lub, x[0]);
if (!xr0())
return true;
++xr0;
if (!xr0())
return true;
return false;
}
virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
Gecode::convex(home, x[0]);
}
};
Convex _convex("Convex::Convex");
class ConvexHull : public SetTest {
public:
ConvexHull(const char* t)
: SetTest(t,2,ds_33,false) {}
virtual bool solution(const SetAssignment& x) const {
CountableSetRanges xr0(x.lub, x[0]);
CountableSetRanges xr1(x.lub, x[1]);
if (!xr0())
return !xr1();
int x0min = xr0.min();
int x0max = xr0.max();
++xr0;
if (!xr0()) {
if (!xr1()) return false;
if (x0min != xr1.min()) return false;
int x1max = Gecode::Set::Limits::min;
while (xr1()) { x1max = xr1.max(); ++xr1;}
if (x0max != x1max) return false;
return true;
}
return false;
}
virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
Gecode::convex(home, x[1], x[0]);
}
};
ConvexHull _convexhull("Convex::ConvexHull");
class ConvexHullS : public SetTest {
public:
ConvexHullS(const char* t)
: SetTest(t,1,ds_33,false) {}
virtual bool solution(const SetAssignment& x) const {
CountableSetRanges xr0(x.lub, x[0]);
if (!xr0())
return true;
++xr0;
if (!xr0())
return true;
return false;
}
virtual void post(Space& home, SetVarArray& x, IntVarArray&) {
Gecode::convex(home, x[0], x[0]);
}
};
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS");
}}}
// STATISTICS: test-set
Gecode::IntSet
Integer sets.
Definition int.hh:174
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
Gecode::Iter::Ranges::MinMax::min
int min(void) const
Return smallest value of range.
Definition ranges-minmax.hpp:99
Gecode::Iter::Ranges::MinMax::max
int max(void) const
Return largest value of range.
Definition ranges-minmax.hpp:103
Gecode::SetVarArray
Set variable array
Definition set.hh:570
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Set::Convex::ConvexHullS
Sharing test for convex hull propagator.
Definition convex.cpp:109
Test::Set::Convex::ConvexHullS::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:115
Test::Set::Convex::ConvexHullS::ConvexHullS
ConvexHullS(const char *t)
Create and register test.
Definition convex.cpp:112
Test::Set::Convex::ConvexHullS::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:125
Test::Set::Convex::ConvexHull
Test for convex hull propagator
Definition convex.cpp:75
Test::Set::Convex::ConvexHull::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:102
Test::Set::Convex::ConvexHull::ConvexHull
ConvexHull(const char *t)
Create and register test.
Definition convex.cpp:78
Test::Set::Convex::ConvexHull::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:81
Test::Set::Convex::Convex
Test for convexity propagator
Definition convex.cpp:52
Test::Set::Convex::Convex::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition convex.cpp:68
Test::Set::Convex::Convex::Convex
Convex(const char *t)
Create and register test.
Definition convex.cpp:55
Test::Set::Convex::Convex::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition convex.cpp:58
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition set.hh:99
Test::Set::SetAssignment
Generate all set assignments.
Definition set.hh:142
Test::Set::SetAssignment::lub
Gecode::IntSet lub
The common superset for all domains.
Definition set.hh:154
Test::Set::SetTest::SetTest
SetTest(const std::string &s, int a, const Gecode::IntSet &d, bool r=false, int w=0)
Constructor.
Definition set.hh:304
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
Gecode
Gecode toplevel namespace
Gecode::convex
void convex(Home home, SetVar x)
Post propagator that propagates that x is convex.
Definition convex.cpp:41
Test::Set::Convex::_convexhulls
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS")
Test::Set::Convex::_convex
Convex _convex("Convex::Convex")
Test::Set::Convex::_convexhull
ConvexHull _convexhull("Convex::ConvexHull")
Test::Set
Testing finite sets.
Definition set.cpp:42
Test
General test support.
Definition afc.cpp:39
set.hh