| 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"); |
| 55 | GECODE_POST; |
| 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)) { |
| 76 | GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,true> |
| 77 | ::post(home,n+xoff,di,noff,noff))); |
| 78 | } else { |
| 79 | GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,false> |
| 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)) { |
| 97 | GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,true> |