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  *  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: 2013-07-01 09:17:01 +0200 (Mon, 01 Jul 2013) $ by $Author: tack $
00017  *     $Revision: 13742 $
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& 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& 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& 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   // Size over degree merit
00087   forceinline
00088   MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch& 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   // Size over AFC merit
00101   forceinline
00102   MeritAFCSize::MeritAFCSize(Space& home, const VarBranch& 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& home, SetView x, int) {
00111     return static_cast<double>(x.unknownSize()) / x.afc(home);
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   // Size over activity merit
00123   forceinline
00124   MeritActivitySize::MeritActivitySize(Space& home,
00125                                        const VarBranch& vb)
00126     : MeritBase<SetView,double>(home,vb), activity(vb.activity()) {}
00127   forceinline
00128   MeritActivitySize::MeritActivitySize(Space& home, bool shared, 
00129                                        MeritActivitySize& m)
00130     : MeritBase<SetView,double>(home,shared,m) {
00131     activity.update(home, shared, m.activity);
00132   }
00133   forceinline double
00134   MeritActivitySize::operator ()(const Space&, SetView x, int i) {
00135     return activity[i] / static_cast<double>(x.unknownSize());
00136   }
00137   forceinline bool
00138   MeritActivitySize::notice(void) const {
00139     return true;
00140   }
00141   forceinline void
00142   MeritActivitySize::dispose(Space&) {
00143     activity.~Activity();
00144   }
00145 
00146 }}}
00147 
00148 // STATISTICS: set-branch