Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
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 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include <gecode/int/circuit.hh>
37
38namespace Gecode {
39
40 void
41 circuit(Home home, int offset, const IntVarArgs& x, IntPropLevel ipl) {
42 Int::Limits::nonnegative(offset,"Int::circuit");
43 if (x.size() == 0)
44 throw Int::TooFewArguments("Int::circuit");
45 if (same(x))
46 throw Int::ArgumentSame("Int::circuit");
49
50 if (offset == 0) {
52 NOV no;
53 if (vbd(ipl) == IPL_DOM) {
55 ::post(home,xv,no)));
56 } else {
58 ::post(home,xv,no)));
59 }
60 } else {
61 typedef Int::Offset OV;
62 OV off(-offset);
63 if (vbd(ipl) == IPL_DOM) {
65 ::post(home,xv,off)));
66 } else {
68 ::post(home,xv,off)));
69 }
70 }
71 }
72 void
73 circuit(Home home, const IntVarArgs& x, IntPropLevel ipl) {
74 circuit(home,0,x,ipl);
75 }
76
77 void
78 circuit(Home home, const IntArgs& c, int offset,
79 const IntVarArgs& x, const IntVarArgs& y, IntVar z,
80 IntPropLevel ipl) {
81 Int::Limits::nonnegative(offset,"Int::circuit");
82 int n = x.size();
83 if (n == 0)
84 throw Int::TooFewArguments("Int::circuit");
85 if (same(x))
86 throw Int::ArgumentSame("Int::circuit");
87 if ((y.size() != n) || (c.size() != n*n))
88 throw Int::ArgumentSizeMismatch("Int::circuit");
89 circuit(home, offset, x, ipl);
91 IntArgs cx(offset+n);
92 for (int i=0; i<offset; i++)
93 cx[i] = 0;
94 for (int i=0; i<n; i++) {
95 for (int j=0; j<n; j++)
96 cx[offset+j] = c[i*n+j];
97 element(home, cx, x[i], y[i]);
98 }
99 linear(home, y, IRT_EQ, z);
100 }
101 void
102 circuit(Home home, const IntArgs& c,
103 const IntVarArgs& x, const IntVarArgs& y, IntVar z,
104 IntPropLevel ipl) {
105 circuit(home,c,0,x,y,z,ipl);
106 }
107 void
108 circuit(Home home, const IntArgs& c, int offset,
109 const IntVarArgs& x, IntVar z,
110 IntPropLevel ipl) {
111 Int::Limits::nonnegative(offset,"Int::circuit");
114 circuit(home, c, offset, x, y, z, ipl);
115 }
116 void
117 circuit(Home home, const IntArgs& c,
118 const IntVarArgs& x, IntVar z,
119 IntPropLevel ipl) {
120 circuit(home,c,0,x,z,ipl);
121 }
122
123 void
124 path(Home home, int offset, const IntVarArgs& x, IntVar s, IntVar e,
125 IntPropLevel ipl) {
126 Int::Limits::nonnegative(offset,"Int::path");
127 int n=x.size();
128 if (n == 0)
129 throw Int::TooFewArguments("Int::path");
130 if (same(x))
131 throw Int::ArgumentSame("Int::path");
133 ViewArray<Int::IntView> xv(home,n+1);
134 for (int i=0; i<n; i++)
135 xv[i] = Int::IntView(x[i]);
136 xv[n] = s;
137
138 if (offset == 0) {
139 element(home, x, e, n);
140 typedef Int::NoOffset<Int::IntView> NOV;
141 NOV no;
142 if (vbd(ipl) == IPL_DOM) {
144 ::post(home,xv,no)));
145 } else {
147 ::post(home,xv,no)));
148 }
149 } else {
150 IntVarArgs ox(n+offset);
151 IntVar y(home, -1,-1);
152 for (int i=0; i<offset; i++)
153 ox[i] = y;
154 for (int i=0; i<n; i++)
155 ox[offset + i] = x[i];
156 element(home, ox, e, offset+n);
157 typedef Int::Offset OV;
158 OV off(-offset);
159 if (vbd(ipl) == IPL_DOM) {
161 ::post(home,xv,off)));
162 } else {
164 ::post(home,xv,off)));
165 }
166 }
167 }
168 void
169 path(Home home, const IntVarArgs& x, IntVar s, IntVar e,
170 IntPropLevel ipl) {
171 path(home,0,x,s,e,ipl);
172 }
173
174 void
175 path(Home home, const IntArgs& c, int offset,
176 const IntVarArgs& x, IntVar s, IntVar e,
177 const IntVarArgs& y, IntVar z,
178 IntPropLevel ipl) {
179 Int::Limits::nonnegative(offset,"Int::path");
180 int n = x.size();
181 if (n == 0)
182 throw Int::TooFewArguments("Int::path");
183 if (same(x))
184 throw Int::ArgumentSame("Int::path");
185 if ((y.size() != n) || (c.size() != n*n))
186 throw Int::ArgumentSizeMismatch("Int::path");
188 path(home, offset, x, s, e, ipl);
189 IntArgs cx(offset+n+1);
190 for (int i=0; i<offset; i++)
191 cx[i] = 0;
192 cx[offset+n] = 0;
193 for (int i=0; i<n; i++) {
194 for (int j=0; j<n; j++)
195 cx[offset+j] = c[i*n+j];
196 element(home, cx, x[i], y[i]);
197 }
198 linear(home, y, IRT_EQ, z);
199 }
200 void
201 path(Home home, const IntArgs& c,
202 const IntVarArgs& x, IntVar s, IntVar e,
203 const IntVarArgs& y, IntVar z,
204 IntPropLevel ipl) {
205 path(home,c,0,x,s,e,y,z,ipl);
206 }
207 void
208 path(Home home, const IntArgs& c, int offset,
209 const IntVarArgs& x, IntVar s, IntVar e, IntVar z,
210 IntPropLevel ipl) {
211 Int::Limits::nonnegative(offset,"Int::path");
214 path(home, c, offset, x, s, e, y, z, ipl);
215 }
216 void
217 path(Home home, const IntArgs& c,
218 const IntVarArgs& x, IntVar s, IntVar e, IntVar z,
219 IntPropLevel ipl) {
220 path(home,c,0,x,s,e,z,ipl);
221 }
222
223}
224
225// STATISTICS: int-post
FloatNum size(void) const
Return size of float value (distance between maximum and minimum)
Definition val.hpp:78
Home class for posting propagators
Definition core.hpp:856
Passing integer arguments.
Definition int.hh:634
Passing integer variables.
Definition int.hh:662
Integer variables.
Definition int.hh:371
Exception: Arguments contain same variable multiply
Definition exception.hpp:80
Exception: Arguments are of different size
Definition exception.hpp:73
"Domain consistent" circuit propagator
Definition circuit.hh:121
"Value-consistent" circuit propagator
Definition circuit.hh:88
Integer view for integer variables.
Definition view.hpp:129
Converter without offsets.
Definition view.hpp:618
Converter with fixed offset.
Definition view.hpp:650
Exception: Too few arguments available in argument array
Definition exception.hpp:66
View arrays.
Definition array.hpp:253
int offset(void) const
Integer-precision integer scale view.
Definition view.hpp:642
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition linear.cpp:41
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:989
@ IRT_EQ
Equality ( )
Definition int.hh:941
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:994
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:68
const int min
Smallest allowed integer value.
Definition int.hh:118
const int max
Largest allowed integer value.
Definition int.hh:116
Gecode toplevel namespace
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
void element(Home home, IntSharedArray n, IntVar x0, IntVar x1, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for .
Definition element.cpp:39
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition set.hh:773
void path(Home home, const IntVarArgs &x, IntVar s, IntVar e, IntPropLevel ipl=IPL_DEF)
Post propagator such that x forms a Hamiltonian path.
Definition circuit.cpp:169
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition array.hpp:1943
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
void circuit(Home home, const IntVarArgs &x, IntPropLevel ipl=IPL_DEF)
Post propagator such that x forms a circuit.
Definition circuit.cpp:73
Post propagator for SetVar x
Definition set.hh:773