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
00039
00040 #ifndef __GECODE_INT_EXTENSIONAL_HH__
00041 #define __GECODE_INT_EXTENSIONAL_HH__
00042
00043 #include "gecode/int.hh"
00044
00045 #include "gecode/int/rel.hh"
00046
00052 namespace Gecode { namespace Int { namespace Extensional {
00053
00054 class Layer;
00055 class State;
00056
00071 template <class View>
00072 class LayeredGraph : public Propagator {
00073 protected:
00075 class Index : public Advisor {
00076 public:
00078 int i;
00080 Index(Space* home, Propagator* p, Council<Index>& c, int i);
00082 Index(Space* home, bool share, Index& a);
00084 void dispose(Space* home, Council<Index>& c);
00085 };
00087 class IndexRange {
00088 private:
00089 int _fst;
00090 int _lst;
00091 public:
00093 IndexRange(void);
00095 void reset(void);
00097 void add(int i);
00099 int fst(void) const;
00101 int lst(void) const;
00102 };
00104 Council<Index> c;
00106 ViewArray<View> x;
00108 DFA dfa;
00110 int start;
00112 Layer* layers;
00114 State* states;
00116 IndexRange i_ch;
00118 IndexRange o_ch;
00119
00121 bool constructed(void) const;
00123 void eliminate(void);
00125 ExecStatus construct(Space* home);
00127 ExecStatus prune(Space* home);
00128
00130 LayeredGraph(Space* home, bool share, LayeredGraph<View>& p);
00131 public:
00133 LayeredGraph(Space* home, ViewArray<View>& x, DFA& d);
00135 virtual Actor* copy(Space* home, bool share);
00137 virtual PropCost cost(ModEventDelta med) const;
00139 virtual ExecStatus advise(Space* home, Advisor* a, const Delta* d);
00141 virtual ExecStatus propagate(Space* home, ModEventDelta med);
00143 virtual Reflection::ActorSpec spec(const Space* home,
00144 Reflection::VarMap& m) const;
00146 static void post(Space* home, Reflection::VarMap& vars,
00147 const Reflection::ActorSpec& spec);
00149 static Gecode::Support::Symbol ati(void);
00151 virtual size_t dispose(Space* home);
00153 static ExecStatus post(Space* home, ViewArray<View>& x, DFA& d);
00154 };
00155
00156 }}}
00157
00158 #include "gecode/int/extensional/layered-graph.icc"
00159
00160
00161 #include "gecode/int/extensional/bitset.icc"
00162
00163 namespace Gecode { namespace Int { namespace Extensional {
00164
00165 typedef TupleSet::Tuple Tuple;
00166 typedef BitSet* Domain;
00167
00178 template <class View, bool subscribe = true>
00179 class Base : public Propagator {
00180 protected:
00181 ViewArray<View> x;
00182 TupleSet tupleSet;
00183 Tuple** last_data;
00184
00185 TupleSet::TupleSetI* ts(void);
00186
00188 Base(Space* home, bool share, Base<View,subscribe>& p);
00190 Base(Space* home, ViewArray<View>& x, const TupleSet& t);
00191
00192 void init_last(Space* home, Tuple** source);
00193 Tuple last(int var, int val);
00194 Tuple last_next(int var, int val);
00195 void init_dom(Space* home, Domain dom);
00196 bool valid(Tuple t, Domain dom);
00197 Tuple find_support(Domain dom, int var, int val);
00198
00199 public:
00200 virtual PropCost cost(ModEventDelta med) const;
00201
00202
00203 virtual size_t dispose(Space* home);
00204 };
00205 }}}
00206
00207 #include "gecode/int/extensional/base.icc"
00208
00209
00210 namespace Gecode { namespace Int { namespace Extensional {
00211
00222 template <class View>
00223 class Basic : public Base<View> {
00224 protected:
00225 using Base<View>::x;
00226 using Base<View>::tupleSet;
00227 using Base<View>::ts;
00228 using Base<View>::last;
00229 using Base<View>::last_next;
00230 using Base<View>::init_last;
00231 using Base<View>::init_dom;
00232 using Base<View>::find_support;
00233
00235 Basic(Space* home, bool share, Basic<View>& p);
00237 Basic(Space* home, ViewArray<View>& x, const TupleSet& t);
00238
00239 public:
00241 virtual ExecStatus propagate(Space* home, ModEventDelta med);
00248 virtual PropCost cost(ModEventDelta med) const;
00250 virtual Actor* copy(Space* home, bool share);
00252 static ExecStatus post(Space* home, ViewArray<View>& x, const TupleSet& t);
00253
00255 virtual Reflection::ActorSpec spec(const Space* home,
00256 Reflection::VarMap& m) const;
00258 static void post(Space* home, Reflection::VarMap& vars,
00259 const Reflection::ActorSpec& spec);
00261 static Gecode::Support::Symbol ati(void);
00262 };
00263 }}}
00264
00265 #include "gecode/int/extensional/basic.icc"
00266
00267
00268 namespace Gecode { namespace Int { namespace Extensional {
00278 template <class View>
00279 class Incremental : public Base<View, false> {
00280 protected:
00281 using Base<View, false>::x;
00282 using Base<View, false>::tupleSet;
00283 using Base<View, false>::ts;
00284 using Base<View, false>::last;
00285 using Base<View, false>::last_next;
00286 using Base<View, false>::init_last;
00287 using Base<View, false>::init_dom;
00289 class SupportEntry : public FreeList {
00290 public:
00292 Tuple t;
00294 SupportEntry* next;
00295
00297
00298
00299 SupportEntry(void);
00301 SupportEntry(Tuple t0, SupportEntry* n0 = NULL);
00303
00305
00306
00311 void dispose(Space* home, SupportEntry* l);
00313 void dispose(Space* home);
00314
00316 static void* operator new(size_t s, Space* home);
00318 static void operator delete(void*);
00320 static void operator delete(void*, Space*);
00322 };
00324 enum WorkType {
00325 WT_FIND_SUPPORT,
00326 WT_REMOVE_VALUE
00327 };
00329 class Work {
00330 public:
00331 WorkType work;
00332 int var;
00333 int val;
00334 Work(WorkType w0, int var0, int val0)
00335 : work(w0), var(var0), val(val0) {}
00336 };
00337
00338
00339
00340 typedef ::Gecode::Support::DynamicStack<Work> WorkStack;
00341 SupportEntry** support_data;
00342 WorkStack work;
00343 int unassigned;
00344
00346 Incremental(Space* home, bool share, Incremental<View>& p);
00348 Incremental(Space* home, ViewArray<View>& x, const TupleSet& t);
00349
00350 void find_support(Space* home, Domain dom, int var, int val);
00351 void init_support(Space* home);
00352 void add_support(Space* home, Tuple l);
00353 void remove_support(Space* home, Tuple l, int var, int val);
00354 SupportEntry* support(int var, int val);
00355 public:
00357 virtual ExecStatus propagate(Space* home, ModEventDelta med);
00364 virtual PropCost cost(ModEventDelta med) const;
00366 virtual Actor* copy(Space* home, bool share);
00368 static ExecStatus post(Space* home, ViewArray<View>& x, const TupleSet& t);
00369
00370 size_t dispose(Space* home);
00371
00372
00374 virtual Reflection::ActorSpec spec(const Space* home,
00375 Reflection::VarMap& m) const;
00377 static void post(Space* home, Reflection::VarMap& vars,
00378 const Reflection::ActorSpec& spec);
00380 static Gecode::Support::Symbol ati(void);
00381
00382
00383
00384
00385
00386 private:
00387 class SupportAdvisor : public ViewAdvisor<View> {
00388 public:
00389 using ViewAdvisor<View>::x;
00390 unsigned int pos;
00391 SupportAdvisor(Space* home, Propagator* p, Council<SupportAdvisor>& c,
00392 View v, unsigned int position)
00393 : ViewAdvisor<View>(home,p,c,v), pos(position) {}
00394 SupportAdvisor(Space* home, bool share, SupportAdvisor& a)
00395 : ViewAdvisor<View>(home, share, a), pos(a.pos) {
00396 }
00398 void dispose(Space* home, Council<SupportAdvisor>& c) {
00399 ViewAdvisor<View>::dispose(home,c);
00400 }
00401 };
00402 Council<SupportAdvisor> ac;
00403 public:
00404 virtual ExecStatus advise(Space* home, Advisor* a, const Delta* d);
00405 };
00406
00407 }}}
00408
00409 #include "gecode/int/extensional/incremental.icc"
00410
00411
00412 #endif
00413
00414
00415