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