member.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, 2011
*
* 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 <gecode/minimodel.hh>
#include "test/int.hh"
namespace Test { namespace Int {
namespace Member {
class Int : public Test {
public:
Int(int n) : Test("Member::Int::"+str(n),n+1,0,n,true) {}
virtual bool solution(const Assignment& x) const {
int n = x.size() - 1;
for (int i=n; i--; )
if (x[i] == x[n])
return true;
return false;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
int n = x.size() - 1;
IntVarArgs y(n);
for (int i=n; i--; )
y[i] = x[i];
member(home, y, x[n]);
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
Gecode::Reify r) {
using namespace Gecode;
int n = x.size() - 1;
IntVarArgs y(n);
for (int i=n; i--; )
y[i] = x[i];
member(home, y, x[n], r);
}
};
class Bool : public Test {
public:
Bool(int n) : Test("Member::Bool::"+str(n),n+1,0,1,true) {}
virtual bool solution(const Assignment& x) const {
int n = x.size() - 1;
for (int i=n; i--; )
if (x[i] == x[n])
return true;
return false;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
int n = x.size() - 1;
BoolVarArgs y(n);
for (int i=n; i--; )
y[i] = channel(home,x[i]);
member(home, y, channel(home,x[n]));
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x,
Gecode::Reify r) {
using namespace Gecode;
int n = x.size() - 1;
BoolVarArgs y(n);
for (int i=n; i--; )
y[i] = channel(home,x[i]);
member(home, y, channel(home,x[n]), r);
}
};
class Create {
public:
Create(void) {
for (int i=0; i<=4; i++) {
(void) new Int(i);
(void) new Bool(i);
}
}
};
Create c;
}
}}
// STATISTICS: test-int
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::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::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::Member::Bool
Test membership for Boolean variables
Definition member.cpp:82
Test::Int::Member::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition member.cpp:104
Test::Int::Member::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition member.cpp:95
Test::Int::Member::Bool::Bool
Bool(int n)
Create and register test.
Definition member.cpp:85
Test::Int::Member::Bool::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition member.cpp:87
Test::Int::Member::Create
Help class to create and register tests.
Definition member.cpp:116
Test::Int::Member::Create::Create
Create(void)
Perform creation and registration.
Definition member.cpp:119
Test::Int::Member::Int
Test membership for integer variables
Definition member.cpp:48
Test::Int::Member::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition member.cpp:61
Test::Int::Member::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition member.cpp:70
Test::Int::Member::Int::Int
Int(int n)
Create and register test.
Definition member.cpp:51
Test::Int::Member::Int::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition member.cpp:53
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
Gecode::member
void member(Home home, const IntVarArgs &x, IntVar y, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
Definition member.cpp:39
Test::Int::Member
Tests for membership constraints
Definition member.cpp:40
Test::Int::Member::c
Create c
Definition member.cpp:127
Test::Int
Testing finite domain integers.
Definition int.cpp:40
Test
General test support.
Definition afc.cpp:39
Test::r
Region r
Definition region.cpp:65
int.hh