main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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
* Last modified:
10
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11
* $Revision: 14967 $
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
namespace
Gecode
{
namespace
Int {
namespace
Count {
39
40
template
<
class
VX,
class
VY>
41
forceinline
42
GqInt<VX,VY>::GqInt
(
Home
home,
ViewArray<VX>
&
x
,
int
n_s, VY
y
,
int
c
)
43
:
IntBase
<VX,VY>(home,
x
,n_s,
y
,
c
) {}
44
45
template
<
class
VX,
class
VY>
46
ExecStatus
47
GqInt<VX,VY>::post
(
Home
home,
ViewArray<VX>
&
x
, VY
y
,
int
c
) {
48
// Eliminate decided views
49
int
n_x =
x
.size();
50
for
(
int
i
=n_x;
i
--; )
51
switch
(
holds
(
x
[
i
],
y
)) {
52
case
RT_FALSE
:
53
x
[
i
] =
x
[--n_x];
break
;
54
case
RT_TRUE
:
55
x
[
i
] =
x
[--n_x];
c
--;
break
;
56
case
RT_MAYBE
:
57
break
;
58
default
:
59
GECODE_NEVER
;
60
}
61
x
.size(n_x);
62
// RHS too large
63
if
(n_x <
c
)
64
return
ES_FAILED
;
65
// Whatever the x[i] take for values, the inequality is subsumed
66
if
(
c
<= 0)
67
return
ES_OK
;
68
// All views must be equal
69
if
(
c
== n_x)
70
return
post_true
(home,
x
,
y
);
71
(void)
new
(home)
GqInt<VX,VY>
(home,
x
,
c
+1,
y
,
c
);
72
return
ES_OK
;
73
}
74
75
template
<
class
VX,
class
VY>
76
forceinline
77
GqInt<VX,VY>::GqInt
(
Space
& home,
bool
share,
GqInt<VX,VY>
&
p
)
78
:
IntBase
<VX,VY>(home,share,
p
) {}
79
80
template
<
class
VX,
class
VY>
81
Actor
*
82
GqInt<VX,VY>::copy
(
Space
& home,
bool
share) {
83
return
new
(home)
GqInt<VX,VY>
(home,share,*
this
);
84
}
85
86
template
<
class
VX,
class
VY>
87
ExecStatus
88
GqInt<VX,VY>::propagate
(
Space
& home,
const
ModEventDelta
&) {
89
// Eliminate decided views from subscribed views
90
int
n_x =
x
.size();
91
for
(
int
i
=n_s;
i
--; )
92
switch
(
holds
(
x
[
i
],
y
)) {
93
case
RT_FALSE
:
94
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
95
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
96
break
;
97
case
RT_TRUE
:
98
x
[
i
].cancel(home,*
this
,
PC_INT_DOM
);
99
x
[
i
]=
x
[--n_s];
x
[n_s]=
x
[--n_x];
c
--;
100
break
;
101
case
RT_MAYBE
:
102
break
;
103
default
:
104
GECODE_NEVER
;
105
}
106
x
.size(n_x);
107
if
(n_x <
c
)
108
return
ES_FAILED
;
109
if
(
c
<= 0)
110
return
home.
ES_SUBSUMED
(*
this
);
111
// Eliminate decided views from unsubscribed views
112
for
(
int
i
=n_x;
i
-- > n_s; )
113
switch
(
holds
(
x
[
i
],
y
)) {
114
case
RT_FALSE
:
x
[
i
]=
x
[--n_x];
break
;
115
case
RT_TRUE
:
x
[
i
]=
x
[--n_x];
c
--;
break
;
116
case
RT_MAYBE
:
break
;
117
default
:
GECODE_NEVER
;
118
}
119
x
.size(n_x);
120
if
(n_x <
c
)
121
return
ES_FAILED
;
122
if
(
c
<= 0)
123
return
home.
ES_SUBSUMED
(*
this
);
124
if
(
c
== n_x) {
125
// All views must be equal
126
GECODE_ES_CHECK
(
post_true
(home,
x
,
y
));
127
return
home.
ES_SUBSUMED
(*
this
);
128
}
129
// Now, there must be new subscriptions from x[n_s] up to x[c+1]
130
while
(n_s <=
c
)
131
x
[n_s++].subscribe(home,*
this
,
PC_INT_DOM
,
false
);
132
return
ES_FIX
;
133
}
134
135
}}}
136
137
// STATISTICS: int-prop
Gecode::Int::Count::GqInt::copy
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition:
int-gq.hpp:82
Gecode::Int::Count::GqInt::GqInt
GqInt(Space &home, bool share, GqInt &p)
Constructor for cloning p.
Definition:
int-gq.hpp:77
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode::Int::RT_TRUE
@ RT_TRUE
Relation does hold.
Definition:
view.hpp:1617
Gecode
Gecode toplevel namespace
Gecode::Int::RT_MAYBE
@ RT_MAYBE
Relation may hold or not.
Definition:
view.hpp:1616
Gecode::Int::Count::IntBase
Baseclass for count propagators (integer)
Definition:
count.hh:139
Gecode::Int::RT_FALSE
@ RT_FALSE
Relation does not hold.
Definition:
view.hpp:1615
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:95
Gecode::Int::Count::GqInt
Propagator for counting views (greater or equal integer to number of equal views)
Definition:
count.hh:203
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::Int::Count::post_true
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition:
rel.hpp:144
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:60
Gecode::Int::Count::GqInt::post
static ExecStatus post(Home home, ViewArray< VX > &x, VY y, int c)
Post propagator for .
Definition:
int-gq.hpp:47
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:545
Gecode::Int::Count::GqInt::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
int-gq.hpp:88
Gecode::Int::Count::holds
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition:
rel.hpp:108
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:542
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:169
Gecode::ES_OK
@ ES_OK
Execution is okay.
Definition:
core.hpp:544
p
int p
Number of positive literals for node type.
Definition:
bool-expr.cpp:236
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:540