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  *  Contributing authors:
00007  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2012
00011  *     Vincent Barichard, 2012
00012  *
00013  *  Last modified:
00014  *     $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
00015  *     $Revision: 15623 $
00016  *
00017  *  This file is part of Gecode, the generic constraint
00018  *  development environment:
00019  *     http://www.gecode.org
00020  *
00021  *  Permission is hereby granted, free of charge, to any person obtaining
00022  *  a copy of this software and associated documentation files (the
00023  *  "Software"), to deal in the Software without restriction, including
00024  *  without limitation the rights to use, copy, modify, merge, publish,
00025  *  distribute, sublicense, and/or sell copies of the Software, and to
00026  *  permit persons to whom the Software is furnished to do so, subject to
00027  *  the following conditions:
00028  *
00029  *  The above copyright notice and this permission notice shall be
00030  *  included in all copies or substantial portions of the Software.
00031  *
00032  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00033  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00034  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00035  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00036  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00037  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00038  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00039  *
00040  */
00041 
00042 namespace Gecode { namespace Float { namespace Branch {
00043 
00044   // Minimum merit
00045   forceinline
00046   MeritMin::MeritMin(Space& home, const VarBranch<Var>& vb)
00047     : MeritBase<FloatView,double>(home,vb) {}
00048   forceinline
00049   MeritMin::MeritMin(Space& home, bool shared, MeritMin& m)
00050     : MeritBase<FloatView,double>(home,shared,m) {}
00051   forceinline double
00052   MeritMin::operator ()(const Space&, FloatView x, int) {
00053     return x.min();
00054   }
00055 
00056   // Maximum merit
00057   forceinline
00058   MeritMax::MeritMax(Space& home, const VarBranch<Var>& vb)
00059     : MeritBase<FloatView,double>(home,vb) {}
00060   forceinline
00061   MeritMax::MeritMax(Space& home, bool shared, MeritMax& m)
00062     : MeritBase<FloatView,double>(home,shared,m) {}
00063   forceinline double
00064   MeritMax::operator ()(const Space&, FloatView x, int) {
00065     return x.max();
00066   }
00067 
00068   // Size merit
00069   forceinline
00070   MeritSize::MeritSize(Space& home, const VarBranch<Var>& vb)
00071     : MeritBase<FloatView,double>(home,vb) {}
00072   forceinline
00073   MeritSize::MeritSize(Space& home, bool shared, MeritSize& m)
00074     : MeritBase<FloatView,double>(home,shared,m) {}
00075   forceinline double
00076   MeritSize::operator ()(const Space&, FloatView x, int) {
00077     return x.size();
00078   }
00079 
00080   // Degree over size merit
00081   forceinline
00082   MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch<Var>& vb)
00083     : MeritBase<FloatView,double>(home,vb) {}
00084   forceinline
00085   MeritDegreeSize::MeritDegreeSize(Space& home, bool shared,
00086                                    MeritDegreeSize& m)
00087     : MeritBase<FloatView,double>(home,shared,m) {}
00088   forceinline double
00089   MeritDegreeSize::operator ()(const Space&, FloatView x, int) {
00090     return x.size() / static_cast<double>(x.degree());
00091   }
00092 
00093   // AFC over size merit
00094   forceinline
00095   MeritAFCSize::MeritAFCSize(Space& home, const VarBranch<Var>& vb)
00096     : MeritBase<FloatView,double>(home,vb), afc(vb.afc()) {}
00097   forceinline
00098   MeritAFCSize::MeritAFCSize(Space& home, bool shared, MeritAFCSize& m)
00099     : MeritBase<FloatView,double>(home,shared,m) {
00100     afc.update(home,shared,m.afc);
00101   }
00102   forceinline double
00103   MeritAFCSize::operator ()(const Space&, FloatView x, int) {
00104     return x.afc() / static_cast<double>(x.size());
00105   }
00106   forceinline bool
00107   MeritAFCSize::notice(void) const {
00108     return true;
00109   }
00110   forceinline void
00111   MeritAFCSize::dispose(Space&) {
00112     afc.~AFC();
00113   }
00114 
00115   // Action over size merit
00116   forceinline
00117   MeritActionSize::MeritActionSize(Space& home,
00118                                    const VarBranch<Var>& vb)
00119     : MeritBase<FloatView,double>(home,vb), action(vb.action()) {}
00120   forceinline
00121   MeritActionSize::MeritActionSize(Space& home, bool shared,
00122                                    MeritActionSize& m)
00123     : MeritBase<FloatView,double>(home,shared,m) {
00124     action.update(home, shared, m.action);
00125   }
00126   forceinline double
00127   MeritActionSize::operator ()(const Space&, FloatView x, int i) {
00128     return action[i] / static_cast<double>(x.size());
00129   }
00130   forceinline bool
00131   MeritActionSize::notice(void) const {
00132     return true;
00133   }
00134   forceinline void
00135   MeritActionSize::dispose(Space&) {
00136     action.~Action();
00137   }
00138 
00139 
00140   // CHB Q-score over size merit
00141   forceinline
00142   MeritCHBSize::MeritCHBSize(Space& home,
00143                              const VarBranch<Var>& vb)
00144     : MeritBase<FloatView,double>(home,vb), chb(vb.chb()) {}
00145   forceinline
00146   MeritCHBSize::MeritCHBSize(Space& home, bool shared,
00147                              MeritCHBSize& m)
00148     : MeritBase<FloatView,double>(home,shared,m) {
00149     chb.update(home, shared, m.chb);
00150   }
00151   forceinline double
00152   MeritCHBSize::operator ()(const Space&, FloatView x, int i) {
00153     return chb[i] / static_cast<double>(x.size());
00154   }
00155   forceinline bool
00156   MeritCHBSize::notice(void) const {
00157     return true;
00158   }
00159   forceinline void
00160   MeritCHBSize::dispose(Space&) {
00161     chb.~CHB();
00162   }
00163 
00164 }}}
00165 
00166 // STATISTICS: float-branch