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