Generated on Tue Apr 18 10:22:04 2017 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: 2017-02-23 01:27:48 +0100 (Thu, 23 Feb 2017) $ by $Author: tack $
00011  *     $Revision: 15472 $
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 typename View::VarType Var;
00055     typedef _Val Val;
00056   public:
00058     ValSelCommitBase(Space& home, const ValBranch<Var>& vb);
00060     ValSelCommitBase(Space& home, bool shared,
00061                      ValSelCommitBase<View,Val>& vsc);
00063     virtual Val val(const Space& home, View x, int i) = 0;
00065     virtual ModEvent commit(Space& home, unsigned int a,
00066                             View x, int i, Val n) = 0;
00068     virtual NGL* ngl(Space& home, unsigned int a,
00069                      View x, Val n) const = 0;
00071     virtual void print(const Space& home, unsigned int a,
00072                        View x, int i, const Val& n,
00073                        std::ostream& o) const = 0;
00075     virtual ValSelCommitBase<View,Val>* copy(Space& home, bool shared) = 0;
00077     virtual bool notice(void) const = 0;
00079     virtual void dispose(Space& home) = 0;
00081     virtual ~ValSelCommitBase(void);
00083 
00084 
00085     static void* operator new(size_t s, Space& home);
00087     static void operator delete(void* p, Space& home);
00089     static void operator delete(void* p);
00091   };
00092 
00094   template<class ValSel, class ValCommit>
00095   class ValSelCommit
00096     : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
00097   protected:
00098     typedef typename ValSelCommitBase<typename ValSel::View,
00099                                       typename ValSel::Val>::Var Var;
00100     typedef typename ValSelCommitBase<typename ValSel::View,
00101                                       typename ValSel::Val>::Val Val;
00102     typedef typename ValSelCommitBase<typename ValSel::View,
00103                                       typename ValSel::Val>::View View;
00105     ValSel s;
00107     ValCommit c;
00108   public:
00110     ValSelCommit(Space& home, const ValBranch<Var>& vb);
00112     ValSelCommit(Space& home, bool shared,
00113                  ValSelCommit<ValSel,ValCommit>& vsc);
00115     virtual Val val(const Space& home, View x, int i);
00117     virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00119     virtual NGL* ngl(Space& home, unsigned int a,
00120                      View x, Val n) const;
00122     virtual void print(const Space& home, unsigned int a,
00123                        View x, int i, const Val& n,
00124                        std::ostream& o) const;
00126     virtual ValSelCommit<ValSel,ValCommit>* copy(Space& home, bool shared);
00128     virtual bool notice(void) const;
00130     virtual void dispose(Space& home);
00131   };
00133 
00134 
00135   template<class View, class Val>
00136   forceinline
00137   ValSelCommitBase<View,Val>::ValSelCommitBase(Space&, 
00138                                                const ValBranch<Var>&) {}
00139   template<class View, class Val>
00140   forceinline
00141   ValSelCommitBase<View,Val>::
00142     ValSelCommitBase(Space&, bool, ValSelCommitBase<View,Val>&) {}
00143   template<class View, class Val>
00144   ValSelCommitBase<View,Val>::~ValSelCommitBase(void) {}
00145 
00146   template<class View, class Val>
00147   forceinline void
00148   ValSelCommitBase<View,Val>::operator delete(void*) {}
00149   template<class View, class Val>
00150   forceinline void
00151   ValSelCommitBase<View,Val>::operator delete(void*, Space&) {}
00152   template<class View, class Val>
00153   forceinline void*
00154   ValSelCommitBase<View,Val>::operator new(size_t s, Space& home) {
00155     return home.ralloc(s);
00156   }
00157 
00158 
00159 
00160 
00161   template<class ValSel, class ValCommit>
00162   forceinline
00163   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home,
00164                                                const ValBranch<Var>& vb)
00165     : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
00166 
00167   template<class ValSel, class ValCommit>
00168   forceinline
00169   ValSelCommit<ValSel,ValCommit>::ValSelCommit(Space& home, bool shared,
00170                                                ValSelCommit<ValSel,ValCommit>& vsc)
00171     : ValSelCommitBase<View,Val>(home,shared,vsc),
00172       s(home,shared,vsc.s), c(home,shared,vsc.c) {}
00173 
00174   template<class ValSel, class ValCommit>
00175   typename ValSelCommit<ValSel,ValCommit>::Val
00176   ValSelCommit<ValSel,ValCommit>::val(const Space& home, View x, int i) {
00177     return s.val(home,x,i);
00178   }
00179 
00180   template<class ValSel, class ValCommit>
00181   ModEvent
00182   ValSelCommit<ValSel,ValCommit>::commit(Space& home, unsigned int a,
00183                                          View x, int i, Val n) {
00184     return c.commit(home,a,x,i,n);
00185   }
00186 
00187   template<class ValSel, class ValCommit>
00188   NGL*
00189   ValSelCommit<ValSel,ValCommit>::ngl(Space& home, unsigned int a,
00190                                       View x, Val n) const {
00191     return c.ngl(home, a, x, n);
00192   }
00193 
00194   template<class ValSel, class ValCommit>
00195   void
00196   ValSelCommit<ValSel,ValCommit>::print(const Space& home, unsigned int a,
00197                                         View x, int i, const Val& n,
00198                                         std::ostream& o) const {
00199     c.print(home,a,x,i,n,o);
00200   }
00201 
00202   template<class ValSel, class ValCommit>
00203   ValSelCommit<ValSel,ValCommit>*
00204   ValSelCommit<ValSel,ValCommit>::copy(Space& home, bool shared) {
00205     return new (home) ValSelCommit<ValSel,ValCommit>(home,shared,*this);
00206   }
00207 
00208   template<class ValSel, class ValCommit>
00209   bool
00210   ValSelCommit<ValSel,ValCommit>::notice(void) const {
00211     return s.notice() || c.notice();
00212   }
00213 
00214   template<class ValSel, class ValCommit>
00215   void
00216   ValSelCommit<ValSel,ValCommit>::dispose(Space& home) {
00217     s.dispose(home);
00218     c.dispose(home);
00219   }
00220 
00221 }
00222 
00223 // STATISTICS: kernel-branch