Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
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 
40 namespace 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  }
54  SetCmpRel
55  operator <=(const SetExpr& e0, const SetExpr& e1) {
56  return SetCmpRel(e0, SRT_SUB, e1);
57  }
58  BoolExpr
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, IntPropLevel) override;
90  };
91 
92  SetIRTRel::SetIRTRel(const SetExpr& s, IntRelType irt, const LinIntExpr& x)
93  : _s(s), _x(x), _irt(irt) {}
94 
95  void
96  SetIRTRel::post(Home home, BoolVar b, bool neg, IntPropLevel ipl) {
97  if (b.zero()) {
98  rel(home, _s.post(home), neg ? _irt : Gecode::neg(_irt),
99  _x.post(home, ipl));
100  } else if (b.one()) {
101  rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
102  _x.post(home, ipl));
103  } else {
104  rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
105  _x.post(home, ipl), b);
106  }
107  }
108  }
109 
110 
111  /*
112  * IRT relations with SetExpr
113  *
114  */
115  BoolExpr
116  operator ==(const SetExpr& x, const LinIntExpr& y) {
117  return BoolExpr(new SetIRTRel(x, IRT_EQ, y));
118  }
119  BoolExpr
120  operator ==(const LinIntExpr& x, const SetExpr& y) {
121  return operator ==(y, x);
122  }
123 
124  BoolExpr
125  operator !=(const SetExpr& x, const LinIntExpr& y) {
126  return BoolExpr(new SetIRTRel(x, IRT_NQ, y));
127  }
128 
129  BoolExpr
130  operator !=(const LinIntExpr& x, const SetExpr& y) {
131  return operator !=(y, x);
132  }
133 
134  BoolExpr
135  operator <=(const SetExpr& x, const LinIntExpr& y) {
136  return BoolExpr(new SetIRTRel(x, IRT_LQ, y));
137  }
138 
139  BoolExpr
140  operator <=(const LinIntExpr& x, const SetExpr& y) {
141  return operator >=(y, x);
142  }
143 
144  BoolExpr
145  operator <(const SetExpr& x, const LinIntExpr& y) {
146  return BoolExpr(new SetIRTRel(x, IRT_LE, y));
147  }
148 
149  BoolExpr
150  operator <(const LinIntExpr& x, const SetExpr& y) {
151  return operator >(y, x);
152  }
153 
154  BoolExpr
155  operator >=(const SetExpr& x, const LinIntExpr& y) {
156  return BoolExpr(new SetIRTRel(x, IRT_GQ, y));
157  }
158 
159  BoolExpr
160  operator >=(const LinIntExpr& x, const SetExpr& y) {
161  return operator <=(y, x);
162  }
163 
164  BoolExpr
165  operator >(const SetExpr& x, const LinIntExpr& y) {
166  return BoolExpr(new SetIRTRel(x, IRT_GR, y));
167  }
168 
169  BoolExpr
170  operator >(const LinIntExpr& x, const SetExpr& y) {
171  return operator <(y, x);
172  }
173 
174 }
175 
176 #endif
177 
178 // STATISTICS: minimodel-any
NNF * l
Left subtree.
Definition: bool-expr.cpp:240
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:238
Set relations
Definition: minimodel.hh:1130
Less or equal ( )
Definition: int.hh:928
Greater ( )
Definition: int.hh:931
Superset ( )
Definition: set.hh:647
Comparison relation (for two-sided comparisons)
Definition: minimodel.hh:1117
Greater or equal ( )
Definition: int.hh:930
Set expressions
Definition: minimodel.hh:1060
bool one(void) const
Test whether domain is one.
Definition: bool.hpp:107
Miscealloneous Boolean expressions.
Definition: minimodel.hh:1240
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition: irt.hpp:52
Equality ( )
Definition: int.hh:926
IntRelType
Relation types for integers.
Definition: int.hh:925
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:317
SetExpr r
Right side of relation.
Definition: minimodel.hh:1122
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Subset ( )
Definition: set.hh:646
Less ( )
Definition: int.hh:929
Boolean expressions.
Definition: minimodel.hh:1225
Boolean integer variables.
Definition: int.hh:512
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Linear expressions over integer variables.
Definition: minimodel.hh:140
bool operator>=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:277
bool zero(void) const
Test whether domain is zero.
Definition: bool.hpp:103
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:43
Equality ( )
Definition: set.hh:644
Disjoint ( )
Definition: set.hh:648
Post propagator for SetVar x
Definition: set.hh:767
bool operator>(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:260
bool operator<(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:226
bool operator==(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:294
bool operator<=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:243
Disequality ( )
Definition: set.hh:645
Gecode toplevel namespace
Disequality ( )
Definition: int.hh:927
Home class for posting propagators
Definition: core.hpp:853
BoolExpr operator||(const BoolExpr &l, const BoolExpr &r)
Disjunction of Boolean expressions.
Definition: bool-expr.cpp:591
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138