Generated on Tue May 22 09:39:45 2018 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(Space& home, const ValBranch<Var>& vb)
00116     : ValSel<View,Val>(home,vb), v(vb.val()) {
00117     if (!v())
00118       throw InvalidFunction("ValSelFunction::ValSelFunction");
00119   }
00120   template<class View>
00121   forceinline
00122   ValSelFunction<View>::ValSelFunction(Space& home, ValSelFunction<View>& vs)
00123     : ValSel<View,Val>(home,vs), v(vs.v) {
00124   }
00125   template<class View>
00126   forceinline typename ValSelFunction<View>::Val
00127   ValSelFunction<View>::val(const Space& home, View x, int i) {
00128     typename View::VarType y(x.varimp());
00129     GECODE_VALID_FUNCTION(v());
00130     return v()(home,y,i);
00131   }
00132   template<class View>
00133   forceinline bool
00134   ValSelFunction<View>::notice(void) const {
00135     return true;
00136   }
00137   template<class View>
00138   forceinline void
00139   ValSelFunction<View>::dispose(Space&) {
00140     v.~SharedData<ValFunction>();
00141   }
00142 
00143 }
00144 
00145 // STATISTICS: kernel-branch