unshare.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 Unshare {
class Int : public Test {
public:
Int(Gecode::IntPropLevel ipl)
: Test("Unshare::Int::"+str(ipl),9,-1,1,false,ipl) {}
virtual bool solution(const Assignment& x) const {
return ((x[0] == x[3]) &&
(x[1] == x[4]) && (x[1] == x[6]) &&
(x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
IntVarArgs y(6);
y[0]=x[0]; y[1]=y[3]=x[1]; y[2]=y[4]=y[5]=x[2];
unshare(home, y, ipl);
for (int i=0; i<6; i++)
rel(home, y[i], IRT_EQ, x[3+i], IPL_DOM);
}
};
class Bool : public Test {
public:
Bool(void)
: Test("Unshare::Bool",9,0,1,false) {}
virtual bool solution(const Assignment& x) const {
return ((x[0] == x[3]) &&
(x[1] == x[4]) && (x[1] == x[6]) &&
(x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
BoolVarArgs y(6);
y[0]=channel(home,x[0]);
y[1]=y[3]=channel(home,x[1]);
y[2]=y[4]=y[5]=channel(home,x[2]);
unshare(home, y);
for (int i=0; i<6; i++)
rel(home, y[i], IRT_EQ, channel(home,x[3+i]));
}
};
class Failed : public Test {
public:
Failed(void)
: Test("Unshare::Failed",1,-1,1) {}
virtual bool solution(const Assignment& x) const {
(void) x;
return false;
}
virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
using namespace Gecode;
home.fail();
IntVarArgs y(2);
y[0]=x[0]; y[1]=x[0];
unshare(home, y);
REG r(1);
extensional(home, y, r);
}
};
Int i_bnd(Gecode::IPL_BND);
Int i_dom(Gecode::IPL_DOM);
Bool b;
Failed f;
}
}}
// 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::REG
Regular expressions over integer values.
Definition minimodel.hh:1625
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Int::Assignment
Base class for assignments
Definition int.hh:59
Test::Int::Test::ipl
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:234
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Test::Int::Unshare::Bool
Test for unsharing Boolean variables
Definition unshare.cpp:72
Test::Int::Unshare::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:84
Test::Int::Unshare::Bool::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:78
Test::Int::Unshare::Bool::Bool
Bool(void)
Create and register test.
Definition unshare.cpp:75
Test::Int::Unshare::Failed
Test for unsharing in failed spaces
Definition unshare.cpp:97
Test::Int::Unshare::Failed::Failed
Failed(void)
Create and register test.
Definition unshare.cpp:100
Test::Int::Unshare::Failed::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:108
Test::Int::Unshare::Failed::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:103
Test::Int::Unshare::Int
Test for unsharing integer variables
Definition unshare.cpp:49
Test::Int::Unshare::Int::Int
Int(Gecode::IntPropLevel ipl)
Create and register test.
Definition unshare.cpp:52
Test::Int::Unshare::Int::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:55
Test::Int::Unshare::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:61
Gecode::Space::fail
void fail(void)
Fail space.
Definition core.hpp:4030
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
Gecode::extensional
void extensional(Home home, const IntVarArgs &x, DFA d, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for extensional constraint described by a DFA.
Definition extensional-regular.cpp:39
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
Gecode::IRT_EQ
@ IRT_EQ
Equality ( ).
Definition int.hh:926
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition int.hh:978
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::unshare
void unshare(Home home, IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Replace multiple variable occurences in x by fresh variables.
Definition unshare.cpp:136
Test::Int::Unshare
Tests for unsharing variables in arrays
Definition unshare.cpp:41
Test::Int::Unshare::i_bnd
Int i_bnd(Gecode::IPL_BND)
Test::Int::Unshare::i_dom
Int i_dom(Gecode::IPL_DOM)
Test::Int::Unshare::f
Failed f
Definition unshare.cpp:124
Test::Int::Unshare::b
Bool b
Definition unshare.cpp:122
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