Generated on Tue Apr 18 10:21:36 2017 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  *  Last modified:
00010  *     $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
00011  *     $Revision: 15623 $
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 { namespace Int { namespace Branch {
00039 
00040   // Minimum merit
00041   template<class View>
00042   forceinline
00043   MeritMin<View>::MeritMin(Space& home, const VarBranch<Var>& vb)
00044     : MeritBase<View,int>(home,vb) {}
00045   template<class View>
00046   forceinline
00047   MeritMin<View>::MeritMin(Space& home, bool shared, MeritMin& m)
00048     : MeritBase<View,int>(home,shared,m) {}
00049   template<class View>
00050   forceinline int
00051   MeritMin<View>::operator ()(const Space&, View x, int) {
00052     return x.min();
00053   }
00054 
00055   // Maximum merit
00056   template<class View>
00057   forceinline
00058   MeritMax<View>::MeritMax(Space& home, const VarBranch<Var>& vb)
00059     : MeritBase<View,int>(home,vb) {}
00060   template<class View>
00061   forceinline
00062   MeritMax<View>::MeritMax(Space& home, bool shared, MeritMax& m)
00063     : MeritBase<View,int>(home,shared,m) {}
00064   template<class View>
00065   forceinline int
00066   MeritMax<View>::operator ()(const Space&, View x, int) {
00067     return x.max();
00068   }
00069 
00070   // Size merit
00071   template<class View>
00072   forceinline
00073   MeritSize<View>::MeritSize(Space& home, const VarBranch<Var>& vb)
00074     : MeritBase<View,unsigned int>(home,vb) {}
00075   template<class View>
00076   forceinline
00077   MeritSize<View>::MeritSize(Space& home, bool shared, MeritSize& m)
00078     : MeritBase<View,unsigned int>(home,shared,m) {}
00079   template<class View>
00080   forceinline unsigned int
00081   MeritSize<View>::operator ()(const Space&, View x, int) {
00082     return x.size();
00083   }
00084 
00085   // Degree over size merit
00086   template<class View>
00087   forceinline
00088   MeritDegreeSize<View>::MeritDegreeSize(Space& home, const VarBranch<Var>& vb)
00089     : MeritBase<View,double>(home,vb) {}
00090   template<class View>
00091   forceinline
00092   MeritDegreeSize<View>::MeritDegreeSize(Space& home, bool shared,
00093                                          MeritDegreeSize& m)
00094     : MeritBase<View,double>(home,shared,m) {}
00095   template<class View>
00096   forceinline double
00097   MeritDegreeSize<View>::operator ()(const Space&, View x, int) {
00098     return static_cast<double>(x.degree()) / static_cast<double>(x.size());
00099   }
00100 
00101   // AFC over size merit
00102   template<class View>
00103   forceinline
00104   MeritAFCSize<View>::MeritAFCSize(Space& home, const VarBranch<Var>& vb)
00105     : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
00106   template<class View>
00107   forceinline
00108   MeritAFCSize<View>::MeritAFCSize(Space& home, bool shared, MeritAFCSize& m)
00109     : MeritBase<View,double>(home,shared,m) {
00110     afc.update(home,shared,m.afc);
00111   }
00112   template<class View>
00113   forceinline double
00114   MeritAFCSize<View>::operator ()(const Space&, View x, int) {
00115     return x.afc() / static_cast<double>(x.size());
00116   }
00117   template<class View>
00118   forceinline bool
00119   MeritAFCSize<View>::notice(void) const {
00120     return true;
00121   }
00122   template<class View>
00123   forceinline void
00124   MeritAFCSize<View>::dispose(Space&) {
00125     afc.~AFC();
00126   }
00127 
00128   // Action over size merit
00129   template<class View>
00130   forceinline
00131   MeritActionSize<View>::MeritActionSize(Space& home,
00132                                          const VarBranch<Var>& vb)
00133     : MeritBase<View,double>(home,vb), action(vb.action()) {}
00134   template<class View>
00135   forceinline
00136   MeritActionSize<View>::MeritActionSize(Space& home, bool shared,
00137                                          MeritActionSize& m)
00138     : MeritBase<View,double>(home,shared,m) {
00139     action.update(home, shared, m.action);
00140   }
00141   template<class View>
00142   forceinline double
00143   MeritActionSize<View>::operator ()(const Space&, View x, int i) {
00144     return action[i] / static_cast<double>(x.size());
00145   }
00146   template<class View>
00147   forceinline bool
00148   MeritActionSize<View>::notice(void) const {
00149     return true;
00150   }
00151   template<class View>
00152   forceinline void
00153   MeritActionSize<View>::dispose(Space&) {
00154     action.~Action();
00155   }
00156 
00157   // CHB over size merit
00158   template<class View>
00159   forceinline
00160   MeritCHBSize<View>::MeritCHBSize(Space& home,
00161                                    const VarBranch<Var>& vb)
00162     : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
00163   template<class View>
00164   forceinline
00165   MeritCHBSize<View>::MeritCHBSize(Space& home, bool shared,
00166                                    MeritCHBSize& m)
00167     : MeritBase<View,double>(home,shared,m) {
00168     chb.update(home, shared, m.chb);
00169   }
00170   template<class View>
00171   forceinline double
00172   MeritCHBSize<View>::operator ()(const Space&, View x, int i) {
00173     return chb[i] / static_cast<double>(x.size());
00174   }
00175   template<class View>
00176   forceinline bool
00177   MeritCHBSize<View>::notice(void) const {
00178     return true;
00179   }
00180   template<class View>
00181   forceinline void
00182   MeritCHBSize<View>::dispose(Space&) {
00183     chb.~CHB();
00184   }
00185 
00186   // Minimum regret merit
00187   template<class View>
00188   forceinline
00189   MeritRegretMin<View>::MeritRegretMin(Space& home, const VarBranch<Var>& vb)
00190     : MeritBase<View,unsigned int>(home,vb) {}
00191   template<class View>
00192   forceinline
00193   MeritRegretMin<View>::MeritRegretMin(Space& home, bool shared, MeritRegretMin& m)
00194     : MeritBase<View,unsigned int>(home,shared,m) {}
00195   template<class View>
00196   forceinline unsigned int
00197   MeritRegretMin<View>::operator ()(const Space&, View x, int) {
00198     return x.regret_min();
00199   }
00200 
00201   // Maximum regret merit
00202   template<class View>
00203   forceinline
00204   MeritRegretMax<View>::MeritRegretMax(Space& home, const VarBranch<Var>& vb)
00205     : MeritBase<View,unsigned int>(home,vb) {}
00206   template<class View>
00207   forceinline
00208   MeritRegretMax<View>::MeritRegretMax(Space& home, bool shared, MeritRegretMax& m)
00209     : MeritBase<View,unsigned int>(home,shared,m) {}
00210   template<class View>
00211   forceinline unsigned int
00212   MeritRegretMax<View>::operator ()(const Space&, View x, int) {
00213     return x.regret_max();
00214   }
00215 
00216 }}}
00217 
00218 // STATISTICS: int-branch