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 #include "gecode/set/projectors.hh"
00023
00024 namespace Gecode {
00025
00026 int
00027 Projector::arity(void) const {
00028 return _arity;
00029 }
00030
00031 void codeScope(Support::DynamicArray<int>& s, const SetExprCode& c,
00032 bool monotone) {
00033 int tmp = 0;
00034 for (int i=0; i<c.size(); i++) {
00035 switch (c[i]) {
00036 case SetExprCode::COMPLEMENT:
00037 case SetExprCode::INTER:
00038 case SetExprCode::UNION:
00039 case SetExprCode::EMPTY:
00040 case SetExprCode::UNIVERSE:
00041 break;
00042 case SetExprCode::GLB:
00043 if (s[tmp] == Set::PC_SET_ANY+1)
00044 s[tmp] = monotone ? Set::PC_SET_CGLB : Set::PC_SET_CLUB;
00045 else if (monotone && s[tmp] != Set::PC_SET_CGLB)
00046 s[tmp] = Set::PC_SET_ANY;
00047 else if (!monotone && s[tmp] != Set::PC_SET_CLUB)
00048 s[tmp] = Set::PC_SET_ANY;
00049 break;
00050 case SetExprCode::LUB:
00051 if (s[tmp] == Set::PC_SET_ANY+1)
00052 s[tmp] = monotone ? Set::PC_SET_CLUB : Set::PC_SET_CGLB;
00053 else if (monotone && s[tmp] != Set::PC_SET_CLUB)
00054 s[tmp] = Set::PC_SET_ANY;
00055 else if (!monotone && s[tmp] != Set::PC_SET_CGLB)
00056 s[tmp] = Set::PC_SET_ANY;
00057 break;
00058 default:
00059 tmp = c[i]-SetExprCode::LAST;
00060 break;
00061 }
00062 }
00063 }
00064
00065 void
00066 Projector::scope(Support::DynamicArray<int>& s) const {
00067 codeScope(s, glb, false);
00068 codeScope(s, lub, true);
00069 }
00070
00071 ExecStatus
00072 Projector::check(Space* home, ViewArray<Set::SetView>& x) {
00073 {
00074
00075 SetExprRanges glbranges(x,glb,false);
00076 Iter::Ranges::Size<SetExprRanges> g(glbranges);
00077 Set::LubRanges<Set::SetView> xir(x[i]);
00078 if (!Iter::Ranges::subset(g, xir))
00079 return ES_FAILED;
00080 while (g()) ++g;
00081 if (g.size() > x[i].cardMax()) {
00082 return ES_FAILED;
00083 }
00084 }
00085 {
00086
00087 SetExprRanges lubranges(x,lub,true);
00088 Iter::Ranges::Size<SetExprRanges> l(lubranges);
00089 Set::GlbRanges<Set::SetView> xir(x[i]);
00090 if (!Iter::Ranges::subset(xir, l))
00091 return ES_FAILED;
00092 while (l()) ++l;
00093 if (l.size() < x[i].cardMin()) {
00094 return ES_FAILED;
00095 }
00096 }
00097 {
00098
00099
00100
00101 SetExprRanges glbranges(x,glb,true);
00102 Set::GlbRanges<Set::SetView> xir(x[i]);
00103 if (!Iter::Ranges::subset(glbranges, xir)) {
00104 return ES_FIX;
00105 }
00106 }
00107 {
00108
00109
00110
00111 SetExprRanges lubranges(x,lub,false);
00112 Set::LubRanges<Set::SetView> xir(x[i]);
00113 if (!Iter::Ranges::subset(xir, lubranges)) {
00114 return ES_FIX;
00115 }
00116 }
00117
00118
00119
00120 return ES_SUBSUMED;
00121 }
00122
00123 }
00124
00125