Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
38namespace Test { namespace Int {
39
41 namespace Unshare {
42
49 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
Node * x
Pointer to corresponding Boolean expression node.
Passing Boolean variables.
Definition int.hh:712
Passing integer variables.
Definition int.hh:656
Integer variable array.
Definition int.hh:763
Regular expressions over integer values.
Computation spaces.
Definition core.hpp:1742
Base class for assignments
Definition int.hh:59
Gecode::IntPropLevel ipl
Propagation level.
Definition int.hh:234
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition int.hpp:209
Test for unsharing Boolean variables
Definition unshare.cpp:72
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:84
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:78
Bool(void)
Create and register test.
Definition unshare.cpp:75
Test for unsharing in failed spaces
Definition unshare.cpp:97
Failed(void)
Create and register test.
Definition unshare.cpp:100
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:108
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:103
Test for unsharing integer variables
Definition unshare.cpp:49
Int(Gecode::IntPropLevel ipl)
Create and register test.
Definition unshare.cpp:52
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition unshare.cpp:55
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition unshare.cpp:61
void fail(void)
Fail space.
Definition core.hpp:4030
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:979
@ IPL_BND
Bounds propagation.
Definition int.hh:978
Gecode toplevel namespace
Int i_bnd(Gecode::IPL_BND)
Int i_dom(Gecode::IPL_DOM)
General test support.
Definition afc.cpp:39
Region r
Definition region.cpp:65