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