Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 #include <gecode/set.hh>
37 
38 
39 namespace Gecode { namespace Set {
40 
41  /*
42  * "Standard" tell operations
43  *
44  */
45  ModEvent
46  SetVarImp::cardMin_full(Space& home) {
48  if (cardMin() == lub.size()) {
49  glb.become(home, lub);
50  me = ME_SET_VAL;
51  }
52  SetDelta d;
53  return notify(home, me, d);
54  }
55 
56  ModEvent
57  SetVarImp::cardMax_full(Space& home) {
59  if (cardMax() == glb.size()) {
60  lub.become(home, glb);
61  me = ME_SET_VAL;
62  }
63  SetDelta d;
64  return notify(home, me, d);
65  }
66 
67  ModEvent
68  SetVarImp::processLubChange(Space& home, SetDelta& d) {
70  if (cardMax() > lub.size()) {
71  lub.card(lub.size());
72  if (cardMin() > cardMax()) {
73  glb.become(home, lub);
74  glb.card(glb.size());
75  lub.card(glb.size());
76  return fail(home);
77  }
78  me = ME_SET_CLUB;
79  }
80  if (cardMax() == lub.size() && cardMin() == cardMax()) {
81  glb.become(home, lub);
82  me = ME_SET_VAL;
83  assert(d.glbMin() == 1);
84  assert(d.glbMax() == 0);
85  }
86  return notify(home, me, d);
87  }
88 
89  ModEvent
90  SetVarImp::processGlbChange(Space& home, SetDelta& d) {
92  if (cardMin() < glb.size()) {
93  glb.card(glb.size());
94  if (cardMin() > cardMax()) {
95  glb.become(home, lub);
96  glb.card(glb.size());
97  lub.card(glb.size());
98  return fail(home);
99  }
100  me = ME_SET_CGLB;
101  }
102  if (cardMin() == glb.size() && cardMin() == cardMax()) {
103  lub.become(home, glb);
104  me = ME_SET_VAL;
105  assert(d.lubMin() == 1);
106  assert(d.lubMax() == 0);
107  }
108  return notify(home, me, d);
109  }
110 
111  /*
112  * Copying variables
113  *
114  */
115 
118  : SetVarImpBase(home,x) {
119  lub.update(home, x.lub);
120  glb.card(x.cardMin());
121  lub.card(x.cardMax());
122  if (x.assigned()) {
123  glb.become(home,lub);
124  } else {
125  glb.update(home,x.glb);
126  }
127  }
128 
129 
130  SetVarImp*
131  SetVarImp::perform_copy(Space& home) {
132  return new (home) SetVarImp(home,*this);
133  }
134 
135  /*
136  * Dependencies
137  *
138  */
139  void
141  bool schedule) {
143  }
144  void
145  SetVarImp::subscribe(Space& home, Advisor& a, bool fail) {
147  }
148  void
151  }
152 
153 
154 }}
155 
156 // STATISTICS: set-var
157 
Post propagator for SetVar x
Definition: set.hh:767
SetVarImp(Space &home, SetVarImp &x)
Constructor for cloning x.
Definition: set.cpp:117
void reschedule(Gecode::Space &home, Gecode::Propagator &p, Gecode::PropCond pc, bool assigned)
Re-schedule propagator p.
Definition: var-imp.hpp:360
unsigned int cardMin(void) const
Return current cardinality minimum.
Definition: set.hpp:99
ModEvent fail(Space &home)
Run advisors to be run on failure and returns ME_GEN_FAILED.
Definition: core.hpp:4570
const Gecode::ModEvent ME_SET_CLUB
Domain operation has changed the least upper bound and the cardinality.
Definition: var-type.hpp:179
unsigned int cardMin(void) const
Return cardinality minimum.
Definition: set.hpp:78
unsigned int cardMax(void) const
Return current cardinality maximum.
Definition: set.hpp:102
const Gecode::ModEvent ME_SET_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:142
Computation spaces.
Definition: core.hpp:1742
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
void become(Space &home, const BndSet &s)
Make this set equal to s.
Definition: integerset.hpp:211
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
const Gecode::ModEvent ME_SET_GLB
Domain operation has changed the greatest lower bound.
Definition: var-type.hpp:164
const Gecode::ModEvent ME_SET_LUB
Domain operation has changed the least upper bound.
Definition: var-type.hpp:156
bool assigned(void) const
Test whether variable is assigned.
Definition: set.hpp:94
unsigned int size(void) const
Return size.
Definition: integerset.hpp:93
void update(Space &home, BndSet &x)
Update this set to be a clone of set x.
Definition: integerset.hpp:140
const Gecode::ModEvent ME_SET_CGLB
Domain operation has changed the greatest lower bound and the cardinality.
Definition: var-type.hpp:186
unsigned int cardMax(void) const
Return cardinality maximum.
Definition: set.hpp:81
static void schedule(Gecode::Space &home, Gecode::Propagator &p, Gecode::ModEvent me)
Schedule propagator p.
Definition: var-imp.hpp:356
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
int ModEvent
Type for modification events.
Definition: core.hpp:62
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: set.cpp:149
int PropCond
Type for propagation conditions.
Definition: core.hpp:72
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:365
Base-class for Set-variable implementations.
Definition: var-imp.hpp:139
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition: set.cpp:140
Gecode::IntSet d(v, 7)
void subscribe(Gecode::Space &home, Gecode::Propagator &p, Gecode::PropCond pc, bool assigned, bool schedule)
Subscribe propagator p with propagation condition pc.
Definition: var-imp.hpp:347
Base-class for advisors.
Definition: core.hpp:1292
static ModEvent me(const ModEventDelta &med)
Project modification event for this variable type from med.
Definition: core.hpp:4270
Finite integer set variable implementation.
Definition: var-imp.hpp:430
#define forceinline
Definition: config.hpp:185
const Gecode::ModEvent ME_SET_CARD
Domain operation has changed the variable cardinality.
Definition: var-type.hpp:148
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
unsigned int card(void) const
Return cardinality.
Definition: integerset.hpp:130