Generated on Sat Feb 7 2015 02:01:20 for Gecode by doxygen 1.8.9.1
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  * 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/channel.hh>
41 
42 namespace Gecode {
43 
44  void
45  channel(Home home, const IntVarArgs& x, int xoff,
46  const IntVarArgs& y, int yoff,
47  IntConLevel icl) {
48  using namespace Int;
49  using namespace Channel;
50  int n = x.size();
51  if (n != y.size())
52  throw ArgumentSizeMismatch("Int::channel");
53  if (x.same(home) || y.same(home))
54  throw ArgumentSame("Int::channel");
55  Limits::check(xoff,"Int::channel");
56  Limits::check(yoff,"Int::channel");
57  if ((xoff < 0) || (yoff < 0))
58  throw OutOfLimits("Int::channel");
59  if (home.failed()) return;
60  if (n == 0)
61  return;
62 
63  if ((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
64  if (icl == ICL_DOM) {
65  DomInfo<IntView,NoOffset<IntView> >* di =
66  static_cast<Space&>(home).
67  alloc<DomInfo<IntView,NoOffset<IntView> > >(2*(n+xoff));
68  for (int i=n; i--; ) {
69  di[xoff+i ].init(x[i],n+xoff);
70  di[2*xoff+i+n].init(y[i],n+xoff);
71  }
72  if (xoff == 1) {
73  IntVar x0(home,0,0);
74  di[0].init(x0, n+xoff);
75  IntVar y0(home,0,0);
76  di[n+xoff].init(y0, n+xoff);
77  }
78  NoOffset<IntView> noff;
79  if (x.same(home,y)) {
81  ::post(home,n+xoff,di,noff,noff)));
82  } else {
84  ::post(home,n+xoff,di,noff,noff)));
85  }
86  } else {
87  ValInfo<IntView>* vi =
88  static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*(n+xoff));
89  for (int i=n; i--; ) {
90  vi[xoff+i ].init(x[i],n+xoff);
91  vi[2*xoff+i+n].init(y[i],n+xoff);
92  }
93  if (xoff == 1) {
94  IntVar x0(home,0,0);
95  vi[0].init(x0, n+xoff);
96  IntVar y0(home,0,0);
97  vi[n+xoff].init(y0, n+xoff);
98  }
99  NoOffset<IntView> noff;
100  if (x.same(home,y)) {
102  ::post(home,n+xoff,vi,noff,noff)));
103  } else {
105  ::post(home,n+xoff,vi,noff,noff)));
106  }
107  }
108  } else {
109  if (icl == ICL_DOM) {
110  DomInfo<IntView,Offset>* di =
111  static_cast<Space&>(home).alloc<DomInfo<IntView,Offset> >(2*n);
112  for (int i=n; i--; ) {
113  di[i ].init(x[i],n);
114  di[i+n].init(y[i],n);
115  }
116  Offset ox(-xoff);
117  Offset oy(-yoff);
118  if (x.same(home,y)) {
119  GECODE_ES_FAIL((Dom<IntView,Offset,true>
120  ::post(home,n,di,ox,oy)));
121  } else {
122  GECODE_ES_FAIL((Dom<IntView,Offset,false>
123  ::post(home,n,di,ox,oy)));
124  }
125  } else {
126  ValInfo<IntView>* vi =
127  static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*n);
128  for (int i=n; i--; ) {
129  vi[i ].init(x[i],n);
130  vi[i+n].init(y[i],n);
131  }
132  Offset ox(-xoff);
133  Offset oy(-yoff);
134  if (x.same(home,y)) {
135  GECODE_ES_FAIL((Val<IntView,Offset,true>
136  ::post(home,n,vi,ox,oy)));
137  } else {
138  GECODE_ES_FAIL((Val<IntView,Offset,false>
139  ::post(home,n,vi,ox,oy)));
140  }
141  }
142  }
143 
144  }
145 
146  void
147  channel(Home home, const IntVarArgs& x, const IntVarArgs& y,
148  IntConLevel icl) {
149  channel(home, x, 0, y, 0, icl);
150  }
151  void
153  using namespace Int;
154  if (home.failed()) return;
156  }
157 
158  void
159  channel(Home home, const BoolVarArgs& x, IntVar y, int o,
160  IntConLevel) {
161  using namespace Int;
162  if (x.same(home))
163  throw ArgumentSame("Int::channel");
164  Limits::check(o,"Int::channel");
165  if (home.failed()) return;
166  ViewArray<BoolView> xv(home,x);
168  }
169 
170 }
171 
172 // 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
Exception: Value out of limits
Definition: exception.hpp:48
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
static ExecStatus post(Home home, BoolView x0, IntView x1)
Post propagator for .
Definition: link-single.hpp:46
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition: arithmetic.cpp:218
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
Converter without offsets.
Definition: view.hpp:585
Computation spaces.
Definition: core.hpp:1362
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Passing integer variables.
Definition: int.hh:636
static ExecStatus post(Home home, ViewArray< BoolView > &x, IntView y, int o)
Post propagator for .
Definition: link-multi.hpp:49
Passing Boolean variables.
Definition: int.hh:690
Converter with fixed offset.
Definition: view.hpp:617
Boolean integer variables.
Definition: int.hh:491
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 check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
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 propagation or consistency.
Definition: int.hh:940
bool same(const Space &home) const
Test whether array contains same variable multiply.
Definition: array.hpp:2085