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

brancher-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  *  Last modified:
00010  *     $Date: 2012-10-02 15:49:50 +0200 (Tue, 02 Oct 2012) $ by $Author: schulte $
00011  *     $Revision: 13123 $
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 ValSel {
00049   public:
00051     typedef _View View;
00053     typedef _Val Val;
00054   public:
00056     ValSel(Space& home, const ValBranch& vb);
00058     ValSel(Space& home, bool shared, ValSel<View,Val>& vs);
00060     bool notice(void) const;
00062     void dispose(Space& home);
00063   };
00064 
00066   template<class View>
00067   class ValSelFunction : 
00068     public ValSel<View,
00069                   typename BranchTraits<typename View::VarType>::ValType> {
00070   public:
00072     typedef typename ValSel<View,
00073                             typename BranchTraits<typename View::VarType>
00074                               ::ValType>::Val Val;
00076     typedef typename View::VarType Var;
00078     typedef typename BranchTraits<Var>::Val ValFunction;
00079   protected:
00081     ValFunction v;
00082   public:
00084     ValSelFunction(Space& home, const ValBranch& vb);
00086     ValSelFunction(Space& home, bool shared, ValSelFunction<View>& vs);
00088     Val val(const Space& home, View x, int i);
00089   };
00091 
00092 
00093   // Baseclass value selection
00094   template<class View, class Val>
00095   forceinline
00096   ValSel<View,Val>::ValSel(Space&, const ValBranch&) {}
00097   template<class View, class Val>
00098   forceinline
00099   ValSel<View,Val>::ValSel(Space&, bool, ValSel<View,Val>&) {}
00100   template<class View, class Val>
00101   forceinline bool
00102   ValSel<View,Val>::notice(void) const {
00103     return false;
00104   }
00105   template<class View, class Val>
00106   forceinline void
00107   ValSel<View,Val>::dispose(Space&) {}
00108 
00109 
00110   // User-defined value selection
00111   template<class View>
00112   forceinline
00113   ValSelFunction<View>::ValSelFunction(Space& home, const ValBranch& vb)
00114     : ValSel<View,Val>(home,vb),
00115       v(function_cast<ValFunction>(vb.val())) {}
00116   template<class View>
00117   forceinline
00118   ValSelFunction<View>::ValSelFunction(Space& home, bool shared, 
00119                                        ValSelFunction<View>& vs) 
00120     : ValSel<View,Val>(home,shared,vs), v(vs.v) {}
00121   template<class View>
00122   forceinline typename ValSelFunction<View>::Val
00123   ValSelFunction<View>::val(const Space& home, View x, int i) {
00124     typename View::VarType y(x.varimp());
00125     return v(home,y,i);
00126   }
00127 
00128 }
00129 
00130 // STATISTICS: kernel-branch