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 #include <gecode/int/element.hh>
00035
00036 namespace Gecode {
00037
00038 void
00039 element(Home home, IntSharedArray c, IntVar x0, IntVar x1,
00040 IntPropLevel) {
00041 using namespace Int;
00042 if (c.size() == 0)
00043 throw TooFewArguments("Int::element");
00044 GECODE_POST;
00045 for (int i=0; i<c.size(); i++)
00046 Limits::check(c[i],"Int::element");
00047 GECODE_ES_FAIL((Element::post_int<IntView,IntView>(home,c,x0,x1)));
00048 }
00049
00050 void
00051 element(Home home, IntSharedArray c, IntVar x0, BoolVar x1,
00052 IntPropLevel) {
00053 using namespace Int;
00054 if (c.size() == 0)
00055 throw TooFewArguments("Int::element");
00056 GECODE_POST;
00057 for (int i=0; i<c.size(); i++)
00058 Limits::check(c[i],"Int::element");
00059 GECODE_ES_FAIL((Element::post_int<IntView,BoolView>(home,c,x0,x1)));
00060 }
00061
00062 void
00063 element(Home home, IntSharedArray c, IntVar x0, int x1,
00064 IntPropLevel) {
00065 using namespace Int;
00066 if (c.size() == 0)
00067 throw TooFewArguments("Int::element");
00068 Limits::check(x1,"Int::element");
00069 GECODE_POST;
00070 for (int i=0; i<c.size(); i++)
00071 Limits::check(c[i],"Int::element");
00072 ConstIntView cx1(x1);
00073 GECODE_ES_FAIL(
00074 (Element::post_int<IntView,ConstIntView>(home,c,x0,cx1)));
00075 }
00076
00077 void
00078 element(Home home, const IntVarArgs& c, IntVar x0, IntVar x1,
00079 IntPropLevel ipl) {
00080 using namespace Int;
00081 if (c.size() == 0)
00082 throw TooFewArguments("Int::element");
00083 GECODE_POST;
00084 IdxViewArray<IntView> iv(home,c);
00085 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
00086 GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,IntView>
00087 ::post(home,iv,x0,x1)));
00088 } else {
00089 GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,IntView>
00090 ::post(home,iv,x0,x1)));
00091 }
00092 }
00093
00094 void
00095 element(Home home, const IntVarArgs& c, IntVar x0, int x1,
00096 IntPropLevel ipl) {
00097 using namespace Int;
00098 if (c.size() == 0)
00099 throw TooFewArguments("Int::element");
00100 Limits::check(x1,"Int::element");
00101 GECODE_POST;
00102 IdxViewArray<IntView> iv(home,c);
00103 ConstIntView v1(x1);
00104 if ((vbd(ipl) == IPL_DOM) || (vbd(ipl) == IPL_DEF)) {
00105 GECODE_ES_FAIL((Element::ViewDom<IntView,IntView,ConstIntView>
00106 ::post(home,iv,x0,v1)));
00107 } else {
00108 GECODE_ES_FAIL((Element::ViewBnd<IntView,IntView,ConstIntView>
00109 ::post(home,iv,x0,v1)));
00110 }
00111 }
00112
00113 void
00114 element(Home home, const BoolVarArgs& c, IntVar x0, BoolVar x1,
00115 IntPropLevel) {
00116 using namespace Int;
00117 if (c.size() == 0)
00118 throw TooFewArguments("Int::element");
00119 GECODE_POST;
00120 IdxViewArray<BoolView> iv(home,c);
00121 GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,BoolView>
00122 ::post(home,iv,x0,x1)));
00123 }
00124
00125 void
00126 element(Home home, const BoolVarArgs& c, IntVar x0, int x1,
00127 IntPropLevel) {
00128 using namespace Int;
00129 if (c.size() == 0)
00130 throw TooFewArguments("Int::element");
00131 Limits::check(x1,"Int::element");
00132 GECODE_POST;
00133 IdxViewArray<BoolView> iv(home,c);
00134 ConstIntView v1(x1);
00135 GECODE_ES_FAIL((Element::ViewBnd<BoolView,IntView,ConstIntView>
00136 ::post(home,iv,x0,v1)));
00137 }
00138
00139 namespace {
00140 IntVar
00141 pair(Home home, IntVar x, int w, IntVar y, int h) {
00142 IntVar xy(home,0,w*h-1);
00143 if (Int::Element::Pair::post(home,x,y,xy,w,h) != ES_OK)
00144 home.fail();
00145 return xy;
00146 }
00147 }
00148
00149 void
00150 element(Home home, IntSharedArray a,
00151 IntVar x, int w, IntVar y, int h, IntVar z,
00152 IntPropLevel ipl) {
00153 using namespace Int;
00154 if (a.size() != w*h)
00155 throw Int::ArgumentSizeMismatch("Int::element");
00156 GECODE_POST;
00157 element(home, a, pair(home,x,w,y,h), z, ipl);
00158 }
00159
00160 void
00161 element(Home home, IntSharedArray a,
00162 IntVar x, int w, IntVar y, int h, BoolVar z,
00163 IntPropLevel ipl) {
00164 using namespace Int;
00165 if (a.size() != w*h)
00166 throw Int::ArgumentSizeMismatch("Int::element");
00167 GECODE_POST;
00168 element(home, a, pair(home,x,w,y,h), z, ipl);
00169 }
00170
00171 void
00172 element(Home home, const IntVarArgs& a,
00173 IntVar x, int w, IntVar y, int h, IntVar z,
00174 IntPropLevel ipl) {
00175 using namespace Int;
00176 if (a.size() != w*h)
00177 throw Int::ArgumentSizeMismatch("Int::element");
00178 GECODE_POST;
00179 element(home, a, pair(home,x,w,y,h), z, ipl);
00180 }
00181
00182 void
00183 element(Home home, const BoolVarArgs& a,
00184 IntVar x, int w, IntVar y, int h, BoolVar z,
00185 IntPropLevel ipl) {
00186 using namespace Int;
00187 if (a.size() != w*h)
00188 throw Int::ArgumentSizeMismatch("Int::element");
00189 GECODE_POST;
00190 element(home, a, pair(home,x,w,y,h), z, ipl);
00191 }
00192
00193 }
00194
00195