Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
channel.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/channel.hh>
37
38namespace Gecode {
39
40 void
41 channel(Home home, const IntVarArgs& x, int xoff,
42 const IntVarArgs& y, int yoff,
43 IntPropLevel ipl) {
44 using namespace Int;
45 using namespace Channel;
46 int n = x.size();
47 if (n != y.size())
48 throw ArgumentSizeMismatch("Int::channel");
49 if (same(x) || same(y))
50 throw ArgumentSame("Int::channel");
51 Limits::check(xoff,"Int::channel");
52 Limits::check(yoff,"Int::channel");
53 if ((xoff < 0) || (yoff < 0))
54 throw OutOfLimits("Int::channel");
56 if (n == 0)
57 return;
58
59 if ((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
60 if (vbd(ipl) == IPL_DOM) {
61 DomInfo<IntView,NoOffset<IntView> >* di =
62 static_cast<Space&>(home).
63 alloc<DomInfo<IntView,NoOffset<IntView> > >(2*(n+xoff));
64 for (int i=0; i<n; i++) {
65 di[xoff+i ].init(x[i],n+xoff);
66 di[2*xoff+i+n].init(y[i],n+xoff);
67 }
68 if (xoff == 1) {
69 IntVar x0(home,0,0);
70 di[0].init(x0, n+xoff);
71 IntVar y0(home,0,0);
72 di[n+xoff].init(y0, n+xoff);
73 }
75 if (same(x,y)) {
77 ::post(home,n+xoff,di,noff,noff)));
78 } else {
80 ::post(home,n+xoff,di,noff,noff)));
81 }
82 } else {
83 ValInfo<IntView>* vi =
84 static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*(n+xoff));
85 for (int i=0; i<n; i++) {
86 vi[xoff+i ].init(x[i],n+xoff);
87 vi[2*xoff+i+n].init(y[i],n+xoff);
88 }
89 if (xoff == 1) {
90 IntVar x0(home,0,0);
91 vi[0].init(x0, n+xoff);
92 IntVar y0(home,0,0);
93 vi[n+xoff].init(y0, n+xoff);
94 }
96 if (same(x,y)) {
98 ::post(home,n+xoff,vi,noff,noff)));
99 } else {
101 ::post(home,n+xoff,vi,noff,noff)));
102 }
103 }
104 } else {
105 if (vbd(ipl) == IPL_DOM) {
106 DomInfo<IntView,Offset>* di =
107 static_cast<Space&>(home).alloc<DomInfo<IntView,Offset> >(2*n);
108 for (int i=0; i<n; i++) {
109 di[i ].init(x[i],n);
110 di[i+n].init(y[i],n);
111 }
112 Offset ox(-xoff);
113 Offset oy(-yoff);
114 if (same(x,y)) {
116 ::post(home,n,di,ox,oy)));
117 } else {
119 ::post(home,n,di,ox,oy)));
120 }
121 } else {
122 ValInfo<IntView>* vi =
123 static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*n);
124 for (int i=0; i<n; i++) {
125 vi[i ].init(x[i],n);
126 vi[i+n].init(y[i],n);
127 }
128 Offset ox(-xoff);
129 Offset oy(-yoff);
130 if (same(x,y)) {
132 ::post(home,n,vi,ox,oy)));
133 } else {
135 ::post(home,n,vi,ox,oy)));
136 }
137 }
138 }
139
140 }
141
142 void
143 channel(Home home, const IntVarArgs& x, const IntVarArgs& y,
144 IntPropLevel ipl) {
145 channel(home, x, 0, y, 0, ipl);
146 }
147 void
149 using namespace Int;
152 }
153
154 void
155 channel(Home home, const BoolVarArgs& x, IntVar y, int o,
156 IntPropLevel) {
157 using namespace Int;
158 if (same(x))
159 throw ArgumentSame("Int::channel");
160 Limits::check(o,"Int::channel");
162 ViewArray<BoolView> xv(home,x);
164 }
165
166}
167
168// STATISTICS: int-post
Passing Boolean variables.
Definition int.hh:721
Boolean integer variables.
Definition int.hh:515
Home class for posting propagators
Definition core.hpp:856
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
static ExecStatus post(Home home, ViewArray< BoolView > &x, IntView y, int o)
Post propagator for .
static ExecStatus post(Home home, BoolView x0, IntView x1)
Post propagator for .
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: Value out of limits
Definition exception.hpp:44
Computation spaces.
Definition core.hpp:1744
View arrays.
Definition array.hpp:253
#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
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:989
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition int.hh:994
Channel propagators
Domain propagators.
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition limits.hpp:46
Finite domain integers.
Gecode toplevel namespace
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition channel.cpp:41
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition ipl.hpp:37
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
Post propagator for SetVar x
Definition set.hh:773