Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
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/minimodel.hh>
41 
42 #ifdef GECODE_HAS_SET_VARS
43 
44 namespace Gecode {
45 
46  /*
47  * Operators
48  *
49  */
50  SetRel
51  operator ==(const SetExpr& e0, const SetExpr& e1) {
52  return SetRel(e0, SRT_EQ, e1);
53  }
54  SetRel
55  operator !=(const SetExpr& e0, const SetExpr& e1) {
56  return SetRel(e0, SRT_NQ, e1);
57  }
58  SetCmpRel
59  operator <=(const SetExpr& e0, const SetExpr& e1) {
60  return SetCmpRel(e0, SRT_SUB, e1);
61  }
62  BoolExpr
63  operator <=(const SetCmpRel& r, const SetExpr& l) {
64  return BoolExpr(r) && BoolExpr(r.r <= l);
65  }
66  SetCmpRel
67  operator >=(const SetExpr& e0, const SetExpr& e1) {
68  return SetCmpRel(e0, SRT_SUP, e1);
69  }
70  BoolExpr
71  operator >=(const SetCmpRel& r, const SetExpr& l) {
72  return BoolExpr(r) && BoolExpr(r.r >= l);
73  }
74  SetRel
75  operator ||(const SetExpr& e0, const SetExpr& e1) {
76  return SetRel(e0, SRT_DISJ, e1);
77  }
78 
79  namespace {
80 
82  class SetIRTRel : public BoolExpr::Misc {
84  SetExpr _s;
86  LinIntExpr _x;
88  IntRelType _irt;
89  public:
91  SetIRTRel(const SetExpr&, IntRelType, const LinIntExpr&);
93  virtual void post(Home, BoolVar b, bool neg, IntPropLevel) override;
94  };
95 
96  SetIRTRel::SetIRTRel(const SetExpr& s, IntRelType irt, const LinIntExpr& x)
97  : _s(s), _x(x), _irt(irt) {}
98 
99  void
100  SetIRTRel::post(Home home, BoolVar b, bool neg, IntPropLevel ipl) {
101  if (b.zero()) {
102  rel(home, _s.post(home), neg ? _irt : Gecode::neg(_irt),
103  _x.post(home, ipl));
104  } else if (b.one()) {
105  rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
106  _x.post(home, ipl));
107  } else {
108  rel(home, _s.post(home), neg ? Gecode::neg(_irt) : _irt,
109  _x.post(home, ipl), b);
110  }
111  }
112  }
113 
114 
115  /*
116  * IRT relations with SetExpr
117  *
118  */
119  BoolExpr
120  operator ==(const SetExpr& x, const LinIntExpr& y) {
121  return BoolExpr(new SetIRTRel(x, IRT_EQ, y));
122  }
123  BoolExpr
124  operator ==(const LinIntExpr& x, const SetExpr& y) {
125  return operator ==(y, x);
126  }
127 
128  BoolExpr
129  operator !=(const SetExpr& x, const LinIntExpr& y) {
130  return BoolExpr(new SetIRTRel(x, IRT_NQ, y));
131  }
132 
133  BoolExpr
134  operator !=(const LinIntExpr& x, const SetExpr& y) {
135  return operator !=(y, x);
136  }
137 
138  BoolExpr
139  operator <=(const SetExpr& x, const LinIntExpr& y) {
140  return BoolExpr(new SetIRTRel(x, IRT_LQ, y));
141  }
142 
143  BoolExpr
144  operator <=(const LinIntExpr& x, const SetExpr& y) {
145  return operator >=(y, x);
146  }
147 
148  BoolExpr
149  operator <(const SetExpr& x, const LinIntExpr& y) {
150  return BoolExpr(new SetIRTRel(x, IRT_LE, y));
151  }
152 
153  BoolExpr
154  operator <(const LinIntExpr& x, const SetExpr& y) {
155  return operator >(y, x);
156  }
157 
158  BoolExpr
159  operator >=(const SetExpr& x, const LinIntExpr& y) {
160  return BoolExpr(new SetIRTRel(x, IRT_GQ, y));
161  }
162 
163  BoolExpr
164  operator >=(const LinIntExpr& x, const SetExpr& y) {
165  return operator <=(y, x);
166  }
167 
168  BoolExpr
169  operator >(const SetExpr& x, const LinIntExpr& y) {
170  return BoolExpr(new SetIRTRel(x, IRT_GR, y));
171  }
172 
173  BoolExpr
174  operator >(const LinIntExpr& x, const SetExpr& y) {
175  return operator <(y, x);
176  }
177 
178 }
179 
180 #endif
181 
182 // STATISTICS: minimodel-any
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:242
Set relations
Definition: minimodel.hh:1134
Less or equal ( )
Definition: int.hh:907
Greater ( )
Definition: int.hh:910
Superset ( )
Definition: set.hh:649
Comparison relation (for two-sided comparisons)
Definition: minimodel.hh:1121
Greater or equal ( )
Definition: int.hh:909
Set expressions
Definition: minimodel.hh:1064
bool one(void) const
Test whether domain is one.
Definition: bool.hpp:111
Miscealloneous Boolean expressions.
Definition: minimodel.hh:1244
IntRelType neg(IntRelType irt)
Return negated relation type of irt.
Definition: irt.hpp:56
Equality ( )
Definition: int.hh:905
IntRelType
Relation types for integers.
Definition: int.hh:904
bool operator!=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:321
SetExpr r
Right side of relation.
Definition: minimodel.hh:1126
Subset ( )
Definition: set.hh:648
Less ( )
Definition: int.hh:908
Boolean expressions.
Definition: minimodel.hh:1229
Boolean integer variables.
Definition: int.hh:492
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:953
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Linear expressions over integer variables.
Definition: minimodel.hh:144
bool operator>=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:281
bool zero(void) const
Test whether domain is zero.
Definition: bool.hpp:107
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
Equality ( )
Definition: set.hh:646
Disjoint ( )
Definition: set.hh:650
Post propagator for SetVar x
Definition: set.hh:769
bool operator>(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:264
bool operator<(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:230
bool operator==(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:298
bool operator<=(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:247
Disequality ( )
Definition: set.hh:647
Gecode toplevel namespace
Disequality ( )
Definition: int.hh:906
Home class for posting propagators
Definition: core.hpp:846
BoolExpr operator||(const BoolExpr &l, const BoolExpr &r)
Disjunction of Boolean expressions.
Definition: bool-expr.cpp:596
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:142