Generated on Sun Aug 26 2012 08:43:09 for Gecode by doxygen 1.8.1.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: 2011-08-18 20:26:27 +1000 (Thu, 18 Aug 2011) $ by $Author: tack $
13  * $Revision: 12314 $
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 using namespace Gecode::Int;
46 
47 namespace Gecode {
48 
49  void
50  rel(Home home, SetVar s, IntRelType r, IntVar x) {
51  if (home.failed()) return;
52  switch (r) {
53  case IRT_EQ:
54  {
56  Set::SingletonView xsingle(xv);
59  ::post(home,s,xsingle)));
60 
61  }
62  break;
63  case IRT_NQ:
64  {
66  GECODE_ME_FAIL( sv.cardMin(home, 1));
68  Set::SingletonView xsingle(xv);
71  ::post(home,xsingle,sv)));
72 
73  }
74  break;
75  case IRT_LQ:
76  {
78  rel(home, tmp, IRT_LQ, x);
80  }
81  break;
82  case IRT_LE:
83  {
85  rel(home, tmp, IRT_LE, x);
87  }
88  break;
89  case IRT_GQ:
90  {
92  rel(home, tmp, IRT_GQ, x);
94  }
95  break;
96  case IRT_GR:
97  {
99  rel(home, tmp, IRT_GR, x);
101  }
102  break;
103  default:
104  throw UnknownRelation("Set::rel");
105  }
106 
107  }
108 
109  void
110  rel(Home home, IntVar x, IntRelType r, SetVar s) {
111  IntRelType rr;
112  switch (r) {
113  case IRT_LE: rr=IRT_GR; break;
114  case IRT_LQ: rr=IRT_GQ; break;
115  case IRT_GR: rr=IRT_LE; break;
116  case IRT_GQ: rr=IRT_LQ; break;
117  default: rr=r;
118  }
119  rel(home, s, rr, x);
120  }
121 
122  void
123  min(Home home, SetVar s, IntVar x){
124  if (home.failed()) return;
126  }
127  void
128  notMin(Home home, SetVar s, IntVar x){
129  if (home.failed()) return;
131  }
132  void
133  min(Home home, SetVar s, IntVar x, BoolVar b){
134  if (home.failed()) return;
137  }
138  void
139  max(Home home, SetVar s, IntVar x){
140  if (home.failed()) return;
142  }
143  void
144  notMax(Home home, SetVar s, IntVar x){
145  if (home.failed()) return;
147  }
148  void
149  max(Home home, SetVar s, IntVar x, BoolVar b){
150  if (home.failed()) return;
153  }
154 
155  void
156  channelSorted(Home home, const IntVarArgs& x, SetVar y) {
157  if (home.failed()) return;
158  ViewArray<IntView> xa(home,x);
160  }
161 
162  void
163  channel(Home home, const IntVarArgs& x, const SetVarArgs& y) {
164  if (home.failed()) return;
166  for (int i=x.size(); i--;)
167  new (&xa[i]) Int::CachedView<Int::IntView>(x[i]);
169  for (int i=y.size(); i--;)
170  new (&ya[i]) Set::CachedView<Set::SetView>(y[i]);
172  }
173 
174  void
175  channel(Home home, const BoolVarArgs& x, SetVar y) {
176  if (home.failed()) return;
177  ViewArray<Int::BoolView> xv(home,x);
179  ::post(home,xv,y)));
180  }
181 
183  SetVar x, IntVar y) {
184  if (home.failed()) return;
186  weights,x,y));
187  }
188 
189 }
190 
191 // STATISTICS: set-post