Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.9.1
circuit.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  * Guido Tack <tack@gecode.org>
6  *
7  * Copyright:
8  * Christian Schulte, 2006
9  * Guido Tack, 2011
10  *
11  * Last modified:
12  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
13  * $Revision: 13068 $
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/int/circuit.hh>
41 
42 namespace Gecode {
43 
44  void
45  circuit(Home home, int offset, const IntVarArgs& x, IntConLevel icl) {
46  Int::Limits::nonnegative(offset,"Int::circuit");
47  if (x.size() == 0)
48  throw Int::TooFewArguments("Int::circuit");
49  if (x.same(home))
50  throw Int::ArgumentSame("Int::circuit");
51  if (home.failed()) return;
52  ViewArray<Int::IntView> xv(home,x);
53 
54  if (offset == 0) {
55  typedef Int::NoOffset<Int::IntView> NOV;
56  NOV no;
57  if (icl == ICL_DOM) {
59  ::post(home,xv,no)));
60  } else {
62  ::post(home,xv,no)));
63  }
64  } else {
65  typedef Int::Offset OV;
66  OV off(-offset);
67  if (icl == ICL_DOM) {
69  ::post(home,xv,off)));
70  } else {
72  ::post(home,xv,off)));
73  }
74  }
75  }
76  void
77  circuit(Home home, const IntVarArgs& x, IntConLevel icl) {
78  circuit(home,0,x,icl);
79  }
80 
81  void
82  circuit(Home home, const IntArgs& c, int offset,
83  const IntVarArgs& x, const IntVarArgs& y, IntVar z,
84  IntConLevel icl) {
85  Int::Limits::nonnegative(offset,"Int::circuit");
86  int n = x.size();
87  if (n == 0)
88  throw Int::TooFewArguments("Int::circuit");
89  if (x.same(home))
90  throw Int::ArgumentSame("Int::circuit");
91  if ((y.size() != n) || (c.size() != n*n))
92  throw Int::ArgumentSizeMismatch("Int::circuit");
93  circuit(home, offset, x, icl);
94  if (home.failed()) return;
95  IntArgs cx(offset+n);
96  for (int i=0; i<offset; i++)
97  cx[i] = 0;
98  for (int i=n; i--; ) {
99  for (int j=0; j<n; j++)
100  cx[offset+j] = c[i*n+j];
101  element(home, cx, x[i], y[i]);
102  }
103  linear(home, y, IRT_EQ, z);
104  }
105  void
106  circuit(Home home, const IntArgs& c,
107  const IntVarArgs& x, const IntVarArgs& y, IntVar z,
108  IntConLevel icl) {
109  circuit(home,c,0,x,y,z,icl);
110  }
111  void
112  circuit(Home home, const IntArgs& c, int offset,
113  const IntVarArgs& x, IntVar z,
114  IntConLevel icl) {
115  Int::Limits::nonnegative(offset,"Int::circuit");
116  if (home.failed()) return;
118  circuit(home, c, offset, x, y, z, icl);
119  }
120  void
121  circuit(Home home, const IntArgs& c,
122  const IntVarArgs& x, IntVar z,
123  IntConLevel icl) {
124  circuit(home,c,0,x,z,icl);
125  }
126 
127  void
128  path(Home home, int offset, const IntVarArgs& x, IntVar s, IntVar e,
129  IntConLevel icl) {
130  Int::Limits::nonnegative(offset,"Int::path");
131  int n=x.size();
132  if (n == 0)
133  throw Int::TooFewArguments("Int::path");
134  if (x.same(home))
135  throw Int::ArgumentSame("Int::path");
136  if (home.failed()) return;
137  ViewArray<Int::IntView> xv(home,n+1);
138  for (int i=n; i--; )
139  xv[i] = Int::IntView(x[i]);
140  xv[n] = s;
141 
142  if (offset == 0) {
143  element(home, x, e, n);
144  typedef Int::NoOffset<Int::IntView> NOV;
145  NOV no;
146  if (icl == ICL_DOM) {
148  ::post(home,xv,no)));
149  } else {
151  ::post(home,xv,no)));
152  }
153  } else {
154  IntVarArgs ox(n+offset);
155  IntVar y(home, -1,-1);
156  for (int i=offset; i--; )
157  ox[i] = y;
158  for (int i=n; i--; )
159  ox[offset + i] = x[i];
160  element(home, ox, e, offset+n);
161  typedef Int::Offset OV;
162  OV off(-offset);
163  if (icl == ICL_DOM) {
165  ::post(home,xv,off)));
166  } else {
168  ::post(home,xv,off)));
169  }
170  }
171  }
172  void
173  path(Home home, const IntVarArgs& x, IntVar s, IntVar e,
174  IntConLevel icl) {
175  path(home,0,x,s,e,icl);
176  }
177 
178  void
179  path(Home home, const IntArgs& c, int offset,
180  const IntVarArgs& x, IntVar s, IntVar e,
181  const IntVarArgs& y, IntVar z,
182  IntConLevel icl) {
183  Int::Limits::nonnegative(offset,"Int::path");
184  int n = x.size();
185  if (n == 0)
186  throw Int::TooFewArguments("Int::path");
187  if (x.same(home))
188  throw Int::ArgumentSame("Int::path");
189  if ((y.size() != n) || (c.size() != n*n))
190  throw Int::ArgumentSizeMismatch("Int::path");
191  if (home.failed()) return;
192  path(home, offset, x, s, e, icl);
193  IntArgs cx(offset+n+1);
194  for (int i=0; i<offset; i++)
195  cx[i] = 0;
196  cx[offset+n] = 0;
197  for (int i=n; i--; ) {
198  for (int j=0; j<n; j++)
199  cx[offset+j] = c[i*n+j];
200  element(home, cx, x[i], y[i]);
201  }
202  linear(home, y, IRT_EQ, z);
203  }
204  void
205  path(Home home, const IntArgs& c,
206  const IntVarArgs& x, IntVar s, IntVar e,
207  const IntVarArgs& y, IntVar z,
208  IntConLevel icl) {
209  path(home,c,0,x,s,e,y,z,icl);
210  }
211  void
212  path(Home home, const IntArgs& c, int offset,
213  const IntVarArgs& x, IntVar s, IntVar e, IntVar z,
214  IntConLevel icl) {
215  Int::Limits::nonnegative(offset,"Int::path");
216  if (home.failed()) return;
218  path(home, c, offset, x, s, e, y, z, icl);
219  }
220  void
221  path(Home home, const IntArgs& c,
222  const IntVarArgs& x, IntVar s, IntVar e, IntVar z,
223  IntConLevel icl) {
224  path(home,c,0,x,s,e,z,icl);
225  }
226 
227 }
228 
229 // STATISTICS: int-post
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatNum c)
Post propagator for .
Definition: linear.cpp:45
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Converter without offsets.
Definition: view.hpp:585
Exception: Too few arguments available in argument array
Definition: exception.hpp:70
void nonnegative(int n, const char *l)
Check whether n is in range and nonnegative, otherwise throw out of limits with information l...
Definition: limits.hpp:72
void path(Home home, int offset, const IntVarArgs &x, IntVar s, IntVar e, IntConLevel icl)
Post propagator such that x forms a Hamiltonian path.
Definition: circuit.cpp:128
const int max
Largest allowed integer value.
Definition: int.hh:113
const int min
Smallest allowed integer value.
Definition: int.hh:115
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Equality ( )
Definition: int.hh:904
void element(Home home, IntSharedArray c, IntVar x0, IntVar x1, IntConLevel)
Post domain consistent propagator for .
Definition: element.cpp:43
"Value-consistent" circuit propagator
Definition: circuit.hh:90
Passing integer variables.
Definition: int.hh:636
Passing integer arguments.
Definition: int.hh:607
Converter with fixed offset.
Definition: view.hpp:617
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Integer variables.
Definition: int.hh:350
Exception: Arguments contain same variable multiply
Definition: exception.hpp:84
Gecode toplevel namespace
void circuit(Home home, int offset, const IntVarArgs &x, IntConLevel icl)
Post propagator such that x forms a circuit.
Definition: circuit.cpp:45
Home class for posting propagators
Definition: core.hpp:717
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
"Domain consistent" circuit propagator
Definition: circuit.hh:123
Domain propagation or consistency.
Definition: int.hh:940
bool same(const Space &home) const
Test whether array contains same variable multiply.
Definition: array.hpp:2085