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

brancher-val-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 ValCommit {
00049   public:
00051     typedef _View View;
00053     typedef _Val Val;
00054   public:
00056     ValCommit(Space& home, const ValBranch& vb);
00058     ValCommit(Space& home, bool shared, ValCommit<View,Val>& vs);
00060     bool notice(void) const;
00062     void dispose(Space& home);
00063   };
00064 
00066   template<class View>
00067   class ValCommitFunction : public 
00068   ValCommit<View,
00069             typename BranchTraits<typename View::VarType>::ValType> {
00070     typedef typename ValCommit<View,
00071                                typename BranchTraits<typename View::VarType>
00072                                  ::ValType>::Val Val;
00073   public:
00075     typedef typename View::VarType Var;
00077     typedef typename BranchTraits<Var>::Commit CommitFunction;
00078   protected:
00080     CommitFunction c;
00081   public:
00083     ValCommitFunction(Space& home, const ValBranch& vb);
00085     ValCommitFunction(Space& home, bool shared, ValCommitFunction& vc);
00087     ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00089     NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
00091     void print(const Space& home, unsigned int a, View x, int i, 
00092                const Val& n, std::ostream& o) const;
00093   };
00095 
00096   // Baseclass for value commit
00097   template<class View, class Val>
00098   forceinline
00099   ValCommit<View,Val>::ValCommit(Space&, const ValBranch&) {}
00100   template<class View, class Val>
00101   forceinline
00102   ValCommit<View,Val>::ValCommit(Space&, bool, ValCommit<View,Val>&) {}
00103   template<class View, class Val>
00104   forceinline bool
00105   ValCommit<View,Val>::notice(void) const {
00106     return false;
00107   }
00108   template<class View, class Val>
00109   forceinline void
00110   ValCommit<View,Val>::dispose(Space&) {}
00111 
00112 
00113   // User-defined value selection
00114   template<class View>
00115   forceinline
00116   ValCommitFunction<View>::ValCommitFunction(Space& home, 
00117                                              const ValBranch& vb) 
00118     : ValCommit<View,Val>(home,vb),
00119       c(function_cast<CommitFunction>(vb.commit())) {}
00120   template<class View>
00121   forceinline
00122   ValCommitFunction<View>::ValCommitFunction(Space& home, bool shared, 
00123                                              ValCommitFunction<View>& vc) 
00124     : ValCommit<View,Val>(home,shared,vc), c(vc.c) {}
00125   template<class View>
00126   forceinline ModEvent
00127   ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i, 
00128                                   Val n) {
00129     typename View::VarType y(x.varimp());
00130     c(home,a,y,i,n);
00131     return home.failed() ? ES_FAILED : ES_OK;
00132   }
00133   template<class View>
00134   forceinline NGL*
00135   ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
00136     return NULL;
00137   }
00138   template<class View>
00139   forceinline void
00140   ValCommitFunction<View>::print(const Space&, unsigned int, 
00141                                  View, int i, const Val&,
00142                                  std::ostream& o) const {
00143     o << "var[" << i << "] is user-defined.";
00144   }
00145 
00146 }
00147 
00148 // STATISTICS: kernel-branch