00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <gecode/int/channel.hh>
00037
00038 namespace Gecode {
00039
00040 void
00041 channel(Home home, const IntVarArgs& x, int xoff,
00042 const IntVarArgs& y, int yoff,
00043 IntPropLevel ipl) {
00044 using namespace Int;
00045 using namespace Channel;
00046 int n = x.size();
00047 if (n != y.size())
00048 throw ArgumentSizeMismatch("Int::channel");
00049 if (same(x) || same(y))
00050 throw ArgumentSame("Int::channel");
00051 Limits::check(xoff,"Int::channel");
00052 Limits::check(yoff,"Int::channel");
00053 if ((xoff < 0) || (yoff < 0))
00054 throw OutOfLimits("Int::channel");
00055 GECODE_POST;
00056 if (n == 0)
00057 return;
00058
00059 if ((xoff < 2) && (yoff < 2) && (xoff == yoff)) {
00060 if (vbd(ipl) == IPL_DOM) {
00061 DomInfo<IntView,NoOffset<IntView> >* di =
00062 static_cast<Space&>(home).
00063 alloc<DomInfo<IntView,NoOffset<IntView> > >(2*(n+xoff));
00064 for (int i=0; i<n; i++) {
00065 di[xoff+i ].init(x[i],n+xoff);
00066 di[2*xoff+i+n].init(y[i],n+xoff);
00067 }
00068 if (xoff == 1) {
00069 IntVar x0(home,0,0);
00070 di[0].init(x0, n+xoff);
00071 IntVar y0(home,0,0);
00072 di[n+xoff].init(y0, n+xoff);
00073 }
00074 NoOffset<IntView> noff;
00075 if (same(x,y)) {
00076 GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,true>
00077 ::post(home,n+xoff,di,noff,noff)));
00078 } else {
00079 GECODE_ES_FAIL((Dom<IntView,NoOffset<IntView>,false>
00080 ::post(home,n+xoff,di,noff,noff)));
00081 }
00082 } else {
00083 ValInfo<IntView>* vi =
00084 static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*(n+xoff));
00085 for (int i=0; i<n; i++) {
00086 vi[xoff+i ].init(x[i],n+xoff);
00087 vi[2*xoff+i+n].init(y[i],n+xoff);
00088 }
00089 if (xoff == 1) {
00090 IntVar x0(home,0,0);
00091 vi[0].init(x0, n+xoff);
00092 IntVar y0(home,0,0);
00093 vi[n+xoff].init(y0, n+xoff);
00094 }
00095 NoOffset<IntView> noff;
00096 if (same(x,y)) {
00097 GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,true>
00098 ::post(home,n+xoff,vi,noff,noff)));
00099 } else {
00100 GECODE_ES_FAIL((Val<IntView,NoOffset<IntView>,false>
00101 ::post(home,n+xoff,vi,noff,noff)));
00102 }
00103 }
00104 } else {
00105 if (vbd(ipl) == IPL_DOM) {
00106 DomInfo<IntView,Offset>* di =
00107 static_cast<Space&>(home).alloc<DomInfo<IntView,Offset> >(2*n);
00108 for (int i=0; i<n; i++) {
00109 di[i ].init(x[i],n);
00110 di[i+n].init(y[i],n);
00111 }
00112 Offset ox(-xoff);
00113 Offset oy(-yoff);
00114 if (same(x,y)) {
00115 GECODE_ES_FAIL((Dom<IntView,Offset,true>
00116 ::post(home,n,di,ox,oy)));
00117 } else {
00118 GECODE_ES_FAIL((Dom<IntView,Offset,false>
00119 ::post(home,n,di,ox,oy)));
00120 }
00121 } else {
00122 ValInfo<IntView>* vi =
00123 static_cast<Space&>(home).alloc<ValInfo<IntView> >(2*n);
00124 for (int i=0; i<n; i++) {
00125 vi[i ].init(x[i],n);
00126 vi[i+n].init(y[i],n);
00127 }
00128 Offset ox(-xoff);
00129 Offset oy(-yoff);
00130 if (same(x,y)) {
00131 GECODE_ES_FAIL((Val<IntView,Offset,true>
00132 ::post(home,n,vi,ox,oy)));
00133 } else {
00134 GECODE_ES_FAIL((Val<IntView,Offset,false>
00135 ::post(home,n,vi,ox,oy)));
00136 }
00137 }
00138 }
00139
00140 }
00141
00142 void
00143 channel(Home home, const IntVarArgs& x, const IntVarArgs& y,
00144 IntPropLevel ipl) {
00145 channel(home, x, 0, y, 0, ipl);
00146 }
00147 void
00148 channel(Home home, BoolVar x0, IntVar x1, IntPropLevel) {
00149 using namespace Int;
00150 GECODE_POST;
00151 GECODE_ES_FAIL(Channel::LinkSingle::post(home,x0,x1));
00152 }
00153
00154 void
00155 channel(Home home, const BoolVarArgs& x, IntVar y, int o,
00156 IntPropLevel) {
00157 using namespace Int;
00158 if (same(x))
00159 throw ArgumentSame("Int::channel");
00160 Limits::check(o,"Int::channel");
00161 GECODE_POST;
00162 ViewArray<BoolView> xv(home,x);
00163 GECODE_ES_FAIL(Channel::LinkMulti::post(home,xv,y,o));
00164 }
00165
00166 }
00167
00168