Generated on Fri Mar 20 15:56:10 2015 for Gecode by doxygen 1.6.3

ldsb.hh

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <chris.mears@monash.edu>
00005  *
00006  *  Copyright:
00007  *     Christopher Mears, 2012
00008  *
00009  *  Last modified:
00010  *     $Date: 2013-05-08 13:30:48 +0200 (Wed, 08 May 2013) $ by $Author: schulte $
00011  *     $Revision: 13622 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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     // e.g. lookup[2] == 10 indicates that the variable with index 2
00239     // occurs at position 10 in the "indices" array.
00240     // If a variable occurs more than once, only the first occurrence
00241     // is recorded.
00242     // A value of -1 indicates that the variable does not occur in
00243     // "indices".
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     // Position of variable that last choice was created for
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 // STATISTICS: int-branch
00395