Generated on Tue Oct 22 2013 00:49:00 for Gecode by doxygen 1.8.4
val-sel-commit.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  *
6  * Copyright:
7  * Christian Schulte, 2012
8  *
9  * Last modified:
10  * $Date: 2013-03-05 20:51:24 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13438 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #include <gecode/int/branch.hh>
39 
40 namespace Gecode { namespace Int { namespace Branch {
41 
42  ValSelCommitBase<IntView,int>*
43  valselcommitint(Space& home, int n, const IntValBranch& ivb) {
44  assert((ivb.select() != IntValBranch::SEL_VALUES_MIN) &&
46  switch (ivb.select()) {
48  return new (home)
51  return new (home)
54  return new (home)
57  return new (home)
60  return new (home)
63  return new (home)
66  return new (home)
69  return new (home)
72  if (ivb.commit() == NULL) {
73  return new (home)
75  } else {
76  return new (home)
78  }
83  {
84  IntSharedArray v(ivb.values());
85  if (n != v.size())
86  throw ArgumentSizeMismatch("Int::branch");
87  for (int i=n; i--; )
88  Limits::check(v[i],"Int::branch");
89  switch (ivb.select()) {
91  return new (home)
93  ValCommitEq<IntView> >(home,ivb);
95  return new (home)
97  ValCommitEq<IntView> >(home,ivb);
99  return new (home)
101  ValCommitEq<IntView> >(home,ivb);
103  return new (home)
105  ValCommitEq<IntView> >(home,ivb);
106  default: GECODE_NEVER;
107  }
108  }
109  default:
110  throw UnknownBranching("Int::branch");
111  }
112  }
113 
115  valselcommitint(Space& home, const IntAssign& ia) {
116  switch (ia.select()) {
117  case IntAssign::SEL_MIN:
118  return new (home)
120  case IntAssign::SEL_MED:
121  return new (home)
123  case IntAssign::SEL_MAX:
124  return new (home)
126  case IntAssign::SEL_RND:
127  return new (home)
130  if (ia.commit() == NULL) {
131  return new (home)
133  } else {
134  return new (home)
136  }
137  default:
138  throw UnknownBranching("Int::assign");
139  }
140  }
141 
143  valselcommitbool(Space& home, int n, const IntValBranch& ivb) {
144  switch (ivb.select()) {
150  return new (home)
156  return new (home)
159  return new (home)
162  if (ivb.commit() == NULL) {
163  return new (home)
165  } else {
166  return new (home)
168  }
173  {
174  IntSharedArray v(ivb.values());
175  if (n != v.size())
176  throw ArgumentSizeMismatch("Int::branch");
177  for (int i=n; i--; )
178  if ((v[i] < 0) || (v[i] > 1))
179  throw OutOfLimits("Int::branch");
180  switch (ivb.select()) {
182  return new (home)
184  ValCommitEq<BoolView> >(home,ivb);
186  return new (home)
188  ValCommitEq<BoolView> >(home,ivb);
190  return new (home)
192  ValCommitEq<BoolView> >(home,ivb);
194  return new (home)
196  ValCommitEq<BoolView> >(home,ivb);
197  default: GECODE_NEVER;
198  }
199  }
200  default:
201  throw UnknownBranching("Int::branch");
202  }
203  }
204 
206  valselcommitbool(Space& home, const IntAssign& ia) {
207  switch (ia.select()) {
208  case IntAssign::SEL_MIN:
209  return new (home)
211  case IntAssign::SEL_MED:
212  return new (home)
214  case IntAssign::SEL_MAX:
215  return new (home)
217  case IntAssign::SEL_RND:
218  return new (home)
221  if (ia.commit() == NULL) {
222  return new (home)
224  } else {
225  return new (home)
227  }
228  default:
229  throw UnknownBranching("Bool::assign");
230  }
231  }
232 
233 }}}
234 
235 
236 // STATISTICS: int-branch
237