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 #ifndef __GECODE_INT_LDSB_HH__
00035 #define __GECODE_INT_LDSB_HH__
00036
00037 #include <gecode/int.hh>
00038
00043 namespace Gecode { namespace Int { namespace LDSB {
00044
00046 class Literal {
00047 public:
00049 Literal(void);
00051 Literal(int _var, int _val);
00052
00055 int _variable;
00059 int _value;
00060
00063 bool operator <(const Literal &rhs) const;
00064 };
00065
00077 GECODE_INT_EXPORT
00078 std::pair<int,int>
00079 findVar(int *indices, unsigned int n_values, unsigned int seq_size, int index);
00080 }}}
00081
00082 namespace Gecode {
00084 template<>
00085 class ArrayTraits<ArgArray<VarImpBase*> > {
00086 public:
00087 typedef ArgArray<VarImpBase*> StorageType;
00088 typedef VarImpBase* ValueType;
00089 typedef ArgArray<VarImpBase*> ArgsType;
00090 };
00091
00093 typedef ArgArray<Int::LDSB::Literal> LiteralArgs;
00095 template<>
00096 class ArrayTraits<LiteralArgs> {
00097 public:
00098 typedef LiteralArgs StorageType;
00099 typedef Int::LDSB::Literal ValueType;
00100 typedef LiteralArgs ArgsType;
00101 };
00102 }
00103
00104 namespace Gecode { namespace Int { namespace LDSB {
00106 class GECODE_INT_EXPORT SymmetryObject {
00107 public:
00109 int nrefs;
00111 SymmetryObject(void);
00113 virtual ~SymmetryObject(void);
00114 };
00116 class GECODE_INT_EXPORT VariableSymmetryObject : public SymmetryObject {
00117 public:
00119 VarImpBase** xs;
00121 int nxs;
00123 VariableSymmetryObject(ArgArray<VarImpBase*> vars);
00125 ~VariableSymmetryObject(void);
00126 };
00128 class GECODE_INT_EXPORT ValueSymmetryObject : public SymmetryObject {
00129 public:
00131 IntSet values;
00133 ValueSymmetryObject(IntSet vs);
00134 };
00136 class GECODE_INT_EXPORT VariableSequenceSymmetryObject : public SymmetryObject {
00137 public:
00139 VarImpBase** xs;
00141 int nxs;
00143 int seq_size;
00145 VariableSequenceSymmetryObject(ArgArray<VarImpBase*> vars, int ss);
00147 ~VariableSequenceSymmetryObject();
00148 };
00150 class GECODE_INT_EXPORT ValueSequenceSymmetryObject : public SymmetryObject {
00151 public:
00153 IntArgs values;
00155 int seq_size;
00157 ValueSequenceSymmetryObject(IntArgs vs, int ss);
00158 };
00159
00161 template<class View>
00162 class SymmetryImp {
00163 public:
00165 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const = 0;
00167 virtual void update(Literal) = 0;
00169 virtual SymmetryImp<View>* copy(Space& home) const = 0;
00171 virtual size_t dispose(Space& home) = 0;
00173 virtual ~SymmetryImp(void);
00175 static void* operator new(size_t s, Space& home);
00177 static void operator delete(void*,Space&);
00179 static void operator delete(void*);
00180 };
00182 template <class View>
00183 class VariableSymmetryImp : public SymmetryImp<View> {
00184 protected:
00186 Support::BitSetOffset<Space> indices;
00187 public:
00189 VariableSymmetryImp<View>(Space& home, int* vs, unsigned int n);
00191 VariableSymmetryImp<View>(Space& home, const VariableSymmetryImp<View>& other);
00193 virtual size_t dispose(Space& home);
00195 void update(Literal);
00197 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00199 SymmetryImp<View>* copy(Space& home) const;
00200 };
00202 template <class View>
00203 class ValueSymmetryImp : public SymmetryImp<View>
00204 {
00205 public:
00207 Support::BitSetOffset<Space> values;
00209 ValueSymmetryImp<View>(Space& home, int* vs, unsigned int n);
00211 ValueSymmetryImp<View>(Space& home, const ValueSymmetryImp<View>& other);
00213 virtual size_t dispose(Space& home);
00215 void update(Literal);
00217 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00219 SymmetryImp<View>* copy(Space& home) const;
00220 };
00222 template <class View>
00223 class VariableSequenceSymmetryImp : public SymmetryImp<View>
00224 {
00225 protected:
00227 unsigned int *indices;
00229 unsigned int n_indices;
00231 unsigned int seq_size;
00233 unsigned int n_seqs;
00234
00236
00237
00238
00239
00240
00241
00242 int *lookup;
00244 unsigned int lookup_size;
00245
00248 int getVal(unsigned int sequence, unsigned int position) const;
00249 public:
00251 VariableSequenceSymmetryImp<View>(Space& home, int *_indices, unsigned int n, unsigned int seqsize);
00253 VariableSequenceSymmetryImp<View>(Space& home, const VariableSequenceSymmetryImp<View>& s);
00255 virtual size_t dispose(Space& home);
00257 void update(Literal);
00259 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00261 SymmetryImp<View>* copy(Space& home) const;
00262 };
00264 template <class View>
00265 class ValueSequenceSymmetryImp : public SymmetryImp<View>
00266 {
00267 protected:
00269 int *values;
00271 unsigned int n_values;
00273 unsigned int seq_size;
00275 unsigned int n_seqs;
00277 Support::BitSet<Space> dead_sequences;
00280 int getVal(unsigned int sequence, unsigned int position) const;
00281 private:
00282 ValueSequenceSymmetryImp<View>(const ValueSequenceSymmetryImp<View>&);
00283 public:
00285 ValueSequenceSymmetryImp<View>(Space& home, int* _values, unsigned int n, unsigned int seqsize);
00287 ValueSequenceSymmetryImp<View>(Space& home, const ValueSequenceSymmetryImp<View>& vss);
00289 virtual size_t dispose(Space& home);
00291 void update(Literal);
00293 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00295 SymmetryImp<View>* copy(Space& home) const;
00296 };
00297
00300 template<class Val>
00301 class GECODE_VTABLE_EXPORT LDSBChoice : public PosValChoice<Val> {
00302 private:
00304 const Literal * const _literals;
00306 const int _nliterals;
00307 public:
00310 LDSBChoice(const Brancher& b, unsigned int a, const Pos& p, const Val& n,
00311 const Literal* literals, int nliterals);
00313 ~LDSBChoice(void);
00315 const Literal* literals(void) const;
00317 int nliterals(void) const;
00319 virtual void archive(Archive& e) const;
00320 };
00321
00330 template<class View, int n, class Val, unsigned int a,
00331 class Filter, class Print>
00332 class LDSBBrancher : public ViewValBrancher<View,n,Val,a,Filter,Print> {
00333 public:
00334 using typename ViewValBrancher<View,n,Val,a,Filter,Print>::Var;
00336 SymmetryImp<View>** _syms;
00338 int _nsyms;
00339
00340 int _prevPos;
00341 protected:
00343 LDSBBrancher(Space& home, LDSBBrancher& b);
00345 LDSBBrancher(Home home,
00346 ViewArray<View>& x,
00347 ViewSel<View>* vs[n],
00348 ValSelCommitBase<View,Val>* vsc,
00349 SymmetryImp<View>** syms, int nsyms,
00350 BranchFilter<Var> bf,
00351 VarValPrint<Var,Val> vvp);
00352 public:
00354 virtual const Choice* choice(Space& home);
00356 virtual const Choice* choice(const Space& home, Archive& e);
00358 virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
00360 virtual Actor* copy(Space& home);
00362 virtual size_t dispose(Space& home);
00364 static void post(Home home,
00365 ViewArray<View>& x,
00366 ViewSel<View>* vs[n],
00367 ValSelCommitBase<View,Val>* vsc,
00368 SymmetryImp<View>** syms,
00369 int nsyms,
00370 BranchFilter<Var> bf,
00371 VarValPrint<Var,Val> vvp);
00372 };
00373
00375 template<class View, int n, class Val, unsigned int a>
00376 void postldsbbrancher(Home home,
00377 ViewArray<View>& x,
00378 ViewSel<View>* vs[n],
00379 ValSelCommitBase<View,Val>* vsc,
00380 SymmetryImp<View>** syms, int nsyms,
00381 BranchFilter<typename View::VarType> bf,
00382 VarValPrint<typename View::VarType,Val> vvp);
00383
00385 template<class View>
00386 ModEvent prune(Space& home, View x, int v);
00387
00388 }}}
00389
00390 #include <gecode/int/ldsb/brancher.hpp>
00391 #include <gecode/int/ldsb/sym-imp.hpp>
00392
00393 #endif
00394
00395
00396