Generated on Sun Feb 17 15:24:25 2019 for Gecode by doxygen 1.6.3

val-sel-commit.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main author:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2012
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode {
00035 
00042 
00043   template<class _View, class _Val>
00044   class ValSelCommitBase {
00045   public:
00047     typedef _View View;
00049     typedef typename View::VarType Var;
00051     typedef _Val Val;
00052   public:
00054     ValSelCommitBase(Space& home, const ValBranch<Var>& vb);
00056     ValSelCommitBase(Space& home, ValSelCommitBase<View,Val>& vsc);
00058     virtual Val val(const Space& home, View x, int i) = 0;
00060     virtual ModEvent commit(Space& home, unsigned int a,
00061                             View x, int i, Val n) = 0;
00063     virtual NGL* ngl(Space& home, unsigned int a,
00064                      View x, Val n) const = 0;
00066     virtual void print(const Space& home, unsigned int a,
00067                        View x, int i, const Val& n,
00068                        std::ostream& o) const = 0;
00070     virtual ValSelCommitBase<View,Val>* copy(Space& home) = 0;
00072     virtual bool notice(void) const = 0;
00074     virtual void dispose(Space& home) = 0;
00076     virtual ~ValSelCommitBase(void);
00078 
00079 
00080     static void* operator new(size_t s, Space& home);
00082     static void operator delete(void* p, Space& home);
00084     static void operator delete(void* p);
00086   };
00087 
00089   template<class ValSel, class ValCommit>
00090   class ValSelCommit
00091     : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
00092   protected:
00093     typedef typename ValSelCommitBase<typename ValSel::View,
00094                                       typename ValSel::Val>::Var Var;
00095     typedef typename ValSelCommitBase<typename ValSel::View,
00096                                       typename ValSel::Val>::Val Val;
00097     typedef typename ValSelCommitBase<typename ValSel::View,
00098                                       typename ValSel::Val>::View View;
00100     ValSel s;
00102     ValCommit c;
00103   public:
00105     ValSelCommit(Space& home, const ValBranch<Var>& vb);
00107     ValSelCommit(Space& home, ValSelCommit<ValSel,ValCommit>& vsc);
00109     virtual Val val(const Space& home, View x, int i);
00111     virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00113     virtual NGL* ngl(Space& home, unsigned int a,
00114                      View x, Val n) const;
00116     virtual void print(const Space& home, unsigned int a,
00117                        View x, int i, const Val& n,
00118                        std::ostream& o) const;
00120     virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home);
00122     virtual bool notice(void) const;
00124     virtual void dispose(Space& home);
00125   };
00127 
00128 
00129   template<class View, class Val>
00130   forceinline
00131   ValSelCommitBase<View,Val>::ValSelCommitBase(Space&, 
00132                                                const ValBranch<Var>&) {}
00133   template<class View, class Val>
00134   forceinline
00135   ValSelCommitBase<View,Val>::
00136     ValSelCommitBase(Space&, ValSelCommitBase<View,Val>&) {}
00137   template<class View, class Val>
00138   ValSelCommitBase<View,Val>::~ValSelCommitBase(void) {}
00139 
00140   template<class View, class Val>
00141   forceinline void
00142   ValSelCommitBase<View,Val>::operator delete(void*) {}
00143   template<class View, class Val>
00144   forceinline void
00145   ValSelCommitBase<View,Val>::operator delete(void*, Space&) {}
00146   template<class View, class Val>
00147   forceinline void*
00148   ValSelCommitBase<View,Val>::operator new(size_t s, Space& home) {
00149     return home.ralloc(s);
00150   }
00151 
00152 
00153 
00154 
00155   template<class ValSel, class ValCommit>
00156   forceinline
00157   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home,
00158                                                const ValBranch<Var>& vb)
00159     : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
00160 
00161   template<class ValSel, class ValCommit>
00162   forceinline
00163   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home,
00164                                                ValSelCommit<ValSel,ValCommit>& vsc)
00165     : ValSelCommitBase<View,Val>(home,vsc),
00166       s(home,vsc.s), c(home,vsc.c) {}
00167 
00168   template<class ValSel, class ValCommit>
00169   typename ValSelCommit<ValSel,ValCommit>::Val
00170   ValSelCommit<ValSel,ValCommit>::val(const Space& home, View x, int i) {
00171     return s.val(home,x,i);
00172   }
00173 
00174   template<class ValSel, class ValCommit>
00175   ModEvent
00176   ValSelCommit<ValSel,ValCommit>::commit(Space& home, unsigned int a,
00177                                          View x, int i, Val n) {
00178     return c.commit(home,a,x,i,n);
00179   }
00180 
00181   template<class ValSel, class ValCommit>
00182   NGL*
00183   ValSelCommit<ValSel,ValCommit>::ngl(Space& home, unsigned int a,
00184                                       View x, Val n) const {
00185     return c.ngl(home, a, x, n);
00186   }
00187 
00188   template<class ValSel, class ValCommit>
00189   void
00190   ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
00191                                         View x, int i, const Val& n,
00192                                         std::ostream& o) const {
00193     c.print(home,a,x,i,n,o);
00194   }
00195 
00196   template<class ValSel, class ValCommit>
00197   ValSelCommit<ValSel,ValCommit>*
00198   ValSelCommit<ValSel,ValCommit>::copy(Space& home) {
00199     return new (home) ValSelCommit<ValSel,ValCommit>(home,*this);
00200   }
00201 
00202   template<class ValSel, class ValCommit>
00203   bool
00204   ValSelCommit<ValSel,ValCommit>::notice(void) const {
00205     return s.notice() || c.notice();
00206   }
00207 
00208   template<class ValSel, class ValCommit>
00209   void
00210   ValSelCommit<ValSel,ValCommit>::dispose(Space& home) {
00211     s.dispose(home);
00212     c.dispose(home);
00213   }
00214 
00215 }
00216 
00217 // STATISTICS: kernel-branch