projector.cc
Go to the documentation of this file.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/set/projectors.hh"
00039
00040 namespace Gecode {
00041
00042 int
00043 Projector::arity(void) const {
00044 return _arity;
00045 }
00046
00047 void codeScope(Support::DynamicArray<int>& s, const SetExprCode& c,
00048 bool monotone) {
00049 int tmp = 0;
00050 for (int i=0; i<c.size(); i++) {
00051 switch (c[i]) {
00052 case SetExprCode::COMPLEMENT:
00053 case SetExprCode::INTER:
00054 case SetExprCode::UNION:
00055 case SetExprCode::EMPTY:
00056 case SetExprCode::UNIVERSE:
00057 break;
00058 case SetExprCode::GLB:
00059 if (s[tmp] == Set::PC_SET_ANY+1)
00060 s[tmp] = monotone ? Set::PC_SET_CGLB : Set::PC_SET_CLUB;
00061 else if (monotone && s[tmp] != Set::PC_SET_CGLB)
00062 s[tmp] = Set::PC_SET_ANY;
00063 else if (!monotone && s[tmp] != Set::PC_SET_CLUB)
00064 s[tmp] = Set::PC_SET_ANY;
00065 break;
00066 case SetExprCode::LUB:
00067 if (s[tmp] == Set::PC_SET_ANY+1)
00068 s[tmp] = monotone ? Set::PC_SET_CLUB : Set::PC_SET_CGLB;
00069 else if (monotone && s[tmp] != Set::PC_SET_CLUB)
00070 s[tmp] = Set::PC_SET_ANY;
00071 else if (!monotone && s[tmp] != Set::PC_SET_CGLB)
00072 s[tmp] = Set::PC_SET_ANY;
00073 break;
00074 default:
00075 tmp = c[i]-SetExprCode::LAST;
00076 break;
00077 }
00078 }
00079 }
00080
00081 void
00082 Projector::scope(Support::DynamicArray<int>& s) const {
00083 codeScope(s, glb, false);
00084 codeScope(s, lub, true);
00085 }
00086
00087 ExecStatus
00088 Projector::check(Space*, ViewArray<Set::SetView>& x) {
00089 {
00090
00091 SetExprRanges glbranges(x,glb,false);
00092 Iter::Ranges::Size<SetExprRanges> g(glbranges);
00093 Set::LubRanges<Set::SetView> xir(x[i]);
00094 if (!Iter::Ranges::subset(g, xir))
00095 return ES_FAILED;
00096 while (g()) ++g;
00097 if (g.size() > x[i].cardMax()) {
00098 return ES_FAILED;
00099 }
00100 }
00101 {
00102
00103 SetExprRanges lubranges(x,lub,true);
00104 Iter::Ranges::Size<SetExprRanges> l(lubranges);
00105 Set::GlbRanges<Set::SetView> xir(x[i]);
00106 if (!Iter::Ranges::subset(xir, l))
00107 return ES_FAILED;
00108 while (l()) ++l;
00109 if (l.size() < x[i].cardMin()) {
00110 return ES_FAILED;
00111 }
00112 }
00113 {
00114
00115
00116
00117 SetExprRanges glbranges(x,glb,true);
00118 Set::GlbRanges<Set::SetView> xir(x[i]);
00119 if (!Iter::Ranges::subset(glbranges, xir)) {
00120 return ES_FIX;
00121 }
00122 }
00123 {
00124
00125
00126
00127 SetExprRanges lubranges(x,lub,false);
00128 Set::LubRanges<Set::SetView> xir(x[i]);
00129 if (!Iter::Ranges::subset(xir, lubranges)) {
00130 return ES_FIX;
00131 }
00132 }
00133
00134
00135
00136 return __ES_SUBSUMED;
00137 }
00138
00139 }
00140
00141 std::ostream&
00142 operator<<(std::ostream& os, const Gecode::Projector& p) {
00143 return os << p.getGlb() << " <= x[" << p.getIdx() << "] <= " << p.getLub()
00144 << std::endl;
00145 }
00146
00147