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 #ifndef __GECODE_INT_LDSB_HH__
00039 #define __GECODE_INT_LDSB_HH__
00040
00041 #include <gecode/int.hh>
00042
00047 namespace Gecode { namespace Int { namespace LDSB {
00048
00050 class Literal {
00051 public:
00053 Literal(void);
00055 Literal(int _var, int _val);
00056
00059 int _variable;
00063 int _value;
00064
00067 bool operator <(const Literal &rhs) const;
00068 };
00069
00081 GECODE_INT_EXPORT
00082 std::pair<int,int>
00083 findVar(int *indices, unsigned int n_values, unsigned int seq_size, int index);
00084 }}}
00085
00086 namespace Gecode {
00088 template<>
00089 class ArrayTraits<ArgArray<VarImpBase*> > {
00090 public:
00091 typedef ArgArray<VarImpBase*> StorageType;
00092 typedef VarImpBase* ValueType;
00093 typedef ArgArray<VarImpBase*> ArgsType;
00094 };
00095
00097 typedef ArgArray<Int::LDSB::Literal> LiteralArgs;
00099 template<>
00100 class ArrayTraits<LiteralArgs> {
00101 public:
00102 typedef LiteralArgs StorageType;
00103 typedef Int::LDSB::Literal ValueType;
00104 typedef LiteralArgs ArgsType;
00105 };
00106 }
00107
00108 namespace Gecode { namespace Int { namespace LDSB {
00110 class GECODE_INT_EXPORT SymmetryObject {
00111 public:
00113 int nrefs;
00115 SymmetryObject(void);
00117 virtual ~SymmetryObject(void);
00118 };
00120 class GECODE_INT_EXPORT VariableSymmetryObject : public SymmetryObject {
00121 public:
00123 VarImpBase** xs;
00125 int nxs;
00127 VariableSymmetryObject(ArgArray<VarImpBase*> vars);
00129 ~VariableSymmetryObject(void);
00130 };
00132 class GECODE_INT_EXPORT ValueSymmetryObject : public SymmetryObject {
00133 public:
00135 IntSet values;
00137 ValueSymmetryObject(IntSet vs);
00138 };
00140 class GECODE_INT_EXPORT VariableSequenceSymmetryObject : public SymmetryObject {
00141 public:
00143 VarImpBase** xs;
00145 int nxs;
00147 int seq_size;
00149 VariableSequenceSymmetryObject(ArgArray<VarImpBase*> vars, int ss);
00151 ~VariableSequenceSymmetryObject();
00152 };
00154 class GECODE_INT_EXPORT ValueSequenceSymmetryObject : public SymmetryObject {
00155 public:
00157 IntArgs values;
00159 int seq_size;
00161 ValueSequenceSymmetryObject(IntArgs vs, int ss);
00162 };
00163
00165 template<class View>
00166 class SymmetryImp {
00167 public:
00169 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const = 0;
00171 virtual void update(Literal) = 0;
00173 virtual SymmetryImp<View>* copy(Space& home, bool share) const = 0;
00175 virtual size_t dispose(Space& home) = 0;
00177 static void* operator new(size_t s, Space& home);
00179 static void operator delete(void*,Space&);
00181 static void operator delete(void*);
00182 };
00184 template <class View>
00185 class VariableSymmetryImp : public SymmetryImp<View> {
00186 protected:
00188 Support::BitSetOffset<Space> indices;
00189 public:
00191 VariableSymmetryImp<View>(Space& home, int* vs, unsigned int n);
00193 VariableSymmetryImp<View>(Space& home, const VariableSymmetryImp<View>& other);
00195 virtual size_t dispose(Space& home);
00197 void update(Literal);
00199 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00201 SymmetryImp<View>* copy(Space& home, bool share) const;
00202 };
00204 template <class View>
00205 class ValueSymmetryImp : public SymmetryImp<View>
00206 {
00207 public:
00209 Support::BitSetOffset<Space> values;
00211 ValueSymmetryImp<View>(Space& home, int* vs, unsigned int n);
00213 ValueSymmetryImp<View>(Space& home, const ValueSymmetryImp<View>& other);
00215 virtual size_t dispose(Space& home);
00217 void update(Literal);
00219 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00221 SymmetryImp<View>* copy(Space& home, bool share) const;
00222 };
00224 template <class View>
00225 class VariableSequenceSymmetryImp : public SymmetryImp<View>
00226 {
00227 protected:
00229 unsigned int *indices;
00231 unsigned int n_indices;
00233 unsigned int seq_size;
00235 unsigned int n_seqs;
00236
00238
00239
00240
00241
00242
00243
00244 int *lookup;
00246 unsigned int lookup_size;
00247
00250 int getVal(unsigned int sequence, unsigned int position) const;
00251 public:
00253 VariableSequenceSymmetryImp<View>(Space& home, int *_indices, unsigned int n, unsigned int seqsize);
00255 VariableSequenceSymmetryImp<View>(Space& home, bool share, const VariableSequenceSymmetryImp<View>& s);
00257 virtual size_t dispose(Space& home);
00259 void update(Literal);
00261 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00263 SymmetryImp<View>* copy(Space& home, bool share) const;
00264 };
00266 template <class View>
00267 class ValueSequenceSymmetryImp : public SymmetryImp<View>
00268 {
00269 protected:
00271 int *values;
00273 unsigned int n_values;
00275 unsigned int seq_size;
00277 unsigned int n_seqs;
00279 Support::BitSet<Space> dead_sequences;
00282 int getVal(unsigned int sequence, unsigned int position) const;
00283 private:
00284 ValueSequenceSymmetryImp<View>(const ValueSequenceSymmetryImp<View>&);
00285 public:
00287 ValueSequenceSymmetryImp<View>(Space& home, int* _values, unsigned int n, unsigned int seqsize);
00289 ValueSequenceSymmetryImp<View>(Space& home, const ValueSequenceSymmetryImp<View>& vss);
00291 virtual size_t dispose(Space& home);
00293 void update(Literal);
00295 virtual ArgArray<Literal> symmetric(Literal, const ViewArray<View>&) const;
00297 SymmetryImp<View>* copy(Space& home, bool share) const;
00298 };
00299
00302 template<class Val>
00303 class GECODE_VTABLE_EXPORT LDSBChoice : public PosValChoice<Val> {
00304 private:
00306 const Literal * const _literals;
00308 const int _nliterals;
00309 public:
00312 LDSBChoice(const Brancher& b, unsigned int a, const Pos& p, const Val& n,
00313 const Literal* literals, int nliterals);
00315 ~LDSBChoice(void);
00317 const Literal* literals(void) const;
00319 int nliterals(void) const;
00321 virtual size_t size(void) const;
00323 virtual void archive(Archive& e) const;
00324 };
00325
00334 template<class View, int n, class Val, unsigned int a>
00335 class LDSBBrancher : public ViewValBrancher<View,n,Val,a> {
00336 typedef typename ViewBrancher<View,n>::BranchFilter BranchFilter;
00337 public:
00339 SymmetryImp<View>** _syms;
00341 int _nsyms;
00342
00343 int _prevPos;
00344 protected:
00346 typedef void (*VarValPrint)(const Space& home, const BrancherHandle& bh,
00347 unsigned int b,
00348 typename View::VarType x, int i,
00349 const Val& m,
00350 std::ostream& o);
00352 LDSBBrancher(Space& home, bool share, LDSBBrancher& b);
00354 LDSBBrancher(Home home,
00355 ViewArray<View>& x,
00356 ViewSel<View>* vs[n],
00357 ValSelCommitBase<View,Val>* vsc,
00358 SymmetryImp<View>** syms, int nsyms,
00359 BranchFilter bf,
00360 VarValPrint vvp);
00361 public:
00363 virtual const Choice* choice(Space& home);
00365 virtual const Choice* choice(const Space& home, Archive& e);
00367 virtual ExecStatus commit(Space& home, const Choice& c, unsigned int b);
00369 virtual Actor* copy(Space& home, bool share);
00371 virtual size_t dispose(Space& home);
00373 static BrancherHandle post(Home home,
00374 ViewArray<View>& x,
00375 ViewSel<View>* vs[n],
00376 ValSelCommitBase<View,Val>* vsc,
00377 SymmetryImp<View>** syms,
00378 int nsyms,
00379 BranchFilter bf,
00380 VarValPrint vvp);
00381 };
00382
00384 template<class View>
00385 ModEvent prune(Space& home, View x, int v);
00386
00387 }}}
00388
00389 #include <gecode/int/ldsb/brancher.hpp>
00390 #include <gecode/int/ldsb/sym-imp.hpp>
00391
00392 #endif
00393
00394
00395