main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
test
int
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
:
52
Int
(
Gecode::IntPropLevel
ipl
)
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
119
Int
i_bnd
(
Gecode::IPL_BND
);
120
Int
i_dom
(
Gecode::IPL_DOM
);
121
122
Bool
b
;
123
124
Failed
f
;
126
127
}
128
}}
129
130
// STATISTICS: test-int
Test::Int::Unshare::Int::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
unshare.cpp:55
Test::r
Region r
Definition:
region.cpp:65
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
minimodel.hh
Test::Int::Test::ipl
Gecode::IntPropLevel ipl
Propagation level.
Definition:
int.hh:234
Test::Int::Unshare::Failed
Test for unsharing in failed spaces
Definition:
unshare.cpp:97
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
Test::Int::Unshare::Int
Test for unsharing integer variables
Definition:
unshare.cpp:49
Test::Int::Unshare::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
unshare.cpp:61
Gecode::IntPropLevel
IntPropLevel
Propagation levels for integer propagators.
Definition:
int.hh:974
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Int::Unshare::Failed::Failed
Failed(void)
Create and register test.
Definition:
unshare.cpp:100
int.hh
Gecode::REG
Regular expressions over integer values.
Definition:
minimodel.hh:1625
Test::Int::Unshare::i_bnd
Int i_bnd(Gecode::IPL_BND)
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Gecode
Gecode toplevel namespace
Test::Int::Unshare::b
Bool b
Definition:
unshare.cpp:122
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Test::Int::Unshare::Failed::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
unshare.cpp:108
Gecode::unshare
void unshare(Home home, BoolVarArgs &x, IntPropLevel)
Replace multiple variable occurences in x by fresh variables.
Definition:
unshare.cpp:141
Gecode::IPL_DOM
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition:
int.hh:979
Test::Int::Unshare::Bool
Test for unsharing Boolean variables
Definition:
unshare.cpp:72
Test::Int::Unshare::Failed::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
unshare.cpp:103
Gecode::IPL_BND
@ IPL_BND
Bounds propagation.
Definition:
int.hh:978
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:59
Test::Int::Unshare::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
unshare.cpp:84
Gecode::Space::fail
void fail(void)
Fail space.
Definition:
core.hpp:4030
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:43
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::Unshare::Int::Int
Int(Gecode::IntPropLevel ipl)
Create and register test.
Definition:
unshare.cpp:52
Test::Int::Unshare::Bool::Bool
Bool(void)
Create and register test.
Definition:
unshare.cpp:75
Test
General test support.
Definition:
afc.cpp:39
Gecode::extensional
void extensional(Home home, const IntVarArgs &x, DFA dfa, IntPropLevel)
Post domain consistent propagator for extensional constraint described by a DFA.
Definition:
extensional-regular.cpp:39
Test::Int::Unshare::f
Failed f
Definition:
unshare.cpp:124
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:926
Test::Int::Unshare::Bool::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
unshare.cpp:78
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::Unshare::i_dom
Int i_dom(Gecode::IPL_DOM)
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:209