Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
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 
Select smallest value.
Definition: int.hh:4085
Class for value selection and commit.
Select all values starting from smallest.
Definition: int.hh:3994
User-defined value selection.
Exception: Value out of limits
Definition: exception.hpp:48
Select values greater than mean of smallest and largest value.
Definition: int.hh:3990
Select the smallest range of the variable domain if it has several ranges, otherwise select values no...
Definition: int.hh:3991
Value selection class for nearest value.
Definition: branch.hh:396
Which values to select for branching first.
Definition: int.hh:3981
Select all values starting from largest.
Definition: int.hh:3995
Select select(void) const
Return selection strategy.
Definition: assign.hpp:53
Select value according to user-defined functions.
Definition: int.hh:3993
Select values not greater than mean of smallest and largest value.
Definition: int.hh:3989
Select select(void) const
Return selection strategy.
Definition: val.hpp:57
Value commit class for less or equal.
Definition: branch.hh:538
Computation spaces.
Definition: core.hpp:1362
Base class for value selection and commit.
Value commit class for greater.
Definition: branch.hh:582
Value selection class for mimimum of view.
Definition: branch.hh:248
Value selection class for average of view.
Definition: branch.hh:299
Value selection class for random value of view.
Definition: branch.hh:316
Select value nearest to a given value, use smaller one in case of ties.
Definition: int.hh:3996
Exception: Unknown value or variable selection passed as argument
Definition: exception.hpp:112
Select greatest value not greater than the median.
Definition: int.hh:4086
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Value selection class for minimum range of integer view.
Definition: branch.hh:339
Value selection class for maximum of view.
Definition: branch.hh:265
Select smallest value.
Definition: int.hh:3985
IntSharedArray values(void) const
Return shared array of values.
Definition: val.hpp:62
Select largest value.
Definition: int.hh:3987
Value commit class for greater or equal.
Definition: branch.hh:560
Select value near to a given value, decrement values first.
Definition: int.hh:3999
Select random value.
Definition: int.hh:4088
Select value nearest to a given value, use larger one in case of ties.
Definition: int.hh:3997
const int v[7]
Definition: distinct.cpp:207
Value commit class for equality.
Definition: branch.hh:516
Value selection class for median of view.
Definition: branch.hh:282
ValSelCommitBase< IntView, int > * valselcommitint(Space &home, int n, const IntValBranch &ivb)
Return value and commit for integer views.
Select largest value.
Definition: int.hh:4087
Select random value.
Definition: int.hh:3988
Select value according to user-defined functions.
Definition: int.hh:4089
VoidFunction commit(void) const
Return commit function.
Definition: branch-val.hpp:94
Which values to select for assignment.
Definition: int.hh:4081
ValSelCommitBase< BoolView, int > * valselcommitbool(Space &home, int n, const IntValBranch &ivb)
Return value and commit for Boolean views.
Select value near to a given value, increment values first.
Definition: int.hh:3998
Value selection class for nearest value.
Definition: branch.hh:372
Class for user-defined value commit.
Gecode toplevel namespace
Select the largest range of the variable domain if it has several ranges, otherwise select values gre...
Definition: int.hh:3992
Value selection class for maximum range of integer view.
Definition: branch.hh:355
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Select greatest value not greater than the median.
Definition: int.hh:3986