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