Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
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 
38 namespace 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  }
74  NoOffset<IntView> noff;
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  }
95  NoOffset<IntView> noff;
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)) {
115  GECODE_ES_FAIL((Dom<IntView,Offset,true>
116  ::post(home,n,di,ox,oy)));
117  } else {
118  GECODE_ES_FAIL((Dom<IntView,Offset,false>
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)) {
131  GECODE_ES_FAIL((Val<IntView,Offset,true>
132  ::post(home,n,vi,ox,oy)));
133  } else {
134  GECODE_ES_FAIL((Val<IntView,Offset,false>
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;
150  GECODE_POST;
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");
161  GECODE_POST;
162  ViewArray<BoolView> xv(home,x);
164  }
165 
166 }
167 
168 // STATISTICS: int-post
Post propagator for SetVar x
Definition: set.hh:767
Exception: Arguments are of different size
Definition: exception.hpp:73
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:103
Converter with fixed offset.
Definition: view.hpp:650
Passing integer variables.
Definition: int.hh:656
static ExecStatus post(Home home, BoolView x0, IntView x1)
Post propagator for .
Definition: link-single.hpp:42
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
IntPropLevel
Propagation levels for integer propagators.
Definition: int.hh:974
Computation spaces.
Definition: core.hpp:1742
static ExecStatus post(Home home, ViewArray< BoolView > &x, IntView y, int o)
Post propagator for .
Definition: link-multi.hpp:53
Gecode toplevel namespace
IntPropLevel vbd(IntPropLevel ipl)
Extract value, bounds, or domain propagation from propagation level.
Definition: ipl.hpp:37
Exception: Arguments contain same variable multiply
Definition: exception.hpp:80
Converter without offsets.
Definition: view.hpp:618
Passing Boolean variables.
Definition: int.hh:712
Home class for posting propagators
Definition: core.hpp:856
Boolean integer variables.
Definition: int.hh:512
@ IPL_DOM
Domain propagation Options: basic versus advanced propagation.
Definition: int.hh:979
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition: filter.cpp:138
Integer variables.
Definition: int.hh:371
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: channel.cpp:41
#define GECODE_POST
Check for failure in a constraint post function.
Definition: macros.hpp:40
Integer view for integer variables.
Definition: view.hpp:129
bool same(VarArgArray< Var > x, VarArgArray< Var > y)
Definition: array.hpp:1937
Exception: Value out of limits
Definition: exception.hpp:44
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Gecode::IntArgs i({1, 2, 3, 4})