Generated on Fri Mar 20 15:55:58 2015 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: 2013-02-19 13:26:08 +0100 (Tue, 19 Feb 2013) $ by $Author: schulte $
00011  *     $Revision: 13313 $
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& 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& 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& 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& 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& 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& home, View x, int) {
00115     return x.afc(home) / 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   // Activity over size merit
00129   template<class View>
00130   forceinline
00131   MeritActivitySize<View>::MeritActivitySize(Space& home,
00132                                              const VarBranch& vb)
00133     : MeritBase<View,double>(home,vb), activity(vb.activity()) {}
00134   template<class View>
00135   forceinline
00136   MeritActivitySize<View>::MeritActivitySize(Space& home, bool shared, 
00137                                              MeritActivitySize& m)
00138     : MeritBase<View,double>(home,shared,m) {
00139     activity.update(home, shared, m.activity);
00140   }
00141   template<class View>
00142   forceinline double
00143   MeritActivitySize<View>::operator ()(const Space&, View x, int i) {
00144     return activity[i] / static_cast<double>(x.size());
00145   }
00146   template<class View>
00147   forceinline bool
00148   MeritActivitySize<View>::notice(void) const {
00149     return true;
00150   }
00151   template<class View>
00152   forceinline void
00153   MeritActivitySize<View>::dispose(Space&) {
00154     activity.~Activity();
00155   }
00156 
00157   // Minimum regret merit
00158   template<class View>
00159   forceinline
00160   MeritRegretMin<View>::MeritRegretMin(Space& home, const VarBranch& vb)
00161     : MeritBase<View,unsigned int>(home,vb) {}
00162   template<class View>
00163   forceinline
00164   MeritRegretMin<View>::MeritRegretMin(Space& home, bool shared, MeritRegretMin& m)
00165     : MeritBase<View,unsigned int>(home,shared,m) {}
00166   template<class View>
00167   forceinline unsigned int
00168   MeritRegretMin<View>::operator ()(const Space&, View x, int) {
00169     return x.regret_min();
00170   }
00171 
00172   // Maximum regret merit
00173   template<class View>
00174   forceinline
00175   MeritRegretMax<View>::MeritRegretMax(Space& home, const VarBranch& vb)
00176     : MeritBase<View,unsigned int>(home,vb) {}
00177   template<class View>
00178   forceinline
00179   MeritRegretMax<View>::MeritRegretMax(Space& home, bool shared, MeritRegretMax& m)
00180     : MeritBase<View,unsigned int>(home,shared,m) {}
00181   template<class View>
00182   forceinline unsigned int
00183   MeritRegretMax<View>::operator ()(const Space&, View x, int) {
00184     return x.regret_max();
00185   }
00186 
00187 }}}
00188 
00189 // STATISTICS: int-branch