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
00068 template <class View, class Degree, class StateIdx>
00069 class LayeredGraph : public Propagator {
00070 protected:
00072 class State {
00073 public:
00074 Degree i_deg;
00075 Degree o_deg;
00076 };
00078 class Edge {
00079 public:
00080 StateIdx i_state;
00081 StateIdx o_state;
00082 Edge* next;
00083
00084 Edge(StateIdx i, StateIdx o, Edge* n);
00086 static void operator delete(void* p, size_t s);
00088 static void operator delete(void* p, Space& home);
00090 static void* operator new(size_t s, Space& home);
00091 };
00093 class Support {
00094 public:
00095 int val;
00096 Edge* edges;
00097 };
00099 class Layer {
00100 public:
00101 unsigned int size;
00102 Support* support;
00103 };
00105 class LayerValues {
00106 private:
00107 const Support* s1;
00108 const Support* s2;
00109 public:
00111 LayerValues(void);
00113 LayerValues(const Layer& l);
00115 void init(const Layer& l);
00117 bool operator ()(void) const;
00119 void operator ++(void);
00121 int val(void) const;
00122 };
00124 class Index : public Advisor {
00125 public:
00127 StateIdx i;
00129 Index(Space& home, Propagator& p, Council<Index>& c, StateIdx i);
00131 Index(Space& home, bool share, Index& a);
00132 };
00134 class IndexRange {
00135 private:
00136 int _fst;
00137 int _lst;
00138 public:
00140 IndexRange(void);
00142 void reset(void);
00144 void add(int i);
00146 int fst(void) const;
00148 int lst(void) const;
00149 };
00151 Council<Index> c;
00153 ViewArray<View> x;
00155 DFA dfa;
00157 StateIdx start;
00159 Layer* layers;
00161 State* states;
00163 IndexRange i_ch;
00165 IndexRange o_ch;
00166
00168 bool constructed(void) const;
00170 void eliminate(void);
00172 ExecStatus construct(Space& home);
00174 ExecStatus prune(Space& home);
00175
00177 LayeredGraph(Space& home, bool share,
00178 LayeredGraph<View,Degree,StateIdx>& p);
00179 public:
00181 LayeredGraph(Space& home, ViewArray<View>& x, DFA& d);
00183 virtual Actor* copy(Space& home, bool share);
00185 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00187 virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00189 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00191 virtual size_t dispose(Space& home);
00193 static ExecStatus post(Space& home, ViewArray<View>& x, DFA& d);
00194 };
00195
00197 template <class View>
00198 ExecStatus post_lgp(Space& home, ViewArray<View>& x, DFA dfa);
00199
00200 }}}
00201
00202 #include <gecode/int/extensional/layered-graph.hpp>
00203
00204
00205 #include <gecode/int/extensional/bitset.hpp>
00206
00207 namespace Gecode { namespace Int { namespace Extensional {
00208
00209 typedef TupleSet::Tuple Tuple;
00210 typedef BitSet* Domain;
00211
00222 template <class View, bool subscribe = true>
00223 class Base : public Propagator {
00224 protected:
00225 ViewArray<View> x;
00226 TupleSet tupleSet;
00227 Tuple** last_data;
00228
00229 TupleSet::TupleSetI* ts(void);
00230
00232 Base(Space& home, bool share, Base<View,subscribe>& p);
00234 Base(Space& home, ViewArray<View>& x, const TupleSet& t);
00236 void init_last(Space& home, Tuple** source);
00238 Tuple last(int i, int n);
00240 Tuple last_next(int i, int n);
00242 void init_dom(Space& home, Domain dom);
00244 bool valid(Tuple t, Domain dom);
00246 Tuple find_support(Domain dom, int i, int n);
00247 public:
00249 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00251 virtual size_t dispose(Space& home);
00252 };
00253 }}}
00254
00255 #include <gecode/int/extensional/base.hpp>
00256
00257
00258 namespace Gecode { namespace Int { namespace Extensional {
00259
00272 template <class View, bool shared>
00273 class Basic : public Base<View> {
00274 protected:
00275 using Base<View>::x;
00276 using Base<View>::tupleSet;
00277 using Base<View>::ts;
00278 using Base<View>::last;
00279 using Base<View>::last_next;
00280 using Base<View>::init_last;
00281 using Base<View>::init_dom;
00282 using Base<View>::find_support;
00283
00285 Basic(Space& home, bool share, Basic<View,shared>& p);
00287 Basic(Space& home, ViewArray<View>& x, const TupleSet& t);
00288
00289 public:
00291 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00298 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00300 virtual Actor* copy(Space& home, bool share);
00302 static ExecStatus post(Space& home, ViewArray<View>& x, const TupleSet& t);
00303 };
00304
00305 }}}
00306
00307 #include <gecode/int/extensional/basic.hpp>
00308
00309
00310 namespace Gecode { namespace Int { namespace Extensional {
00320 template <class View>
00321 class Incremental : public Base<View, false> {
00322 protected:
00323 using Base<View, false>::x;
00324 using Base<View, false>::tupleSet;
00325 using Base<View, false>::ts;
00326 using Base<View, false>::last;
00327 using Base<View, false>::last_next;
00328 using Base<View, false>::init_last;
00329 using Base<View, false>::init_dom;
00331 class SupportEntry : public FreeList {
00332 public:
00334 Tuple t;
00335
00337
00338
00339 SupportEntry* next(void) const;
00341 SupportEntry** nextRef(void);
00343
00345
00346
00347 SupportEntry(Tuple t);
00349 SupportEntry(Tuple t, SupportEntry* n);
00351
00353
00354
00355 void dispose(Space& home, SupportEntry* l);
00357 void dispose(Space& home);
00358
00360 static void* operator new(size_t s, Space& home);
00362 static void operator delete(void* p);
00364 static void operator delete(void* p, Space& home);
00366 };
00368 class WorkEntry : public FreeList {
00369 public:
00371 int i;
00373 int n;
00374
00376
00377
00378 WorkEntry(int i, int n, WorkEntry* ne);
00380
00382
00383
00384 WorkEntry* next(void) const;
00386 void next(WorkEntry* n);
00388
00390
00391
00392 void dispose(Space& home);
00393
00395 static void* operator new(size_t s, Space& home);
00397 static void operator delete(void* p);
00399 static void operator delete(void* p, Space& home);
00401 };
00403 class Work {
00404 private:
00406 WorkEntry* we;
00407 public:
00409 Work(void);
00411 bool empty(void) const;
00413 void push(Space& home, int i, int n);
00415 void pop(Space& home, int& i, int& n);
00416 };
00418 Work w_support;
00420 Work w_remove;
00421
00423 SupportEntry** support_data;
00425 int unassigned;
00426
00428 Incremental(Space& home, bool share, Incremental<View>& p);
00430 Incremental(Space& home, ViewArray<View>& x, const TupleSet& t);
00432 void init_support(Space& home);
00434 void find_support(Space& home, Domain dom, int i, int n);
00436 void add_support(Space& home, Tuple l);
00438 void remove_support(Space& home, Tuple l, int i, int n);
00440 SupportEntry* support(int i, int n);
00441 public:
00443 virtual ExecStatus propagate(Space& home, const ModEventDelta& med);
00450 virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
00452 virtual Actor* copy(Space& home, bool share);
00454 static ExecStatus post(Space& home, ViewArray<View>& x, const TupleSet& t);
00456 size_t dispose(Space& home);
00457 private:
00459 class SupportAdvisor : public Advisor {
00460 public:
00462 int i;
00464 SupportAdvisor(Space& home, Propagator& p, Council<SupportAdvisor>& c,
00465 int i);
00467 SupportAdvisor(Space& home, bool share, SupportAdvisor& a);
00469 void dispose(Space& home, Council<SupportAdvisor>& c);
00470 };
00472 Council<SupportAdvisor> ac;
00473 public:
00475 virtual ExecStatus advise(Space& home, Advisor& a, const Delta& d);
00476 };
00477
00478 }}}
00479
00480 #include <gecode/int/extensional/incremental.hpp>
00481
00482
00483 #endif
00484
00485
00486