dom.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Christian Schulte, 2005
* Vincent Barichard, 2012
*
* 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/float.hh"
#include <gecode/minimodel.hh>
namespace Test { namespace Float {
namespace Dom {
class Val : public Test {
protected:
Gecode::FloatVal c;
public:
Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
: Test("Dom::Val::"+str(n)+"::"+str(c0),
n,-3,3,st,CPLT_ASSIGNMENT,n==1), c(c0) {
testsubsumed = false;
}
virtual MaybeType solution(const Assignment& x) const {
for (int i=x.size(); i--; )
if ((x[i].max() > c.max()) || (x[i].min() < c.min()))
return MT_FALSE;
return MT_TRUE;
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
if (x.size() == 1)
Gecode::dom(home, x[0], c);
else
Gecode::dom(home, x, c);
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r) {
assert(x.size() == 1);
Gecode::dom(home, x[0], c, r);
}
};
class Num : public Test {
protected:
Gecode::FloatNum min;
Gecode::FloatNum max;
public:
Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0,
Gecode::FloatNum st)
: Test("Dom::Num::"+str(n)+"::"+str(min0)+"::"+str(max0),
n,-3,3,st,CPLT_ASSIGNMENT,n==1), min(min0), max(max0) {
testsubsumed = false;
}
virtual MaybeType solution(const Assignment& x) const {
if (max < min)
return MT_FALSE;
for (int i=x.size(); i--; )
if ((x[i].max() > max) || (x[i].min() < min))
return MT_FALSE;
return MT_TRUE;
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
if (x.size() == 1)
Gecode::dom(home, x[0], min, max);
else
Gecode::dom(home, x, min, max);
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r) {
assert(x.size() == 1);
Gecode::dom(home, x[0], min, max, r);
}
};
class Create {
public:
Create(void) {
using namespace Gecode;
FloatNum step = 0.7;
for (int c=-4; c<=4; c++) {
(void) new Val(1,c,step);
(void) new Val(2,c,step);
for (int d=-3; d<=3; d++) {
(void) new Num(1,c,d,step);
(void) new Num(2,c,d,step);
}
}
}
};
Create c;
}
}}
// STATISTICS: test-float
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVarArray
Float variable array.
Definition float.hh:1030
Gecode::Reify
Reification specification.
Definition int.hh:876
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Gecode::VarArray::size
int size(void) const
Return size of array (number of elements).
Definition array.hpp:926
Test::Float::Assignment
Base class for assignments
Definition float.hh:80
Test::Float::Assignment::size
int size(void) const
Return number of variables.
Definition float.hpp:48
Test::Float::Dom::Create
Help class to create and register tests.
Definition dom.cpp:124
Test::Float::Dom::Create::Create
Create(void)
Perform creation and registration.
Definition dom.cpp:127
Test::Float::Dom::Num
Test for domain constraints with float numbers
Definition dom.cpp:85
Test::Float::Dom::Num::max
Gecode::FloatNum max
Float number.
Definition dom.cpp:90
Test::Float::Dom::Num::Num
Num(int n, Gecode::FloatNum min0, Gecode::FloatNum max0, Gecode::FloatNum st)
Create and register test.
Definition dom.cpp:93
Test::Float::Dom::Num::min
Gecode::FloatNum min
Float number.
Definition dom.cpp:88
Test::Float::Dom::Num::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition dom.cpp:109
Test::Float::Dom::Num::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition dom.cpp:116
Test::Float::Dom::Num::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition dom.cpp:100
Test::Float::Dom::Val
Test for domain constraints with a float value
Definition dom.cpp:51
Test::Float::Dom::Val::Val
Val(int n, Gecode::FloatVal c0, Gecode::FloatNum st)
Create and register test.
Definition dom.cpp:57
Test::Float::Dom::Val::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition dom.cpp:63
Test::Float::Dom::Val::c
Gecode::FloatVal c
Float constant.
Definition dom.cpp:54
Test::Float::Dom::Val::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition dom.cpp:77
Test::Float::Dom::Val::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition dom.cpp:70
Test::Float::Test::testsubsumed
bool testsubsumed
Whether to test for subsumption.
Definition float.hh:263
Test::Float::Test::str
static std::string str(Gecode::FloatRelType frt)
Map float relation to string.
Definition float.hpp:194
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::dom
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
Test::Float::Dom
Tests for domain constraints
Definition dom.cpp:43
Test::Float::Dom::c
Create c
Definition dom.cpp:141
Test::Float
Testing domain floats.
Definition float.cpp:43
Test::Float::CPLT_ASSIGNMENT
@ CPLT_ASSIGNMENT
Definition float.hh:62
Test::Float::MaybeType
MaybeType
Type for comparisons and solutions.
Definition float.hh:51
Test::Float::MT_FALSE
@ MT_FALSE
Definition float.hh:52
Test::Float::MT_TRUE
@ MT_TRUE
Definition float.hh:53
Test
General test support.
Definition afc.cpp:39
Test::r
Region r
Definition region.cpp:65
float.hh