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

val-sel.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 ValSel {
00045   public:
00047     typedef _View View;
00049     typedef typename View::VarType Var;
00051     typedef _Val Val;
00052   public:
00054     ValSel(Space& home, const ValBranch<Var>& vb);
00056     ValSel(Space& home, ValSel<View,Val>& vs);
00058     bool notice(void) const;
00060     void dispose(Space& home);
00061   };
00062 
00064   template<class View>
00065   class ValSelFunction :
00066     public ValSel<View,
00067                   typename BranchTraits<typename View::VarType>::ValType> {
00068     using typename ValSel<View,
00069                           typename BranchTraits<typename View::VarType>::ValType>::Var;
00070   public:
00072     typedef typename ValSel<View,
00073                             typename BranchTraits<typename View::VarType>
00074                               ::ValType>::Val Val;
00076     typedef typename BranchTraits<Var>::Val ValFunction;
00077   protected:
00079     SharedData<ValFunction> v;
00080   public:
00082     ValSelFunction(Space& home, const ValBranch<Var>& vb);
00084     ValSelFunction(Space& home, ValSelFunction<View>& vs);
00086     Val val(const Space& home, View x, int i);
00088     bool notice(void) const;
00090     void dispose(Space& home);
00091   };
00093 
00094 
00095   // Baseclass value selection
00096   template<class View, class Val>
00097   forceinline
00098   ValSel<View,Val>::ValSel(Space&, const ValBranch<Var>&) {}
00099   template<class View, class Val>
00100   forceinline
00101   ValSel<View,Val>::ValSel(Space&, ValSel<View,Val>&) {}
00102   template<class View, class Val>
00103   forceinline bool
00104   ValSel<View,Val>::notice(void) const {
00105     return false;
00106   }
00107   template<class View, class Val>
00108   forceinline void
00109   ValSel<View,Val>::dispose(Space&) {}
00110 
00111 
00112   // User-defined value selection
00113   template<class View>
00114   forceinline
00115   ValSelFunction<View>::ValSelFunction
00116     (Space& home, const ValBranch<ValSelFunction<View>::Var>& vb)
00117     : ValSel<View,Val>(home,vb), v(vb.val()) {
00118     if (!v())
00119       throw InvalidFunction("ValSelFunction::ValSelFunction");
00120   }
00121   template<class View>
00122   forceinline
00123   ValSelFunction<View>::ValSelFunction(Space& home, ValSelFunction<View>& vs)
00124     : ValSel<View,Val>(home,vs), v(vs.v) {
00125   }
00126   template<class View>
00127   forceinline typename ValSelFunction<View>::Val
00128   ValSelFunction<View>::val(const Space& home, View x, int i) {
00129     typename View::VarType y(x.varimp());
00130     GECODE_VALID_FUNCTION(v());
00131     return v()(home,y,i);
00132   }
00133   template<class View>
00134   forceinline bool
00135   ValSelFunction<View>::notice(void) const {
00136     return true;
00137   }
00138   template<class View>
00139   forceinline void
00140   ValSelFunction<View>::dispose(Space&) {
00141     v.~SharedData<ValFunction>();
00142   }
00143 
00144 }
00145 
00146 // STATISTICS: kernel-branch