mm-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>
*
* Copyright:
* Christian Schulte, 2008
*
* 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/int.hh"
#include <gecode/minimodel.hh>
namespace Test { namespace Int {
namespace MiniModel {
class IntLex : public Test {
protected:
Gecode::IntRelType irt;
public:
IntLex(Gecode::IntRelType irt0)
: Test("MiniModel::Lex::Int::"+str(irt0),6,-2,2), irt(irt0) {}
virtual bool solution(const Assignment& x) const {
int n=x.size() >> 1;
for (int i=0; i<n; i++)
if (x[i] != x[n+i])
return cmp(x[i],irt,x[n+i]);
return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
(irt == Gecode::IRT_EQ));
GECODE_NEVER;
return false;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
int n=x.size() >> 1;
IntVarArgs y(n); IntVarArgs z(n);
for (int i=0; i<n; i++) {
y[i]=x[i]; z[i]=x[n+i];
}
lex(home, y, irt, z);
}
};
class BoolLex : public Test {
protected:
Gecode::IntRelType irt;
public:
BoolLex(Gecode::IntRelType irt0)
: Test("MiniModel::Lex::Bool::"+str(irt0),10,0,1), irt(irt0) {}
virtual bool solution(const Assignment& x) const {
int n=x.size() >> 1;
for (int i=0; i<n; i++)
if (x[i] != x[n+i])
return cmp(x[i],irt,x[n+i]);
return ((irt == Gecode::IRT_LQ) || (irt == Gecode::IRT_GQ) ||
(irt == Gecode::IRT_EQ));
GECODE_NEVER;
return false;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
int n=x.size() >> 1;
BoolVarArgs y(n); BoolVarArgs z(n);
for (int i=0; i<n; i++) {
y[i]=channel(home,x[i]); z[i]=channel(home,x[n+i]);
}
lex(home, y, irt, z);
}
};
class Create {
public:
Create(void) {
using namespace Gecode;
for (IntRelTypes irts; irts(); ++irts) {
(void) new IntLex(irts.irt());
(void) new BoolLex(irts.irt());
}
}
};
Create c;
}
}}
// STATISTICS: test-minimodel
Gecode::BoolVarArgs
Passing Boolean variables.
Definition int.hh:712
Gecode::IntVarArgs
Passing integer variables.
Definition int.hh:656
Gecode::IntVarArray
Integer variable array.
Definition int.hh:763
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::Int::Assignment
Base class for assignments
Definition int.hh:59
Test::Int::Assignment::size
int size(void) const
Return number of variables.
Definition int.hpp:46
Test::Int::IntRelTypes
Iterator for integer relation types.
Definition int.hh:368
Test::Int::MiniModel::BoolLex
Test for relation between arrays of Boolean variables
Definition mm-rel.cpp:81
Test::Int::MiniModel::BoolLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition mm-rel.cpp:101
Test::Int::MiniModel::BoolLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition mm-rel.cpp:84
Test::Int::MiniModel::BoolLex::BoolLex
BoolLex(Gecode::IntRelType irt0)
Create and register test.
Definition mm-rel.cpp:87
Test::Int::MiniModel::BoolLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition mm-rel.cpp:90
Test::Int::MiniModel::Create
Help class to create and register tests.
Definition mm-rel.cpp:113
Test::Int::MiniModel::Create::Create
Create(void)
Perform creation and registration.
Definition mm-rel.cpp:116
Test::Int::MiniModel::IntLex
Test for relation between arrays of integer variables
Definition mm-rel.cpp:49
Test::Int::MiniModel::IntLex::IntLex
IntLex(Gecode::IntRelType irt0)
Create and register test.
Definition mm-rel.cpp:55
Test::Int::MiniModel::IntLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition mm-rel.cpp:52
Test::Int::MiniModel::IntLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition mm-rel.cpp:58
Test::Int::MiniModel::IntLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition mm-rel.cpp:69
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Test::Int::Test::cmp
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition int.hpp:285
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition int.hh:925
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( ).
Definition int.hh:930
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( ).
Definition int.hh:928
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::lex
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntPropLevel ipl=IPL_DEF)
Post lexical order between x and y.
Definition aliases.hpp:132
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
Test::Int::MiniModel
Tests for minimal modelling constraints (simple relations)
Definition mm-rel.cpp:41
Test::Int::MiniModel::c
Create c
Definition mm-rel.cpp:125
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test
General test support.
Definition afc.cpp:39
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56
int.hh