nary.icc
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 namespace Gecode { namespace Set { namespace Projection {
00039
00040 template <bool negated>
00041 forceinline
00042 NaryProjection<negated>::NaryProjection
00043 (Space* home, ViewArray<SetView>& x0, ProjectorSet& ps0)
00044 : Propagator(home), x(x0), pc(x.size()), ps(ps0) {
00045 force(home);
00046 Support::DynamicArray<int> scope;
00047 ps.scope(scope, x.size());
00048 for (int i=x.size(); i--;) {
00049 pc[i] = scope[i];
00050 if (pc[i] != PC_SET_ANY + 1) {
00051 if (negated)
00052 pc[i] = ComplementView<SetView>::pc_negateset(pc[i]);
00053 x[i].subscribe(home, this, pc[i]);
00054 }
00055 }
00056 }
00057
00058 template <bool negated>
00059 forceinline
00060 NaryProjection<negated>::NaryProjection
00061 (Space* home, bool share, NaryProjection& p)
00062 : Propagator(home,share,p) {
00063 x.update(home,share,p.x);
00064 pc.update(home, share, p.pc);
00065 ps.update(home, share, p.ps);
00066 }
00067
00068 template <bool negated>
00069 PropCost
00070 NaryProjection<negated>::cost(ModEventDelta) const {
00071 switch (x.size()) {
00072 case 1: return PC_UNARY_HI;
00073 case 2: return PC_BINARY_HI;
00074 case 3: return PC_TERNARY_HI;
00075 default: return PC_LINEAR_HI;
00076 }
00077 }
00078
00079 template <bool negated>
00080 Support::Symbol
00081 NaryProjection<negated>::ati(void) {
00082 if (negated)
00083 return Support::Symbol("set.projectors.NaryProjection<true>");
00084 else
00085 return Support::Symbol("set.projectors.NaryProjection<false>");
00086 }
00087
00088 template <bool negated>
00089 Reflection::ActorSpec
00090 NaryProjection<negated>::spec(const Space*, Reflection::VarMap&) const {
00091 throw Reflection::ReflectionException("Not implemented");
00092 }
00093
00094 template <bool negated>
00095 size_t
00096 NaryProjection<negated>::dispose(Space* home) {
00097 unforce(home);
00098 if (!home->failed()) {
00099 for (int i=x.size(); i--;)
00100 if (pc[i] != PC_SET_ANY + 1)
00101 x[i].cancel(home, this, pc[i]);
00102 }
00103 ps.~ProjectorSet();
00104 pc.~SharedArray();
00105 (void) Propagator::dispose(home);
00106 return sizeof(*this);
00107 }
00108
00109 template <bool negated>
00110 ExecStatus
00111 NaryProjection<negated>::post(Space* home,
00112 ViewArray<SetView>& x, ProjectorSet& ps) {
00113 if (ps.arity() != x.size()-1) {
00114 throw Set::InvalidProjector("");
00115 }
00116 (void) new (home) NaryProjection<negated>(home,x,ps);
00117 return ES_OK;
00118 }
00119
00120 template <bool negated>
00121 Actor*
00122 NaryProjection<negated>::copy(Space* home, bool share) {
00123 return new (home) NaryProjection<negated>(home,share,*this);
00124 }
00125
00126 template <bool negated>
00127 ExecStatus
00128 NaryProjection<negated>::propagate(Space* home, ModEventDelta) {
00129 bool done = true;
00130 for (int i=x.size(); i--;)
00131 if (!x[i].assigned()) {
00132 done = false; break;
00133 }
00134 ExecStatus es = ps.propagate<negated>(home, x);
00135 if (es == ES_FAILED)
00136 return ES_FAILED;
00137 if (es == __ES_SUBSUMED)
00138 return ES_SUBSUMED(this,home);
00139 return done ? ES_SUBSUMED(this,home) : es;
00140 }
00141
00142 }}}
00143
00144