Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
int.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  * Last modified:
12  * $Date: 2012-10-19 05:58:26 +0200 (Fri, 19 Oct 2012) $ by $Author: tack $
13  * $Revision: 13156 $
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/set.hh>
41 
42 #include <gecode/set/int.hh>
43 #include <gecode/set/rel.hh>
44 
45 namespace Gecode {
46 
47  void
49  if (home.failed()) return;
50  switch (r) {
51  case IRT_EQ:
52  {
54  Set::SingletonView xsingle(xv);
57  ::post(home,s,xsingle)));
58 
59  }
60  break;
61  case IRT_NQ:
62  {
64  GECODE_ME_FAIL( sv.cardMin(home, 1));
66  Set::SingletonView xsingle(xv);
69  ::post(home,xsingle,sv)));
70 
71  }
72  break;
73  case IRT_LQ:
74  {
76  rel(home, tmp, IRT_LQ, x);
78  }
79  break;
80  case IRT_LE:
81  {
83  rel(home, tmp, IRT_LE, x);
85  }
86  break;
87  case IRT_GQ:
88  {
90  rel(home, tmp, IRT_GQ, x);
92  }
93  break;
94  case IRT_GR:
95  {
97  rel(home, tmp, IRT_GR, x);
99  }
100  break;
101  default:
102  throw Int::UnknownRelation("Set::rel");
103  }
104 
105  }
106 
107  void
109  IntRelType rr;
110  switch (r) {
111  case IRT_LE: rr=IRT_GR; break;
112  case IRT_LQ: rr=IRT_GQ; break;
113  case IRT_GR: rr=IRT_LE; break;
114  case IRT_GQ: rr=IRT_LQ; break;
115  default: rr=r;
116  }
117  rel(home, s, rr, x);
118  }
119 
120  void
121  min(Home home, SetVar s, IntVar x){
122  if (home.failed()) return;
124  }
125  void
126  notMin(Home home, SetVar s, IntVar x){
127  if (home.failed()) return;
129  }
130  void
131  min(Home home, SetVar s, IntVar x, Reify r){
132  if (home.failed()) return;
133  switch (r.mode()) {
134  case RM_EQV:
136  ::post(home,s,x,r.var())));
137  break;
138  case RM_IMP:
140  ::post(home,s,x,r.var())));
141  break;
142  case RM_PMI:
144  ::post(home,s,x,r.var())));
145  break;
146  default: throw Gecode::Int::UnknownReifyMode("Set::min");
147  }
148  }
149  void
150  max(Home home, SetVar s, IntVar x){
151  if (home.failed()) return;
153  }
154  void
155  notMax(Home home, SetVar s, IntVar x){
156  if (home.failed()) return;
158  }
159  void
160  max(Home home, SetVar s, IntVar x, Reify r){
161  if (home.failed()) return;
162  switch (r.mode()) {
163  case RM_EQV:
165  ::post(home,s,x,r.var())));
166  break;
167  case RM_IMP:
169  ::post(home,s,x,r.var())));
170  break;
171  case RM_PMI:
173  ::post(home,s,x,r.var())));
174  break;
175  default: throw Gecode::Int::UnknownReifyMode("Set::max");
176  }
177  }
178 
180  SetVar x, IntVar y) {
181  if (home.failed()) return;
183  weights,x,y));
184  }
185 
186 }
187 
188 // STATISTICS: set-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
unsigned int cardMin(void) const
Return minimum cardinality.
Definition: set.hpp:86
Inverse implication for reification.
Definition: int.hh:847
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
Propagator for not maximum element
Definition: int.hh:174
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Less or equal ( )
Definition: int.hh:906
Greater ( )
Definition: int.hh:909
const int max
Largest allowed integer value.
Definition: int.hh:113
Greater or equal ( )
Definition: int.hh:908
const int min
Smallest allowed integer value.
Definition: int.hh:115
Propagator for reified minimum element
Definition: int.hh:115
Exception: Unknown relation passed as argument
Definition: exception.hpp:91
Equality ( )
Definition: int.hh:904
Propagator for not minimum element
Definition: int.hh:87
IntRelType
Relation types for integers.
Definition: int.hh:903
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Reification specification.
Definition: int.hh:854
Less ( )
Definition: int.hh:907
Singleton set view.
Definition: view.hpp:589
void notMax(Home home, SetVar s, IntVar x)
Post propagator that propagates that x is not the maximal element of s.
Definition: int.cpp:155
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Set view for set variables
Definition: view.hpp:60
Propagator for maximum element
Definition: int.hh:147
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Set variables
Definition: set.hh:129
Integer variables.
Definition: int.hh:350
Reified propagator for maximum element
Definition: int.hh:202
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition: rel.cpp:47
void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y)
Post propagator for .
Definition: int.cpp:179
Propagator for set equality
Definition: rel.hh:146
Propagator for the negated subset constraint
Definition: rel.hh:90
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
Propagator for weight of a set
Definition: int.hh:261
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
Disequality ( )
Definition: int.hh:905
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
void notMin(Home home, SetVar s, IntVar x)
Post propagator that propagates that x is not the minimal element of s.
Definition: int.cpp:126
Propagator for minimum element
Definition: int.hh:59
Equivalence for reification (default)
Definition: int.hh:833