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