Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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
39namespace Gecode { namespace Set {
40
41 /*
42 * "Standard" tell operations
43 *
44 */
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
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
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 }
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
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
144 void
148 void
152
153
154}}
155
156// STATISTICS: set-var
157
Base-class for advisors.
Definition core.hpp:1294
Base-class for propagators.
Definition core.hpp:1066
Finite set delta information for advisors.
Definition var-imp.hpp:52
SetVarImpBase(Gecode::Space &home, SetVarImpBase &x)
Constructor for cloning x.
Definition var-imp.hpp:343
void reschedule(Gecode::Space &home, Gecode::Propagator &p, Gecode::PropCond pc, bool assigned)
Re-schedule propagator p.
Definition var-imp.hpp:360
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
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
static void schedule(Gecode::Space &home, Gecode::Propagator &p, Gecode::ModEvent me)
Schedule propagator p.
Definition var-imp.hpp:356
Finite integer set variable implementation.
Definition var-imp.hpp:430
unsigned int cardMax(void) const
Return current cardinality maximum.
Definition set.hpp:102
bool assigned(void) const
Test whether variable is assigned.
Definition set.hpp:94
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition set.cpp:149
unsigned int cardMin(void) const
Return current cardinality minimum.
Definition set.hpp:99
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition set.cpp:140
SetVarImp(Space &home, SetVarImp &x)
Constructor for cloning x.
Definition set.cpp:117
Computation spaces.
Definition core.hpp:1744
static ModEvent me(const ModEventDelta &med)
Definition core.hpp:4277
Finite integer sets.
Definition var-imp.hpp:137
const Gecode::ModEvent ME_SET_CLUB
Domain operation has changed the least upper bound and the cardinality.
Definition var-type.hpp:179
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_GLB
Domain operation has changed the greatest lower bound.
Definition var-type.hpp:164
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_CARD
Domain operation has changed the variable cardinality.
Definition var-type.hpp:148
const Gecode::ModEvent ME_SET_LUB
Domain operation has changed the least upper bound.
Definition var-type.hpp:156
Gecode toplevel namespace
int PropCond
Type for propagation conditions.
Definition core.hpp:72
Post propagator for SetVar x
Definition set.hh:773
int ModEvent
Type for modification events.
Definition core.hpp:62
Gecode::IntSet d(v, 7)
#define forceinline
Definition config.hpp:194