00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gecode/int/bool.hh"
00023
00024 namespace Gecode {
00025
00026 using namespace Int;
00027
00028 void
00029 bool_not(Space* home, BoolVar b0, BoolVar b1, IntConLevel) {
00030 if (home->failed()) return;
00031 NegBoolView n0(b0);
00032 GECODE_ES_FAIL(home,(Bool::Eq<NegBoolView,BoolView>::post(home,n0,b1)));
00033 }
00034
00035 void
00036 bool_eq(Space* home, BoolVar b0, BoolVar b1, IntConLevel) {
00037 if (home->failed()) return;
00038 GECODE_ES_FAIL(home,(Bool::Eq<BoolView,BoolView>::post(home,b0,b1)));
00039 }
00040
00041 void
00042 bool_and(Space* home, BoolVar b0, BoolVar b1, BoolVar b2, IntConLevel) {
00043 if (home->failed()) return;
00044 NegBoolView n0(b0); NegBoolView n1(b1); NegBoolView n2(b2);
00045 GECODE_ES_FAIL(home,(Bool::Or<NegBoolView,NegBoolView,NegBoolView>
00046 ::post(home,n0,n1,n2)));
00047 }
00048 void
00049 bool_and(Space* home, BoolVar b0, BoolVar b1, bool b2, IntConLevel) {
00050 if (home->failed()) return;
00051 if (b2) {
00052 BoolView bv0(b0); BoolView bv1(b1);
00053 GECODE_ME_FAIL(home,bv0.t_one(home));
00054 GECODE_ME_FAIL(home,bv1.t_one(home));
00055 } else {
00056 NegBoolView n0(b0); NegBoolView n1(b1);
00057 GECODE_ES_FAIL(home,(Bool::OrTrue<NegBoolView,NegBoolView>
00058 ::post(home,n0,n1)));
00059 }
00060 }
00061 void
00062 bool_and(Space* home, const BoolVarArgs& b, BoolVar c, IntConLevel) {
00063 if (home->failed()) return;
00064 ViewArray<NegBoolView> x(home,b.size());
00065 for (int i=b.size(); i--; ) {
00066 NegBoolView nb(b[i]); x[i]=nb;
00067 }
00068 NegBoolView nc(c);
00069 GECODE_ES_FAIL(home,Bool::NaryOr<NegBoolView>::post(home,x,nc));
00070 }
00071 void
00072 bool_and(Space* home, const BoolVarArgs& b, bool c, IntConLevel) {
00073 if (home->failed()) return;
00074 if (c) {
00075 for (int i=b.size(); i--; ) {
00076 BoolView bvi(b[i]); GECODE_ME_FAIL(home,bvi.t_one(home));
00077 }
00078 } else {
00079 ViewArray<NegBoolView> x(home,b.size());
00080 for (int i=b.size(); i--; ) {
00081 NegBoolView nb(b[i]); x[i]=nb;
00082 }
00083 GECODE_ES_FAIL(home,Bool::NaryOrTrue<NegBoolView>::post(home,x));
00084 }
00085 }
00086
00087 void
00088 bool_or(Space* home, BoolVar b0, BoolVar b1, BoolVar b2, IntConLevel) {
00089 if (home->failed()) return;
00090 GECODE_ES_FAIL(home,
00091 (Bool::Or<BoolView,BoolView,BoolView>
00092 ::post(home,b0,b1,b2)));
00093 }
00094 void
00095 bool_or(Space* home, BoolVar b0, BoolVar b1, bool b2, IntConLevel) {
00096 if (home->failed()) return;
00097 if (b2) {
00098 GECODE_ES_FAIL(home,
00099 (Bool::OrTrue<BoolView,BoolView>::post(home,b0,b1)));
00100 } else {
00101 BoolView bv0(b0);
00102 BoolView bv1(b1);
00103 GECODE_ME_FAIL(home,bv0.t_zero(home));
00104 GECODE_ME_FAIL(home,bv1.t_zero(home));
00105 }
00106 }
00107 void
00108 bool_or(Space* home, const BoolVarArgs& b, BoolVar c, IntConLevel) {
00109 if (home->failed()) return;
00110 ViewArray<BoolView> x(home,b);
00111 GECODE_ES_FAIL(home,Bool::NaryOr<BoolView>::post(home,x,c));
00112 }
00113 void
00114 bool_or(Space* home, const BoolVarArgs& b, bool c, IntConLevel) {
00115 if (home->failed()) return;
00116 if (c) {
00117 ViewArray<BoolView> x(home,b);
00118 GECODE_ES_FAIL(home,Bool::NaryOrTrue<BoolView>::post(home,x));
00119 } else {
00120 for (int i=b.size(); i--; ) {
00121 BoolView bvi(b[i]);
00122 GECODE_ME_FAIL(home,bvi.t_zero(home));
00123 }
00124 }
00125 }
00126
00127 void
00128 bool_imp(Space* home, BoolVar b0, BoolVar b1, BoolVar b2, IntConLevel) {
00129 if (home->failed()) return;
00130 NegBoolView n0(b0);
00131 GECODE_ME_FAIL(home,(Bool::Or<NegBoolView,BoolView,BoolView>
00132 ::post(home,n0,b1,b2)));
00133 }
00134 void
00135 bool_imp(Space* home, BoolVar b0, BoolVar b1, bool b2, IntConLevel) {
00136 if (home->failed()) return;
00137 if (b2) {
00138 NegBoolView n0(b0);
00139 GECODE_ME_FAIL(home,(Bool::OrTrue<NegBoolView,BoolView>
00140 ::post(home,n0,b1)));
00141 } else {
00142 BoolView bv0(b0); BoolView bv1(b1);
00143 GECODE_ME_FAIL(home,bv0.t_one(home));
00144 GECODE_ME_FAIL(home,bv1.t_zero(home));
00145 }
00146 }
00147
00148 void
00149 bool_eqv(Space* home, BoolVar b0, BoolVar b1, BoolVar b2, IntConLevel) {
00150 if (home->failed()) return;
00151 GECODE_ES_FAIL(home,(Bool::Eqv<BoolView,BoolView,BoolView>
00152 ::post(home,b0,b1,b2)));
00153 }
00154 void
00155 bool_eqv(Space* home, BoolVar b0, BoolVar b1, bool b2, IntConLevel) {
00156 if (home->failed()) return;
00157 if (b2) {
00158 GECODE_ES_FAIL(home,(Bool::Eq<BoolView,BoolView>::post(home,b0,b1)));
00159 } else {
00160 NegBoolView n0(b0);
00161 GECODE_ES_FAIL(home,(Bool::Eq<NegBoolView,BoolView>::post(home,n0,b1)));
00162 }
00163 }
00164
00165 void
00166 bool_xor(Space* home, BoolVar b0, BoolVar b1, BoolVar b2, IntConLevel) {
00167 if (home->failed()) return;
00168 NegBoolView n2(b2);
00169 GECODE_ES_FAIL(home,(Bool::Eqv<BoolView,BoolView,NegBoolView>
00170 ::post(home,b0,b1,n2)));
00171 }
00172 void
00173 bool_xor(Space* home, BoolVar b0, BoolVar b1, bool b2, IntConLevel) {
00174 if (home->failed()) return;
00175 if (b2) {
00176 NegBoolView n0(b0);
00177 GECODE_ES_FAIL(home,(Bool::Eq<NegBoolView,BoolView>::post(home,n0,b1)));
00178 } else {
00179 GECODE_ES_FAIL(home,(Bool::Eq<BoolView,BoolView>::post(home,b0,b1)));
00180 }
00181 }
00182
00183 }
00184
00185
00186
00187