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