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
distinct
dom.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, 2003
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 <climits>
35
36
namespace
Gecode
{
namespace
Int {
namespace
Distinct {
37
38
template
<
class
View>
39
forceinline
40
Dom<View>::Dom
(
Home
home,
ViewArray<View>
&
x
)
41
:
NaryPropagator
<View,
PC_INT_DOM
>(home,
x
) {}
42
43
template
<
class
View>
44
ExecStatus
45
Dom<View>::post
(
Home
home,
ViewArray<View>
&
x
) {
46
if
(
x
.size() == 2)
47
return
Rel::Nq<View,View>::post
(home,
x
[0],
x
[1]);
48
if
(
x
.size() == 3)
49
return
TerDom<View>::post
(home,
x
[0],
x
[1],
x
[2]);
50
if
(
x
.size() > 3) {
51
// Do bounds propagation to make view-value graph smaller
52
GECODE_ES_CHECK
(prop_bnd<View>(home,
x
));
53
(void)
new
(home)
Dom<View>
(home,
x
);
54
}
55
return
ES_OK
;
56
}
57
58
template
<
class
View>
59
forceinline
60
Dom<View>::Dom
(
Space
& home,
Dom<View>
&
p
)
61
:
NaryPropagator
<View,
PC_INT_DOM
>(home,
p
) {}
62
63
template
<
class
View>
64
PropCost
65
Dom<View>::cost
(
const
Space
&,
const
ModEventDelta
& med)
const
{
66
if
(View::me(med) ==
ME_INT_VAL
)
67
return
PropCost::linear
(
PropCost::LO
,
x
.size());
68
else
69
return
PropCost::quadratic
(
PropCost::HI
,
x
.size());
70
}
71
72
template
<
class
View>
73
Actor
*
74
Dom<View>::copy
(
Space
& home) {
75
return
new
(home)
Dom<View>
(home,*
this
);
76
}
77
78
#ifdef GECODE_HAS_CBS
79
template
<
class
View>
80
void
81
Dom<View>::solndistrib
(
Space
& home, Propagator::SendMarginal send)
const
{
82
cbsdistinct(home,this->
id
(),
x
,send);
83
}
84
85
template
<
class
View>
86
void
87
Dom<View>::domainsizesum(Propagator::InDecision in,
unsigned
int
&
size
,
88
unsigned
int
& size_b)
const
{
89
cbssize(
x
,in,
size
,size_b);
90
}
91
#endif
92
93
94
template
<
class
View>
95
ExecStatus
96
Dom<View>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
97
if
(View::me(med) ==
ME_INT_VAL
) {
98
ExecStatus
es = prop_val<View,false>(home,
x
);
99
GECODE_ES_CHECK
(es);
100
if
(
x
.size() < 2)
101
return
home.
ES_SUBSUMED
(*
this
);
102
if
(es ==
ES_FIX
)
103
return
home.
ES_FIX_PARTIAL
(*
this
,View::med(
ME_INT_DOM
));
104
es = prop_bnd<View>(home,
x
);
105
GECODE_ES_CHECK
(es);
106
if
(
x
.size() < 2)
107
return
home.
ES_SUBSUMED
(*
this
);
108
es = prop_val<View,true>(home,
x
);
109
GECODE_ES_CHECK
(es);
110
if
(
x
.size() < 2)
111
return
home.
ES_SUBSUMED
(*
this
);
112
return
home.
ES_FIX_PARTIAL
(*
this
,View::med(
ME_INT_DOM
));
113
}
114
115
if
(
x
.size() == 2)
116
GECODE_REWRITE
(*
this
,(
Rel::Nq<View,View>::post
(home(*
this
),
x
[0],
x
[1])));
117
if
(
x
.size() == 3)
118
GECODE_REWRITE
(*
this
,
TerDom<View>::post
(home(*
this
),
x
[0],
x
[1],
x
[2]));
119
120
if
(dc.available()) {
121
GECODE_ES_CHECK
(dc.sync());
122
}
else
{
123
GECODE_ES_CHECK
(dc.init(home,
x
));
124
}
125
126
bool
assigned
;
127
GECODE_ES_CHECK
(dc.propagate(home,
assigned
));
128
129
return
ES_FIX
;
130
}
131
132
}}}
133
134
// STATISTICS: int-prop
135
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Gecode::Int::Distinct::Dom::Dom
Dom(Space &home, Dom< View > &p)
Constructor for cloning p.
Definition:
dom.hpp:60
Gecode::Int::Distinct::TerDom::post
static ExecStatus post(Home home, View x0, View x1, View x2)
Post propagator for views x.
Definition:
ter-dom.hpp:49
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3563
Gecode::Int::Distinct::Dom::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition:
dom.hpp:45
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition:
nq.hpp:49
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::Int::Precede::assigned
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition:
single.hpp:43
Gecode::PropCost::LO
@ LO
Cheap.
Definition:
core.hpp:513
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::PropCost::linear
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition:
core.hpp:4796
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:628
Gecode::PropCost::quadratic
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition:
core.hpp:4787
Gecode::Int::Rel::Nq
Binary disequality propagator.
Definition:
rel.hh:460
Gecode::Int::ME_INT_VAL
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition:
var-type.hpp:56
Gecode
Gecode toplevel namespace
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::Distinct::TerDom
Ternary domain consistent distinct propagator.
Definition:
distinct.hh:322
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:856
Gecode::NaryPropagator
n-ary propagator
Definition:
pattern.hpp:142
Gecode::Int::Distinct::Dom::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition:
dom.hpp:65
Gecode::Int::Distinct::Dom::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
dom.hpp:96
Gecode::Int::Distinct::Dom
Domain consistent distinct propagator.
Definition:
distinct.hh:283
Gecode::Int::Distinct::Dom::copy
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition:
dom.hpp:74
Gecode::PropCost
Propagation cost.
Definition:
core.hpp:486
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:477
forceinline
#define forceinline
Definition:
config.hpp:185
Gecode::PropCost::HI
@ HI
Expensive.
Definition:
core.hpp:514
Gecode::ViewArray
View arrays.
Definition:
array.hpp:253
Gecode::Space::ES_FIX_PARTIAL
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition:
core.hpp:3569
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
Gecode::Int::ME_INT_DOM
const Gecode::ModEvent ME_INT_DOM
Domain operation has changed the domain.
Definition:
var-type.hpp:72
GECODE_REWRITE
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition:
macros.hpp:116
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