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