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  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00008  *
00009  *  Copyright:
00010  *     Christian Schulte, 2012
00011  *     Vincent Barichard, 2012
00012  *
00013  *  Last modified:
00014  *     $Date: 2013-06-13 20:53:42 +0200 (Thu, 13 Jun 2013) $ by $Author: tack $
00015  *     $Revision: 13706 $
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& 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& 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& 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   // Size over degree merit
00081   forceinline
00082   MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch& 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   // Size over AFC merit
00094   forceinline
00095   MeritAFCSize::MeritAFCSize(Space& home, const VarBranch& 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& home, FloatView x, int) {
00104     return x.size() / x.afc(home);
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   // Size over activity merit
00116   forceinline
00117   MeritActivitySize::MeritActivitySize(Space& home,
00118                                        const VarBranch& vb)
00119     : MeritBase<FloatView,double>(home,vb), activity(vb.activity()) {}
00120   forceinline
00121   MeritActivitySize::MeritActivitySize(Space& home, bool shared, 
00122                                        MeritActivitySize& m)
00123     : MeritBase<FloatView,double>(home,shared,m) {
00124     activity.update(home, shared, m.activity);
00125   }
00126   forceinline double
00127   MeritActivitySize::operator ()(const Space&, FloatView x, int i) {
00128     return activity[i] / static_cast<double>(x.size());
00129   }
00130   forceinline bool
00131   MeritActivitySize::notice(void) const {
00132     return true;
00133   }
00134   forceinline void
00135   MeritActivitySize::dispose(Space&) {
00136     activity.~Activity();
00137   }
00138 
00139 }}}
00140 
00141 // STATISTICS: float-branch