Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
set-rel.cpp
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 * Matthias Balzer <matthias.balzer@itwm.fraunhofer.de>
6 *
7 * Copyright:
8 * Christian Schulte, 2005
9 * Fraunhofer ITWM, 2017
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/minimodel.hh>
37
38#ifdef GECODE_HAS_SET_VARS
39
40namespace Gecode {
41
42 /*
43 * Operators
44 *
45 */
46 SetRel
47 operator ==(const SetExpr& e0, const SetExpr& e1) {
48 return SetRel(e0, SRT_EQ, e1);
49 }
50 SetRel
51 operator !=(const SetExpr& e0, const SetExpr& e1) {
52 return SetRel(e0, SRT_NQ, e1);
53 }
55 operator <=(const SetExpr& e0, const SetExpr& e1) {
56 return SetCmpRel(e0, SRT_SUB, e1);
57 }
59 operator <=(const SetCmpRel& r, const SetExpr& l) {
60 return BoolExpr(r) && BoolExpr(r.r <= l);
61 }
62 SetCmpRel
63 operator >=(const SetExpr& e0, const SetExpr& e1) {
64 return SetCmpRel(e0, SRT_SUP, e1);
65 }
66 BoolExpr
67 operator >=(const SetCmpRel& r, const SetExpr& l) {
68 return BoolExpr(r) && BoolExpr(r.r >= l);
69 }
70 SetRel
71 operator ||(const SetExpr& e0, const SetExpr& e1) {
72 return SetRel(e0, SRT_DISJ, e1);
73 }
74
75 namespace {
76
78 class SetIRTRel : public BoolExpr::Misc {
80 SetExpr _s;
82 LinIntExpr _x;
84 IntRelType _irt;
85 public:
87 SetIRTRel(const SetExpr&, IntRelType, const LinIntExpr&);
89 virtual void post(Home, BoolVar b, bool neg,
90 const IntPropLevels&) override;
91 };
92
93 SetIRTRel::SetIRTRel(const SetExpr& s, IntRelType irt, const LinIntExpr& x)
94 : _s(s), _x(x), _irt(irt) {}
95
96 void
97 SetIRTRel::post(Home home, BoolVar b, bool neg,
98 const IntPropLevels& ipls) {
99 if (b.zero()) {
100 rel(home, _s.post(home), neg ? _irt : Gecode::neg(_irt),
101 _x.post(home, ipls));
102 } else if (b.one()) {
103 rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
104 _x.post(home, ipls));
105 } else {
106 rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
107 _x.post(home, ipls), b);
108 }
109 }
110 }
111
112
113 /*
114 * IRT relations with SetExpr
115 *
116 */
117 BoolExpr
118 operator ==(const SetExpr& x, const LinIntExpr& y) {
119 return BoolExpr(new SetIRTRel(x, IRT_EQ, y));
120 }
121 BoolExpr
122 operator ==(const LinIntExpr& x, const SetExpr& y) {
123 return operator ==(y, x);
124 }
125
126 BoolExpr
127 operator !=(const SetExpr& x, const LinIntExpr& y) {
128 return BoolExpr(new SetIRTRel(x, IRT_NQ, y));
129 }
130
131 BoolExpr
132 operator !=(const LinIntExpr& x, const SetExpr& y) {
133 return operator !=(y, x);
134 }
135
137 operator <=(const SetExpr& x, const LinIntExpr& y) {
138 return BoolExpr(new SetIRTRel(x, IRT_LQ, y));
139 }
140
142 operator <=(const LinIntExpr& x, const SetExpr& y) {
143 return operator >=(y, x);
144 }
145
147 operator <(const SetExpr& x, const LinIntExpr& y) {
148 return BoolExpr(new SetIRTRel(x, IRT_LE, y));
149 }
150
152 operator <(const LinIntExpr& x, const SetExpr& y) {
153 return operator >(y, x);
154 }
155
156 BoolExpr
157 operator >=(const SetExpr& x, const LinIntExpr& y) {
158 return BoolExpr(new SetIRTRel(x, IRT_GQ, y));
159 }
160
161 BoolExpr
162 operator >=(const LinIntExpr& x, const SetExpr& y) {
163 return operator <=(y, x);
164 }
165
166 BoolExpr
167 operator >(const SetExpr& x, const LinIntExpr& y) {
168 return BoolExpr(new SetIRTRel(x, IRT_GR, y));
169 }
170
171 BoolExpr
172 operator >(const LinIntExpr& x, const SetExpr& y) {
173 return operator <(y, x);
174 }
175
176}
177
178#endif
179
180// STATISTICS: minimodel-any
NNF * l
Left subtree.
struct Gecode::@603::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Node * x
Pointer to corresponding Boolean expression node.
bool neg
Is atomic formula negative.
Boolean expressions.
Linear expressions over integer variables.
Definition minimodel.hh:245
Comparison relation (for two-sided comparisons)
Set expressions
Set relations
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
IntRelType
Relation types for integers.
Definition int.hh:925
@ IRT_EQ
Equality ( )
Definition int.hh:926
@ IRT_NQ
Disequality ( )
Definition int.hh:927
@ IRT_GQ
Greater or equal ( )
Definition int.hh:930
@ IRT_LE
Less ( )
Definition int.hh:929
@ IRT_GR
Greater ( )
Definition int.hh:931
@ IRT_LQ
Less or equal ( )
Definition int.hh:928
@ SRT_NQ
Disequality ( )
Definition set.hh:645
@ SRT_EQ
Equality ( )
Definition set.hh:644
@ SRT_SUP
Superset ( )
Definition set.hh:647
@ SRT_DISJ
Disjoint ( )
Definition set.hh:648
@ SRT_SUB
Subset ( )
Definition set.hh:646
Gecode toplevel namespace
bool operator<=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:243
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
SetRel operator||(const SetExpr &, const SetExpr &)
Disjointness of set expressions.
Definition set-rel.cpp:71
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition irt.hpp:52
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
bool operator>=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:277
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
Post propagator for SetVar x
Definition set.hh:767
bool operator==(const FloatVal &x, const FloatVal &y)
Definition val.hpp:294
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition val.hpp:317