Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
unshare.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2008
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include "test/int.hh"
35 
36 #include <gecode/minimodel.hh>
37 
38 namespace Test { namespace Int {
39 
41  namespace Unshare {
42 
48  class Int : public Test {
50  public:
53  : Test("Unshare::Int::"+str(ipl),9,-1,1,false,ipl) {}
55  virtual bool solution(const Assignment& x) const {
56  return ((x[0] == x[3]) &&
57  (x[1] == x[4]) && (x[1] == x[6]) &&
58  (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
59  }
61  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
62  using namespace Gecode;
63  IntVarArgs y(6);
64  y[0]=x[0]; y[1]=y[3]=x[1]; y[2]=y[4]=y[5]=x[2];
65  unshare(home, y, ipl);
66  for (int i=0; i<6; i++)
67  rel(home, y[i], IRT_EQ, x[3+i], IPL_DOM);
68  }
69  };
70 
72  class Bool : public Test {
73  public:
75  Bool(void)
76  : Test("Unshare::Bool",9,0,1,false) {}
78  virtual bool solution(const Assignment& x) const {
79  return ((x[0] == x[3]) &&
80  (x[1] == x[4]) && (x[1] == x[6]) &&
81  (x[2] == x[5]) && (x[2] == x[7]) && (x[2] == x[8]));
82  }
84  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
85  using namespace Gecode;
86  BoolVarArgs y(6);
87  y[0]=channel(home,x[0]);
88  y[1]=y[3]=channel(home,x[1]);
89  y[2]=y[4]=y[5]=channel(home,x[2]);
90  unshare(home, y);
91  for (int i=0; i<6; i++)
92  rel(home, y[i], IRT_EQ, channel(home,x[3+i]));
93  }
94  };
95 
97  class Failed : public Test {
98  public:
100  Failed(void)
101  : Test("Unshare::Failed",1,-1,1) {}
103  virtual bool solution(const Assignment& x) const {
104  (void) x;
105  return false;
106  }
108  virtual void post(Gecode::Space& home, Gecode::IntVarArray& x) {
109  using namespace Gecode;
110  home.fail();
111  IntVarArgs y(2);
112  y[0]=x[0]; y[1]=x[0];
113  unshare(home, y);
114  REG r(1);
115  extensional(home, y, r);
116  }
117  };
118 
121 
123 
126 
127  }
128 }}
129 
130 // STATISTICS: test-int
Bounds propagation.
Definition: int.hh:978
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition: int.hpp:208
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:41
Regular expressions over integer values.
Definition: minimodel.hh:1518
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: unshare.cpp:61
Integer variable array.
Definition: int.hh:763
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: unshare.cpp:84
Computation spaces.
Definition: core.hpp:1701
Test for unsharing Boolean variables
Definition: unshare.cpp:72
Int i_bnd(Gecode::IPL_BND)
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: unshare.cpp:103
Bool(void)
Create and register test.
Definition: unshare.cpp:75
Equality ( )
Definition: int.hh:926
Gecode::IntArgs i({1, 2, 3, 4})
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: unshare.cpp:78
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
void fail(void)
Fail space.
Definition: core.hpp:3957
Failed(void)
Create and register test.
Definition: unshare.cpp:100
Gecode::IntPropLevel ipl
Propagation level.
Definition: int.hh:234
Passing integer variables.
Definition: int.hh:656
Passing Boolean variables.
Definition: int.hh:712
General test support.
Definition: afc.cpp:39
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Test for unsharing in failed spaces
Definition: unshare.cpp:97
Int i_dom(Gecode::IPL_DOM)
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Region r
Definition: region.cpp:65
Base class for assignments
Definition: int.hh:59
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
Gecode toplevel namespace
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition: unshare.cpp:55
Test for unsharing integer variables
Definition: unshare.cpp:49
Int(Gecode::IntPropLevel ipl)
Create and register test.
Definition: unshare.cpp:52
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition: unshare.cpp:108
void unshare(Home home, BoolVarArgs &x, IntPropLevel)
Replace multiple variable occurences in x by fresh variables.
Definition: unshare.cpp:141