Generated on Fri Oct 19 11:24:53 2018 for Gecode by doxygen 1.6.3

merit.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
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 { namespace Int { namespace Branch {
00035 
00036   // Minimum merit
00037   template<class View>
00038   forceinline
00039   MeritMin<View>::MeritMin(Space& home, const VarBranch<Var>& vb)
00040     : MeritBase<View,int>(home,vb) {}
00041   template<class View>
00042   forceinline
00043   MeritMin<View>::MeritMin(Space& home, MeritMin& m)
00044     : MeritBase<View,int>(home,m) {}
00045   template<class View>
00046   forceinline int
00047   MeritMin<View>::operator ()(const Space&, View x, int) {
00048     return x.min();
00049   }
00050 
00051   // Maximum merit
00052   template<class View>
00053   forceinline
00054   MeritMax<View>::MeritMax(Space& home, const VarBranch<Var>& vb)
00055     : MeritBase<View,int>(home,vb) {}
00056   template<class View>
00057   forceinline
00058   MeritMax<View>::MeritMax(Space& home, MeritMax& m)
00059     : MeritBase<View,int>(home,m) {}
00060   template<class View>
00061   forceinline int
00062   MeritMax<View>::operator ()(const Space&, View x, int) {
00063     return x.max();
00064   }
00065 
00066   // Size merit
00067   template<class View>
00068   forceinline
00069   MeritSize<View>::MeritSize(Space& home, const VarBranch<Var>& vb)
00070     : MeritBase<View,unsigned int>(home,vb) {}
00071   template<class View>
00072   forceinline
00073   MeritSize<View>::MeritSize(Space& home, MeritSize& m)
00074     : MeritBase<View,unsigned int>(home,m) {}
00075   template<class View>
00076   forceinline unsigned int
00077   MeritSize<View>::operator ()(const Space&, View x, int) {
00078     return x.size();
00079   }
00080 
00081   // Degree over size merit
00082   template<class View>
00083   forceinline
00084   MeritDegreeSize<View>::MeritDegreeSize(Space& home, const VarBranch<Var>& vb)
00085     : MeritBase<View,double>(home,vb) {}
00086   template<class View>
00087   forceinline
00088   MeritDegreeSize<View>::MeritDegreeSize(Space& home, MeritDegreeSize& m)
00089     : MeritBase<View,double>(home,m) {}
00090   template<class View>
00091   forceinline double
00092   MeritDegreeSize<View>::operator ()(const Space&, View x, int) {
00093     return static_cast<double>(x.degree()) / static_cast<double>(x.size());
00094   }
00095 
00096   // AFC over size merit
00097   template<class View>
00098   forceinline
00099   MeritAFCSize<View>::MeritAFCSize(Space& home, const VarBranch<Var>& vb)
00100     : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
00101   template<class View>
00102   forceinline
00103   MeritAFCSize<View>::MeritAFCSize(Space& home, MeritAFCSize& m)
00104     : MeritBase<View,double>(home,m), afc(m.afc) {}
00105   template<class View>
00106   forceinline double
00107   MeritAFCSize<View>::operator ()(const Space&, View x, int) {
00108     return x.afc() / static_cast<double>(x.size());
00109   }
00110   template<class View>
00111   forceinline bool
00112   MeritAFCSize<View>::notice(void) const {
00113     return false;
00114   }
00115   template<class View>
00116   forceinline void
00117   MeritAFCSize<View>::dispose(Space&) {
00118     // Not needed
00119     afc.~AFC();
00120   }
00121 
00122   // Action over size merit
00123   template<class View>
00124   forceinline
00125   MeritActionSize<View>::MeritActionSize(Space& home,
00126                                          const VarBranch<Var>& vb)
00127     : MeritBase<View,double>(home,vb), action(vb.action()) {}
00128   template<class View>
00129   forceinline
00130   MeritActionSize<View>::MeritActionSize(Space& home, MeritActionSize& m)
00131     : MeritBase<View,double>(home,m), action(m.action) {}
00132   template<class View>
00133   forceinline double
00134   MeritActionSize<View>::operator ()(const Space&, View x, int i) {
00135     return action[i] / static_cast<double>(x.size());
00136   }
00137   template<class View>
00138   forceinline bool
00139   MeritActionSize<View>::notice(void) const {
00140     return true;
00141   }
00142   template<class View>
00143   forceinline void
00144   MeritActionSize<View>::dispose(Space&) {
00145     action.~Action();
00146   }
00147 
00148   // CHB over size merit
00149   template<class View>
00150   forceinline
00151   MeritCHBSize<View>::MeritCHBSize(Space& home,
00152                                    const VarBranch<Var>& vb)
00153     : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
00154   template<class View>
00155   forceinline
00156   MeritCHBSize<View>::MeritCHBSize(Space& home, MeritCHBSize& m)
00157     : MeritBase<View,double>(home,m), chb(m.chb) {}
00158   template<class View>
00159   forceinline double
00160   MeritCHBSize<View>::operator ()(const Space&, View x, int i) {
00161     return chb[i] / static_cast<double>(x.size());
00162   }
00163   template<class View>
00164   forceinline bool
00165   MeritCHBSize<View>::notice(void) const {
00166     return true;
00167   }
00168   template<class View>
00169   forceinline void
00170   MeritCHBSize<View>::dispose(Space&) {
00171     chb.~CHB();
00172   }
00173 
00174   // Minimum regret merit
00175   template<class View>
00176   forceinline
00177   MeritRegretMin<View>::MeritRegretMin(Space& home, const VarBranch<Var>& vb)
00178     : MeritBase<View,unsigned int>(home,vb) {}
00179   template<class View>
00180   forceinline
00181   MeritRegretMin<View>::MeritRegretMin(Space& home, MeritRegretMin& m)
00182     : MeritBase<View,unsigned int>(home,m) {}
00183   template<class View>
00184   forceinline unsigned int
00185   MeritRegretMin<View>::operator ()(const Space&, View x, int) {
00186     return x.regret_min();
00187   }
00188 
00189   // Maximum regret merit
00190   template<class View>
00191   forceinline
00192   MeritRegretMax<View>::MeritRegretMax(Space& home, const VarBranch<Var>& vb)
00193     : MeritBase<View,unsigned int>(home,vb) {}
00194   template<class View>
00195   forceinline
00196   MeritRegretMax<View>::MeritRegretMax(Space& home, MeritRegretMax& m)
00197     : MeritBase<View,unsigned int>(home,m) {}
00198   template<class View>
00199   forceinline unsigned int
00200   MeritRegretMax<View>::operator ()(const Space&, View x, int) {
00201     return x.regret_max();
00202   }
00203 
00204 }}}
00205 
00206 // STATISTICS: int-branch