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
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
* Last modified:
10
* $Date: 2016-11-08 17:23:24 +0100 (Tue, 08 Nov 2016) $ by $Author: schulte $
11
* $Revision: 15253 $
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 <climits>
39
40
namespace
Gecode
{
namespace
Int {
namespace
Distinct {
41
42
template
<
class
View>
43
forceinline
44
Dom<View>::Dom
(
Home
home,
ViewArray<View>
&
x
)
45
:
NaryPropagator
<View,
PC_INT_DOM
>(home,
x
) {}
46
47
template
<
class
View>
48
ExecStatus
49
Dom<View>::post
(
Home
home,
ViewArray<View>
&
x
) {
50
if
(
x
.size() == 2)
51
return
Rel::Nq<View,View>::post
(home,
x
[0],
x
[1]);
52
if
(
x
.size() == 3)
53
return
TerDom<View>::post
(home,
x
[0],
x
[1],
x
[2]);
54
if
(
x
.size() > 3) {
55
// Do bounds propagation to make view-value graph smaller
56
GECODE_ES_CHECK
(prop_bnd<View>(home,
x
));
57
(void)
new
(home)
Dom<View>
(home,
x
);
58
}
59
return
ES_OK
;
60
}
61
62
template
<
class
View>
63
forceinline
64
Dom<View>::Dom
(
Space
& home,
bool
share,
Dom<View>
&
p
)
65
:
NaryPropagator
<View,
PC_INT_DOM
>(home,share,
p
) {}
66
67
template
<
class
View>
68
PropCost
69
Dom<View>::cost
(
const
Space
&,
const
ModEventDelta
& med)
const
{
70
if
(View::me(med) ==
ME_INT_VAL
)
71
return
PropCost::linear
(
PropCost::LO
,
x
.size());
72
else
73
return
PropCost::quadratic
(
PropCost::HI
,
x
.size());
74
}
75
76
template
<
class
View>
77
Actor
*
78
Dom<View>::copy
(
Space
& home,
bool
share) {
79
return
new
(home)
Dom<View>
(home,share,*
this
);
80
}
81
82
template
<
class
View>
83
ExecStatus
84
Dom<View>::propagate
(
Space
& home,
const
ModEventDelta
& med) {
85
if
(View::me(med) ==
ME_INT_VAL
) {
86
ExecStatus
es = prop_val<View,false>(home,
x
);
87
GECODE_ES_CHECK
(es);
88
if
(
x
.size() < 2)
89
return
home.
ES_SUBSUMED
(*
this
);
90
if
(es ==
ES_FIX
)
91
return
home.
ES_FIX_PARTIAL
(*
this
,View::med(
ME_INT_DOM
));
92
es = prop_bnd<View>(home,
x
);
93
GECODE_ES_CHECK
(es);
94
if
(
x
.size() < 2)
95
return
home.
ES_SUBSUMED
(*
this
);
96
es = prop_val<View,true>(home,
x
);
97
GECODE_ES_CHECK
(es);
98
if
(
x
.size() < 2)
99
return
home.
ES_SUBSUMED
(*
this
);
100
return
home.
ES_FIX_PARTIAL
(*
this
,View::med(
ME_INT_DOM
));
101
}
102
103
if
(
x
.size() == 2)
104
GECODE_REWRITE
(*
this
,(
Rel::Nq<View,View>::post
(home(*
this
),
x
[0],
x
[1])));
105
if
(
x
.size() == 3)
106
GECODE_REWRITE
(*
this
,
TerDom<View>::post
(home(*
this
),
x
[0],
x
[1],
x
[2]));
107
108
if
(dc.available()) {
109
GECODE_ES_CHECK
(dc.sync(home));
110
}
else
{
111
GECODE_ES_CHECK
(dc.init(home,
x
));
112
}
113
114
bool
assigned
;
115
GECODE_ES_CHECK
(dc.propagate(home,
assigned
));
116
117
return
ES_FIX
;
118
}
119
120
}}}
121
122
// STATISTICS: int-prop
123
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:784
forceinline
#define forceinline
Definition:
config.hpp:173
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:53
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Gecode::Int::Distinct::Dom::Dom
Dom(Space &home, bool share, Dom< View > &p)
Constructor for cloning p.
Definition:
dom.hpp:64
Gecode::Int::Distinct::Dom::post
static ExecStatus post(Home home, ViewArray< View > &x)
Post propagator for views x.
Definition:
dom.hpp:49
Gecode::Int::Rel::Nq::post
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition:
nq.hpp:53
Gecode::Int::Precede::assigned
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition:
single.hpp:47
Gecode::PropCost::LO
@ LO
Cheap.
Definition:
core.hpp:581
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::PropCost::linear
static PropCost linear(PropCost::Mod m, unsigned int n)
Linear complexity for modifier pcm and size measure n.
Definition:
core.hpp:4841
Gecode::Actor
Base-class for both propagators and branchers.
Definition:
core.hpp:696
Gecode::PropCost::quadratic
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition:
core.hpp:4832
Gecode::Int::Rel::Nq
Binary disequality propagator.
Definition:
rel.hh:464
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:95
Gecode::Int::Distinct::TerDom
Ternary domain consistent distinct propagator.
Definition:
distinct.hh:285
Gecode::Home
Home class for posting propagators
Definition:
core.hpp:922
Gecode::NaryPropagator
n-ary propagator
Definition:
propagator.hpp:149
Gecode::Int::Distinct::Dom::cost
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function.
Definition:
dom.hpp:69
Gecode::Int::Distinct::Dom::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
dom.hpp:84
Gecode::Int::Distinct::Dom
Domain consistent distinct propagator.
Definition:
distinct.hh:253
Gecode::Int::Distinct::Dom::copy
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition:
dom.hpp:78
Gecode::PropCost
Propagation cost.
Definition:
core.hpp:554
Gecode::ES_FIX
@ ES_FIX
Propagation has computed fixpoint.
Definition:
core.hpp:545
Gecode::PropCost::HI
@ HI
Expensive.
Definition:
core.hpp:582
Gecode::ViewArray
View arrays.
Definition:
array.hpp:234
Gecode::Space::ES_FIX_PARTIAL
ExecStatus ES_FIX_PARTIAL(Propagator &p, const ModEventDelta &med)
Propagator p has computed partial fixpoint
Definition:
core.hpp:3620
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::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:120
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