main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
test
int
precede.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <Chris.Mears@monash.edu>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
*
9
* Copyright:
10
* Christopher Mears, 2011
11
* Christian Schulte, 2011
12
*
13
* This file is part of Gecode, the generic constraint
14
* development environment:
15
* http://www.gecode.org
16
*
17
* Permission is hereby granted, free of charge, to any person obtaining
18
* a copy of this software and associated documentation files (the
19
* "Software"), to deal in the Software without restriction, including
20
* without limitation the rights to use, copy, modify, merge, publish,
21
* distribute, sublicense, and/or sell copies of the Software, and to
22
* permit persons to whom the Software is furnished to do so, subject to
23
* the following conditions:
24
*
25
* The above copyright notice and this permission notice shall be
26
* included in all copies or substantial portions of the Software.
27
*
28
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
*
36
*/
37
38
#include "
test/int.hh
"
39
40
namespace
Test
{
namespace
Int {
41
43
namespace
Precede {
44
46
class
Single
:
public
Test
{
47
private
:
49
int
s, t;
50
public
:
52
Single
(
int
s0,
int
t0)
53
:
Test
(
"Precede::Single::"
+
str
(s0)+
"<"
+
str
(t0),8,1,4),
54
s(s0),
t
(t0) {}
56
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
57
int
n
=
x
.size();
58
for
(
int
i
= 0 ;
i
<
n
;
i
++) {
59
if
(
x
[
i
] ==
t
)
60
return
false
;
61
if
(
x
[
i
] == s)
62
return
true
;
63
}
64
return
true
;
65
}
67
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
68
Gecode::precede
(home,
x
, s,
t
);
69
}
70
};
71
73
class
Multi
:
public
Test
{
74
private
:
76
Gecode::IntArgs
c;
77
public
:
79
Multi
(
const
Gecode::IntArgs
& c0)
80
:
Test
(
"Precede::Multi::"
+
str
(c0),6,1,5), c(c0) {
81
contest
=
CTL_NONE
;
82
}
84
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
85
for
(
int
j=0; j<c.
size
()-1; j++)
86
for
(
int
i
=0;
i
<
x
.size();
i
++) {
87
if
(
x
[
i
] == c[j+1])
88
return
false
;
89
if
(
x
[
i
] == c[j])
90
break
;
91
}
92
return
true
;
93
}
95
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
96
Gecode::precede
(home,
x
, c);
97
}
98
};
99
100
Single
_a
(2, 3);
101
Single
_b
(1, 4);
102
103
Multi
_c
(
Gecode::IntArgs
({1,2,3}));
104
Multi
_d
(
Gecode::IntArgs
({3,2,1}));
105
Multi
_e
(
Gecode::IntArgs
({4,2,3,1}));
106
107
}
108
109
}}
110
111
// STATISTICS: test-int
Test::Int::Test::contest
ConTestLevel contest
Whether to test for certain consistency.
Definition:
int.hh:236
Test::Int::Precede::Single::Single
Single(int s0, int t0)
Create and register test.
Definition:
precede.cpp:52
Test::Int::Precede::_a
Single _a(2, 3)
Test::Int::Precede::Single::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
precede.cpp:56
Test::Int::CTL_NONE
@ CTL_NONE
No consistency-test.
Definition:
int.hh:140
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Test::Int::Precede::_d
Multi _d(Gecode::IntArgs({3, 2, 1}))
Test::Int::Precede::_b
Single _b(1, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Int::Precede::_c
Multi _c(Gecode::IntArgs({1, 2, 3}))
int.hh
Test::Int::Precede::Single::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
precede.cpp:67
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Test::Int::Precede::Multi::Multi
Multi(const Gecode::IntArgs &c0)
Create and register test.
Definition:
precede.cpp:79
Test::Int::Precede::Multi
Test for multiple value precedence constraint
Definition:
precede.cpp:73
Test::Int::Precede::Multi::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
precede.cpp:95
Test::Int::Precede::_e
Multi _e(Gecode::IntArgs({4, 2, 3, 1}))
Gecode::FloatVal::size
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition:
val.hpp:78
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:59
Gecode::precede
void precede(Home home, const IntVarArgs &x, int s, int t, IntPropLevel)
Post propagator that s precedes t in x.
Definition:
precede.cpp:43
Test
General test support.
Definition:
afc.cpp:39
Test::Int::Precede::Single
Test for single value precedence constraint
Definition:
precede.cpp:46
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Gecode::IntArgs
Passing integer arguments.
Definition:
int.hh:628
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::Precede::Multi::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
precede.cpp:84
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:209