main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Sep 17 2012 22:20:45 for Gecode by
doxygen
1.8.1.1
gecode
set
var-imp
set.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Guido Tack <tack@gecode.org>
5
* Christian Schulte <schulte@gecode.org>
6
*
7
* Copyright:
8
* Guido Tack, 2004
9
* Christian Schulte, 2004
10
*
11
* Last modified:
12
* $Date: 2009-02-05 21:48:53 +1100 (Thu, 05 Feb 2009) $ by $Author: schulte $
13
* $Revision: 8155 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/set.hh
>
41
42
43
namespace
Gecode {
namespace
Set {
44
45
/*
46
* "Standard" tell operations
47
*
48
*/
49
ModEvent
50
SetVarImp::cardMin_full(Space& home) {
51
ModEvent
me
=
ME_SET_CARD
;
52
if
(
cardMin
() == lub.
size
()) {
53
glb.
become
(home, lub);
54
me =
ME_SET_VAL
;
55
}
56
SetDelta
d
;
57
return
notify
(home, me, d);
58
}
59
60
ModEvent
61
SetVarImp::cardMax_full(Space& home) {
62
ModEvent
me =
ME_SET_CARD
;
63
if
(
cardMax
() == glb.
size
()) {
64
lub.
become
(home, glb);
65
me =
ME_SET_VAL
;
66
}
67
SetDelta
d
;
68
return
notify
(home, me, d);
69
}
70
71
ModEvent
72
SetVarImp::processLubChange(Space& home, SetDelta&
d
) {
73
ModEvent
me =
ME_SET_LUB
;
74
if
(
cardMax
() > lub.
size
()) {
75
lub.
card
(lub.
size
());
76
if
(
cardMin
() >
cardMax
()) {
77
glb.
become
(home, lub);
78
glb.
card
(glb.
size
());
79
lub.
card
(glb.
size
());
80
return
ME_SET_FAILED
;
81
}
82
me =
ME_SET_CLUB
;
83
}
84
if
(
cardMax
() == lub.
size
() &&
cardMin
() ==
cardMax
()) {
85
glb.
become
(home, lub);
86
me =
ME_SET_VAL
;
87
assert(d.glbMin() == 1);
88
assert(d.glbMax() == 0);
89
}
90
return
notify
(home, me, d);
91
}
92
93
ModEvent
94
SetVarImp::processGlbChange(Space& home, SetDelta& d) {
95
ModEvent
me =
ME_SET_GLB
;
96
if
(
cardMin
() < glb.
size
()) {
97
glb.
card
(glb.
size
());
98
if
(
cardMin
() >
cardMax
()) {
99
glb.
become
(home, lub);
100
glb.
card
(glb.
size
());
101
lub.
card
(glb.
size
());
102
return
ME_SET_FAILED
;
103
}
104
me =
ME_SET_CGLB
;
105
}
106
if
(
cardMin
() == glb.
size
() &&
cardMin
() ==
cardMax
()) {
107
lub.
become
(home, glb);
108
me =
ME_SET_VAL
;
109
assert(d.lubMin() == 1);
110
assert(d.lubMax() == 0);
111
}
112
return
notify
(home, me, d);
113
}
114
115
/*
116
* Copying variables
117
*
118
*/
119
120
forceinline
121
SetVarImp::SetVarImp
(
Space
& home,
bool
share,
SetVarImp
& x)
122
:
SetVarImpBase
(home,share,x) {
123
lub.
update
(home, x.lub);
124
glb.
card
(x.
cardMin
());
125
lub.
card
(x.
cardMax
());
126
if
(x.
assigned
()) {
127
glb.
become
(home,lub);
128
}
else
{
129
glb.
update
(home,x.glb);
130
}
131
}
132
133
134
SetVarImp
*
135
SetVarImp::perform_copy(
Space
& home,
bool
share) {
136
return
new
(home)
SetVarImp
(home,share,*
this
);
137
}
138
139
}}
140
141
// STATISTICS: set-var
142