main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
gecode
int
count
int-gq.hpp
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, 2006
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
namespace
Gecode
{
namespace
Int {
namespace
Count {
35
36
template
<
class
VX,
class
VY>
37
forceinline
38
GqInt<VX,VY>::GqInt
(
Home
home,
ViewArray<VX>
&
x
,
int
n_s, VY
y
,
int
c
)
39
:
IntBase
<VX,VY>(home,
x
,n_s,
y
,
c
) {}
40
41
template
<
class
VX,
class
VY>
42
ExecStatus
43
GqInt<VX,VY>::post
(
Home
home,
ViewArray<VX>
&
x
, VY
y
,
int
c
) {
44
// Eliminate decided views
45
int
n_x =
x
.size();
46
for
(
int
i
=n_x;
i
--; )
47
switch
(
holds
(
x
[
i
],
y
)) {
48
case
RT_FALSE
:
49
x
[
i
] =
x
[--n_x];
break
;
50
case
RT_TRUE
:
51
x
[
i
] =
x
[--n_x];
c
--;
break
;
52
case
RT_MAYBE
:
53
break
;
54
default
:
55
GECODE_NEVER
;
56
}
57
x
.size(n_x);
58
// RHS too large
59
if
(n_x <
c
)
60
return
ES_FAILED
;
61
// Whatever the x[i] take for values, the inequality is subsumed
62
if
(
c
<= 0)
63
return
ES_OK
;
64
// All views must be equal
65
if
(
c
== n_x)
66
return
post_true
(home,
x
,
y
);
67
(void)
new
(home)
GqInt<VX,VY>
(home,
x
,
c
+1,
y
,
c
);
68
return
ES_OK
;
69
}
70
71
template
<
class
VX,
class
VY>
72
forceinline
73
GqInt<VX,VY>::GqInt
(
Space
& home,
GqInt<VX,VY>
&
p
)
74
:
IntBase
<VX,VY>(home,
p
) {}
75
76
template
<
class
VX,
class
VY>
77
Actor
*
78
GqInt<VX,VY>::copy
(
Space
& home) {
79
return
new
(home)
GqInt<VX,VY>
(home,*
this
);
80
}
81
82
template
<
class
VX,
class
VY>
83
ExecStatus
84
GqInt<VX,VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
85
// Eliminate decided views from subscribed views
86
int
n_x =
x
.size();
87
for
(
int
i
=n_s;
i
--; )
88
switch
(
holds
(
x
[
i
],
y
)) {
89
case
RT_FALSE
:
90
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
91
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
92
break
;
93
case
RT_TRUE
:
94
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
95
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
c
--;
96
break
;
97
case
RT_MAYBE
:
98
break
;
99
default
:
100
GECODE_NEVER
;
101
}
102
x
.size(n_x);
103
if
(n_x <
c
)
104
return
ES_FAILED
;
105
if
(
c
<= 0)
106
return
home.
ES_SUBSUMED
(*
this
);
107
// Eliminate decided views from unsubscribed views
108
for
(
int
i
=n_x;
i
-- > n_s; )
109
switch
(
holds
(
x
[
i
],
y
)) {
110
case
RT_FALSE
:
x
[
i
]=
x
[--n_x];
break
;
111
case
RT_TRUE
:
x
[
i
]=
x
[--n_x];
c
--;
break
;
112
case
RT_MAYBE
:
break
;
113
default
:
GECODE_NEVER
;
114
}
115
x
.size(n_x);
116
if
(n_x <
c
)
117
return
ES_FAILED
;
118
if
(
c
<= 0)
119
return
home.
ES_SUBSUMED
(*
this
);
120
if
(
c
== n_x) {
121
// All views must be equal
122
GECODE_ES_CHECK
(
post_true
(home,
x
,
y
));
123
return
home.
ES_SUBSUMED
(*
this
);
124
}
125
// Now, there must be new subscriptions from x[n_s] up to x[c+1]
126
while
(n_s <=
c
)
127
x
[n_s++].subscribe(home,*
this
,
PC_INT_DOM
,
false
);
128
return
ES_FIX
;
129
}
130
131
}}}
132
133
// STATISTICS: int-prop
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::Int::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition:
view.hpp:1737
Gecode::Int::Count::GqInt::GqInt
GqInt(Space &home, GqInt &p)
Constructor for cloning p.
Definition:
int-gq.hpp:73
Gecode
Gecode toplevel namespace
Gecode::Int::RT_MAYBE
@ RT_MAYBE
Relation may hold or not.
Definition:
view.hpp:1736
Gecode::Int::Count::IntBase
Baseclass for count propagators (integer)
Definition:
count.hh:138
Gecode::Int::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition:
view.hpp:1735
GECODE_ES_CHECK
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition:
macros.hpp:91
Gecode::Int::Count::GqInt
Propagator for counting views (greater or equal integer to number of equal views)
Definition:
count.hh:202
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::Int::Count::post_true
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition:
rel.hpp:151
Gecode::Int::Count::GqInt::copy
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition:
int-gq.hpp:78
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:56
Gecode::Int::Count::GqInt::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition:
int-gq.hpp:43
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
Gecode::Int::Count::GqInt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
int-gq.hpp:84
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::Int::Count::holds
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition:
rel.hpp:115
Test::Float::Arithmetic::c
Gecode::FloatVal c(-8, 8)
Gecode::ViewArray< VX >
Gecode::ES_FAILED
@ ES_FAILED
Execution has resulted in failure.
Definition:
core.hpp:474
Gecode::Int::PC_INT_DOM
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition:
var-type.hpp:100
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:89
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:476
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:232
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:472