Generated on Thu Mar 7 2013 10:21:22 for Gecode by doxygen 1.8.3.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: 2011-04-02 00:26:13 +1100 (Sat, 02 Apr 2011) $ by $Author: tack $
13  * $Revision: 11858 $
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