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

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  *  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 ValCommit {
00045   public:
00047     typedef _View View;
00049     typedef typename View::VarType Var;
00051     typedef _Val Val;
00052   public:
00054     ValCommit(Space& home, const ValBranch<Var>& vb);
00056     ValCommit(Space& home, ValCommit<View,Val>& vs);
00058     bool notice(void) const;
00060     void dispose(Space& home);
00061   };
00062 
00064   template<class View>
00065   class ValCommitFunction : public
00066   ValCommit<View,
00067             typename BranchTraits<typename View::VarType>::ValType> {
00068     typedef typename ValCommit<View,
00069                                typename BranchTraits<typename View::VarType>
00070                                  ::ValType>::Val Val;
00071   public:
00073     typedef typename View::VarType Var;
00075     typedef typename BranchTraits<Var>::Commit CommitFunction;
00076   protected:
00078     SharedData<CommitFunction> c;
00079   public:
00081     ValCommitFunction(Space& home, const ValBranch<Var>& vb);
00083     ValCommitFunction(Space& home, ValCommitFunction& vc);
00085     ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
00087     NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
00089     void print(const Space& home, unsigned int a, View x, int i,
00090                const Val& n, std::ostream& o) const;
00092     bool notice(void) const;
00094     void dispose(Space& home);
00095   };
00097 
00098   // Baseclass for value commit
00099   template<class View, class Val>
00100   forceinline
00101   ValCommit<View,Val>::ValCommit(Space&, const ValBranch<Var>&) {}
00102   template<class View, class Val>
00103   forceinline
00104   ValCommit<View,Val>::ValCommit(Space&, ValCommit<View,Val>&) {}
00105   template<class View, class Val>
00106   forceinline bool
00107   ValCommit<View,Val>::notice(void) const {
00108     return false;
00109   }
00110   template<class View, class Val>
00111   forceinline void
00112   ValCommit<View,Val>::dispose(Space&) {}
00113 
00114 
00115   // User-defined value selection
00116   template<class View>
00117   forceinline
00118   ValCommitFunction<View>::ValCommitFunction(Space& home,
00119                                              const ValBranch<Var>& vb)
00120     : ValCommit<View,Val>(home,vb), c(vb.commit()) {
00121     if (!c())
00122       throw InvalidFunction("ValCommitFunction::ValCommitFunction");
00123   }
00124   template<class View>
00125   forceinline
00126   ValCommitFunction<View>::ValCommitFunction(Space& home,
00127                                              ValCommitFunction<View>& vc)
00128     : ValCommit<View,Val>(home,vc), c(vc.c) {
00129   }
00130   template<class View>
00131   forceinline ModEvent
00132   ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
00133                                   Val n) {
00134     typename View::VarType y(x.varimp());
00135     GECODE_VALID_FUNCTION(c());
00136     c()(home,a,y,i,n);
00137     return home.failed() ? ES_FAILED : ES_OK;
00138   }
00139   template<class View>
00140   forceinline NGL*
00141   ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
00142     return NULL;
00143   }
00144   template<class View>
00145   forceinline void
00146   ValCommitFunction<View>::print(const Space&, unsigned int,
00147                                  View, int i, const Val&,
00148                                  std::ostream& o) const {
00149     o << "var[" << i << "] is user-defined.";
00150   }
00151   template<class View>
00152   forceinline bool
00153   ValCommitFunction<View>::notice(void) const {
00154     return true;
00155   }
00156   template<class View>
00157   forceinline void
00158   ValCommitFunction<View>::dispose(Space&) {
00159     c.~SharedData<CommitFunction>();
00160   }
00161 
00162 }
00163 
00164 // STATISTICS: kernel-branch