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

brancher-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  *  Last modified:
00010  *     $Date: 2013-07-04 17:03:13 +0200 (Thu, 04 Jul 2013) $ by $Author: schulte $
00011  *     $Revision: 13801 $
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 namespace Gecode {
00039 
00046 
00047   template<class _View, class _Val>
00048   class ValSelCommitBase {
00049   public:
00051     typedef _View View;
00053     typedef _Val Val;
00054   public:
00056     ValSelCommitBase(Space& home, const ValBranch& vb);
00058     ValSelCommitBase(Space& home, bool shared, 
00059                      ValSelCommitBase<View,Val>& vsc);
00061     virtual Val val(const Space& home, View x, int i) = 0;
00063     virtual ModEvent commit(Space& home, unsigned int a, 
00064                             View x, int i, Val n) = 0;
00066     virtual NGL* ngl(Space& home, unsigned int a,
00067                      View x, Val n) const = 0;
00069     virtual void print(const Space& home, unsigned int a,
00070                        View x, int i, const Val& n,
00071                        std::ostream& o) const = 0;
00073     virtual ValSelCommitBase<View,Val>* copy(Space& home, bool shared) = 0;
00075     virtual bool notice(void) const = 0;
00077     virtual void dispose(Space& home) = 0;
00079 
00080 
00081     static void* operator new(size_t s, Space& home);
00083     static void operator delete(void* p, Space& home);
00085     static void operator delete(void* p);
00087   };
00088 
00090   template<class ValSel, class ValCommit>
00091   class ValSelCommit 
00092     : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
00093   protected:
00094     typedef typename ValSelCommitBase<typename ValSel::View,
00095                                       typename ValSel::Val>::Val Val;
00096     typedef typename ValSelCommitBase<typename ValSel::View,
00097                                       typename ValSel::Val>::View View;
00099     ValSel s;
00101     ValCommit c;
00102   public:
00104     ValSelCommit(Space& home, const ValBranch& vb);
00106     ValSelCommit(Space& home, bool shared, 
00107                  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, bool shared);
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&, const ValBranch&) {}
00132   template<class View, class Val>
00133   forceinline
00134   ValSelCommitBase<View,Val>::
00135     ValSelCommitBase(Space&, bool, ValSelCommitBase<View,Val>&) {}
00136 
00137   template<class View, class Val>
00138   forceinline void
00139   ValSelCommitBase<View,Val>::operator delete(void*) {}
00140   template<class View, class Val>
00141   forceinline void
00142   ValSelCommitBase<View,Val>::operator delete(void*, Space&) {}
00143   template<class View, class Val>
00144   forceinline void*
00145   ValSelCommitBase<View,Val>::operator new(size_t s, Space& home) {
00146     return home.ralloc(s);
00147   }
00148 
00149 
00150 
00151 
00152   template<class ValSel, class ValCommit>
00153   forceinline
00154   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home, 
00155                                                const ValBranch& vb) 
00156     : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
00157 
00158   template<class ValSel, class ValCommit>
00159   forceinline
00160   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home, bool shared, 
00161                                                ValSelCommit<ValSel,ValCommit>& vsc)
00162     : ValSelCommitBase<View,Val>(home,shared,vsc),
00163       s(home,shared,vsc.s), c(home,shared,vsc.c) {}
00164 
00165   template<class ValSel, class ValCommit>
00166   typename ValSelCommit<ValSel,ValCommit>::Val
00167   ValSelCommit<ValSel,ValCommit>::val(const Space& home, View x, int i) {
00168     return s.val(home,x,i);
00169   }
00170 
00171   template<class ValSel, class ValCommit>
00172   ModEvent
00173   ValSelCommit<ValSel,ValCommit>::commit(Space& home, unsigned int a, 
00174                                          View x, int i, Val n) {
00175     return c.commit(home,a,x,i,n);
00176   }
00177 
00178   template<class ValSel, class ValCommit>
00179   NGL* 
00180   ValSelCommit<ValSel,ValCommit>::ngl(Space& home, unsigned int a,
00181                                       View x, Val n) const {
00182     return c.ngl(home, a, x, n);
00183   }
00184 
00185   template<class ValSel, class ValCommit>
00186   void
00187   ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a, 
00188                                         View x, int i, const Val& n,
00189                                         std::ostream& o) const {
00190     c.print(home,a,x,i,n,o);
00191   }
00192 
00193   template<class ValSel, class ValCommit>
00194   ValSelCommit<ValSel,ValCommit>*
00195   ValSelCommit<ValSel,ValCommit>::copy(Space& home, bool shared) {
00196     return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
00197   }
00198 
00199   template<class ValSel, class ValCommit>
00200   bool
00201   ValSelCommit<ValSel,ValCommit>::notice(void) const {
00202     return s.notice() || c.notice();
00203   }
00204 
00205   template<class ValSel, class ValCommit>
00206   void
00207   ValSelCommit<ValSel,ValCommit>::dispose(Space& home) {
00208     s.dispose(home);
00209     c.dispose(home);
00210   }
00211 
00212 }
00213 
00214 // STATISTICS: kernel-branch