Generated on Tue May 22 09:39:44 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  *  Contributing authors:
00007  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2012
00011  *     Vincent Barichard, 2012
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 Float { namespace Branch {
00039 
00040   // Minimum merit
00041   forceinline
00042   MeritMin::MeritMin(Space& home, const VarBranch<Var>& vb)
00043     : MeritBase<FloatView,double>(home,vb) {}
00044   forceinline
00045   MeritMin::MeritMin(Space& home, MeritMin& m)
00046     : MeritBase<FloatView,double>(home,m) {}
00047   forceinline double
00048   MeritMin::operator ()(const Space&, FloatView x, int) {
00049     return x.min();
00050   }
00051 
00052   // Maximum merit
00053   forceinline
00054   MeritMax::MeritMax(Space& home, const VarBranch<Var>& vb)
00055     : MeritBase<FloatView,double>(home,vb) {}
00056   forceinline
00057   MeritMax::MeritMax(Space& home, MeritMax& m)
00058     : MeritBase<FloatView,double>(home,m) {}
00059   forceinline double
00060   MeritMax::operator ()(const Space&, FloatView x, int) {
00061     return x.max();
00062   }
00063 
00064   // Size merit
00065   forceinline
00066   MeritSize::MeritSize(Space& home, const VarBranch<Var>& vb)
00067     : MeritBase<FloatView,double>(home,vb) {}
00068   forceinline
00069   MeritSize::MeritSize(Space& home, MeritSize& m)
00070     : MeritBase<FloatView,double>(home,m) {}
00071   forceinline double
00072   MeritSize::operator ()(const Space&, FloatView x, int) {
00073     return x.size();
00074   }
00075 
00076   // Degree over size merit
00077   forceinline
00078   MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch<Var>& vb)
00079     : MeritBase<FloatView,double>(home,vb) {}
00080   forceinline
00081   MeritDegreeSize::MeritDegreeSize(Space& home,
00082                                    MeritDegreeSize& m)
00083     : MeritBase<FloatView,double>(home,m) {}
00084   forceinline double
00085   MeritDegreeSize::operator ()(const Space&, FloatView x, int) {
00086     return x.size() / static_cast<double>(x.degree());
00087   }
00088 
00089   // AFC over size merit
00090   forceinline
00091   MeritAFCSize::MeritAFCSize(Space& home, const VarBranch<Var>& vb)
00092     : MeritBase<FloatView,double>(home,vb), afc(vb.afc()) {}
00093   forceinline
00094   MeritAFCSize::MeritAFCSize(Space& home, MeritAFCSize& m)
00095     : MeritBase<FloatView,double>(home,m), afc(m.afc) {}
00096   forceinline double
00097   MeritAFCSize::operator ()(const Space&, FloatView x, int) {
00098     return x.afc() / static_cast<double>(x.size());
00099   }
00100   forceinline bool
00101   MeritAFCSize::notice(void) const {
00102     return false;
00103   }
00104   forceinline void
00105   MeritAFCSize::dispose(Space&) {
00106     // Not needed
00107     afc.~AFC();
00108   }
00109 
00110   // Action over size merit
00111   forceinline
00112   MeritActionSize::MeritActionSize(Space& home,
00113                                    const VarBranch<Var>& vb)
00114     : MeritBase<FloatView,double>(home,vb), action(vb.action()) {}
00115   forceinline
00116   MeritActionSize::MeritActionSize(Space& home,
00117                                    MeritActionSize& m)
00118     : MeritBase<FloatView,double>(home,m), action(m.action) {}
00119   forceinline double
00120   MeritActionSize::operator ()(const Space&, FloatView x, int i) {
00121     return action[i] / static_cast<double>(x.size());
00122   }
00123   forceinline bool
00124   MeritActionSize::notice(void) const {
00125     return true;
00126   }
00127   forceinline void
00128   MeritActionSize::dispose(Space&) {
00129     action.~Action();
00130   }
00131 
00132 
00133   // CHB Q-score over size merit
00134   forceinline
00135   MeritCHBSize::MeritCHBSize(Space& home,
00136                              const VarBranch<Var>& vb)
00137     : MeritBase<FloatView,double>(home,vb), chb(vb.chb()) {}
00138   forceinline
00139   MeritCHBSize::MeritCHBSize(Space& home,
00140                              MeritCHBSize& m)
00141     : MeritBase<FloatView,double>(home,m), chb(m.chb) {}
00142   forceinline double
00143   MeritCHBSize::operator ()(const Space&, FloatView x, int i) {
00144     return chb[i] / static_cast<double>(x.size());
00145   }
00146   forceinline bool
00147   MeritCHBSize::notice(void) const {
00148     return true;
00149   }
00150   forceinline void
00151   MeritCHBSize::dispose(Space&) {
00152     chb.~CHB();
00153   }
00154 
00155 }}}
00156 
00157 // STATISTICS: float-branch