Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
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 11:48:53 +0100 (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) {
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 
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 
const Gecode::ModEvent ME_SET_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:138
const Gecode::ModEvent ME_SET_LUB
Domain operation has changed the least upper bound.
Definition: var-type.hpp:156
SetVarImp(Space &home, bool share, SetVarImp &x)
Constructor for cloning x.
Definition: set.cpp:121
int ModEvent
Type for modification events.
Definition: core.hpp:146
Finite integer set variable implementation.
Definition: var-imp.hpp:434
unsigned int card(void) const
Return cardinality.
Definition: integerset.hpp:134
Computation spaces.
Definition: core.hpp:1362
Gecode::IntSet d(v, 7)
unsigned int size(void) const
Return size.
Definition: integerset.hpp:97
unsigned int cardMax(void) const
Return current cardinality maximum.
Definition: set.hpp:106
void become(Space &home, const BndSet &s)
Make this set equal to s.
Definition: integerset.hpp:215
static ModEvent me(const ModEventDelta &med)
Project modification event for this variable type from med.
unsigned int cardMin(void) const
Return current cardinality minimum.
Definition: set.hpp:103
const Gecode::ModEvent ME_SET_CGLB
Domain operation has changed the greatest lower bound and the cardinality.
Definition: var-type.hpp:186
const Gecode::ModEvent ME_SET_GLB
Domain operation has changed the greatest lower bound.
Definition: var-type.hpp:164
void update(Space &home, BndSet &x)
Update this set to be a clone of set x.
Definition: integerset.hpp:144
Base-class for Set-variable implementations.
Definition: var-imp.hpp:117
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
const Gecode::ModEvent ME_SET_CLUB
Domain operation has changed the least upper bound and the cardinality.
Definition: var-type.hpp:179
#define forceinline
Definition: config.hpp:132
Gecode::ModEvent notify(Gecode::Space &home, Gecode::ModEvent me, Gecode::Delta &d)
Notify that variable implementation has been modified with modification event me and delta informatio...
Definition: var-imp.hpp:294
Gecode toplevel namespace
const Gecode::ModEvent ME_SET_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:142
const Gecode::ModEvent ME_SET_CARD
Domain operation has changed the variable cardinality.
Definition: var-type.hpp:148
bool assigned(void) const
Test whether variable is assigned.
Definition: set.hpp:98