rel.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 Rel {
class FloatVarXY : public Test {
protected:
Gecode::FloatRelType frt;
public:
FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
: Test("Rel::Float::Var::XY::"+str(frt0)+"::"+str(n),
n+1,-3,3,st,CPLT_ASSIGNMENT,n==1),
frt(frt0) {
testsubsumed = false;
}
virtual MaybeType solution(const Assignment& x) const {
if (x.size() == 2) {
return cmp(x[0],frt,x[1]);
} else {
MaybeType r1 = cmp(x[0],frt,x[2]);
MaybeType r2 = cmp(x[1],frt,x[2]);
if ((r1 == MT_TRUE) && (r2 == MT_TRUE)) return MT_TRUE;
else if ((r1 == MT_FALSE) || (r2 == MT_FALSE)) return MT_FALSE;
else return MT_MAYBE;
}
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
using namespace Gecode;
if (x.size() == 2) {
rel(home, x[0], frt, x[1]);
} else {
FloatVarArgs y(2);
y[0]=x[0]; y[1]=x[1];
rel(home, y, frt, x[2]);
}
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r) {
assert(x.size() == 2);
Gecode::rel(home, x[0], frt, x[1], r);
}
};
class FloatVarXX : public Test {
protected:
Gecode::FloatRelType frt;
public:
FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
: Test("Rel::Float::Var::XX::"+str(frt0),
1,-3,3,st,CPLT_ASSIGNMENT,true),
frt(frt0) {
testsubsumed = false;
}
virtual MaybeType solution(const Assignment& x) const {
return cmp(x[0],frt,x[0]);
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
Gecode::rel(home, x[0], frt, x[0]);
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r) {
Gecode::rel(home, x[0], frt, x[0], r);
}
};
class FloatFloat : public Test {
protected:
Gecode::FloatRelType frt;
Gecode::FloatVal c;
public:
FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0,
Gecode::FloatNum st)
: Test("Rel::Float::Float::"+str(frt0)+"::"+str(n)+"::"+str(c0),
n,-3,3,st,CPLT_ASSIGNMENT,n==1),
frt(frt0), c(c0) {
testsubsumed = false;
}
virtual MaybeType solution(const Assignment& x) const {
if (x.size() == 1) {
return cmp(x[0],frt,c);
} else {
return cmp(x[0],frt,c) & cmp(x[1],frt,c);
}
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x) {
using namespace Gecode;
if (x.size() == 1)
rel(home, x[0], frt, c);
else
rel(home, x, frt, c);
}
virtual void post(Gecode::Space& home, Gecode::FloatVarArray& x,
Gecode::Reify r) {
assert(x.size() == 1);
Gecode::rel(home, x[0], frt, c, r);
}
};
class Create {
public:
Create(void) {
using namespace Gecode;
Gecode::FloatNum step = 0.7;
for (FloatRelTypes frts; frts(); ++frts) {
(void) new FloatVarXY(frts.frt(),1,step);
(void) new FloatVarXY(frts.frt(),2,step);
(void) new FloatVarXX(frts.frt(),step);
for (int c=-4; c<=4; c++) {
(void) new FloatFloat(frts.frt(),1,c,step);
(void) new FloatFloat(frts.frt(),2,c,step);
}
}
}
};
Create c;
}
}}
// STATISTICS: test-float
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVarArgs
Passing float variables.
Definition float.hh:979
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::FloatRelTypes
Iterator for float relation types.
Definition float.hh:339
Test::Float::Rel::Create
Help class to create and register tests.
Definition rel.cpp:163
Test::Float::Rel::Create::Create
Create(void)
Perform creation and registration.
Definition rel.cpp:166
Test::Float::Rel::FloatFloat
Test for simple relation involving float variable and float constant
Definition rel.cpp:123
Test::Float::Rel::FloatFloat::frt
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:126
Test::Float::Rel::FloatFloat::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition rel.cpp:155
Test::Float::Rel::FloatFloat::c
Gecode::FloatVal c
Float constant.
Definition rel.cpp:128
Test::Float::Rel::FloatFloat::FloatFloat
FloatFloat(Gecode::FloatRelType frt0, int n, Gecode::FloatNum c0, Gecode::FloatNum st)
Create and register test.
Definition rel.cpp:131
Test::Float::Rel::FloatFloat::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition rel.cpp:139
Test::Float::Rel::FloatFloat::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition rel.cpp:147
Test::Float::Rel::FloatVarXX
Test for simple relation involving shared float variables
Definition rel.cpp:95
Test::Float::Rel::FloatVarXX::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition rel.cpp:116
Test::Float::Rel::FloatVarXX::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition rel.cpp:112
Test::Float::Rel::FloatVarXX::frt
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:98
Test::Float::Rel::FloatVarXX::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition rel.cpp:108
Test::Float::Rel::FloatVarXX::FloatVarXX
FloatVarXX(Gecode::FloatRelType frt0, Gecode::FloatNum st)
Create and register test.
Definition rel.cpp:101
Test::Float::Rel::FloatVarXY
Test for simple relation involving float variables
Definition rel.cpp:51
Test::Float::Rel::FloatVarXY::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x)
Post constraint on x.
Definition rel.cpp:76
Test::Float::Rel::FloatVarXY::frt
Gecode::FloatRelType frt
Float relation type to propagate.
Definition rel.cpp:54
Test::Float::Rel::FloatVarXY::solution
virtual MaybeType solution(const Assignment &x) const
Test whether x is solution
Definition rel.cpp:64
Test::Float::Rel::FloatVarXY::FloatVarXY
FloatVarXY(Gecode::FloatRelType frt0, int n, Gecode::FloatNum st)
Create and register test.
Definition rel.cpp:57
Test::Float::Rel::FloatVarXY::post
virtual void post(Gecode::Space &home, Gecode::FloatVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition rel.cpp:87
Test::Float::Test::cmp
static MaybeType cmp(Gecode::FloatVal x, Gecode::FloatRelType r, Gecode::FloatVal y)
Compare x and y with respect to r.
Definition float.hpp:235
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::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
Gecode::FloatRelType
FloatRelType
Relation types for floats.
Definition float.hh:1068
minimodel.hh
Gecode
Gecode toplevel namespace
Test::Float::Rel
Tests for relation constraints
Definition rel.cpp:43
Test::Float::Rel::c
Create c
Definition rel.cpp:181
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_MAYBE
@ MT_MAYBE
Definition float.hh:54
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