1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2 /* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Contributing authors: 7 * Vincent Barichard <Vincent.Barichard@univ-angers.fr> 8 * 9 * Copyright: 10 * Christian Schulte, 2012 11 * Vincent Barichard, 2012 12 * 13 * This file is part of Gecode, the generic constraint 14 * development environment: 15 * http://www.gecode.org 16 * 17 * Permission is hereby granted, free of charge, to any person obtaining 18 * a copy of this software and associated documentation files (the 19 * "Software"), to deal in the Software without restriction, including 20 * without limitation the rights to use, copy, modify, merge, publish, 21 * distribute, sublicense, and/or sell copies of the Software, and to 22 * permit persons to whom the Software is furnished to do so, subject to 23 * the following conditions: 24 * 25 * The above copyright notice and this permission notice shall be 26 * included in all copies or substantial portions of the Software. 27 * 28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 35 * 36 */ 37 38 namespace Gecode { namespace Float { namespace Branch { 39 40 // Minimum merit 41 forceinline MeritMin(Space & home,const VarBranch<Var> & vb)42 MeritMin::MeritMin(Space& home, const VarBranch<Var>& vb) 43 : MeritBase<FloatView,double>(home,vb) {} 44 forceinline MeritMin(Space & home,MeritMin & m)45 MeritMin::MeritMin(Space& home, MeritMin& m) 46 : MeritBase<FloatView,double>(home,m) {} 47 forceinline double operator ()(const Space &,FloatView x,int)48 MeritMin::operator ()(const Space&, FloatView x, int) { 49 return x.min(); 50 } 51 52 // Maximum merit 53 forceinline MeritMax(Space & home,const VarBranch<Var> & vb)54 MeritMax::MeritMax(Space& home, const VarBranch<Var>& vb) 55 : MeritBase<FloatView,double>(home,vb) {} 56 forceinline MeritMax(Space & home,MeritMax & m)57 MeritMax::MeritMax(Space& home, MeritMax& m) 58 : MeritBase<FloatView,double>(home,m) {} 59 forceinline double operator ()(const Space &,FloatView x,int)60 MeritMax::operator ()(const Space&, FloatView x, int) { 61 return x.max(); 62 } 63 64 // Size merit 65 forceinline MeritSize(Space & home,const VarBranch<Var> & vb)66 MeritSize::MeritSize(Space& home, const VarBranch<Var>& vb) 67 : MeritBase<FloatView,double>(home,vb) {} 68 forceinline MeritSize(Space & home,MeritSize & m)69 MeritSize::MeritSize(Space& home, MeritSize& m) 70 : MeritBase<FloatView,double>(home,m) {} 71 forceinline double operator ()(const Space &,FloatView x,int)72 MeritSize::operator ()(const Space&, FloatView x, int) { 73 return x.size(); 74 } 75 76 // Degree over size merit 77 forceinline MeritDegreeSize(Space & home,const VarBranch<Var> & vb)78 MeritDegreeSize::MeritDegreeSize(Space& home, const VarBranch<Var>& vb) 79 : MeritBase<FloatView,double>(home,vb) {} 80 forceinline MeritDegreeSize(Space & home,MeritDegreeSize & m)81 MeritDegreeSize::MeritDegreeSize(Space& home, 82 MeritDegreeSize& m) 83 : MeritBase<FloatView,double>(home,m) {} 84 forceinline double operator ()(const Space &,FloatView x,int)85 MeritDegreeSize::operator ()(const Space&, FloatView x, int) { 86 return x.size() / static_cast<double>(x.degree()); 87 } 88 89 // AFC over size merit 90 forceinline MeritAFCSize(Space & home,const VarBranch<Var> & vb)91 MeritAFCSize::MeritAFCSize(Space& home, const VarBranch<Var>& vb) 92 : MeritBase<FloatView,double>(home,vb), afc(vb.afc()) {} 93 forceinline MeritAFCSize(Space & home,MeritAFCSize & m)94 MeritAFCSize::MeritAFCSize(Space& home, MeritAFCSize& m) 95 : MeritBase<FloatView,double>(home,m), afc(m.afc) {} 96 forceinline double operator ()(const Space &,FloatView x,int)97 MeritAFCSize::operator ()(const Space&, FloatView x, int) { 98 return x.afc() / static_cast<double>(x.size()); 99 } 100 forceinline bool notice(void) const101 MeritAFCSize::notice(void) const { 102 return false; 103 } 104 forceinline void dispose(Space &)105 MeritAFCSize::dispose(Space&) { 106 // Not needed 107 afc.~AFC(); 108 } 109 110 // Action over size merit 111 forceinline MeritActionSize(Space & home,const VarBranch<Var> & vb)112 MeritActionSize::MeritActionSize(Space& home, 113 const VarBranch<Var>& vb) 114 : MeritBase<FloatView,double>(home,vb), action(vb.action()) {} 115 forceinline MeritActionSize(Space & home,MeritActionSize & m)116 MeritActionSize::MeritActionSize(Space& home, 117 MeritActionSize& m) 118 : MeritBase<FloatView,double>(home,m), action(m.action) {} 119 forceinline double operator ()(const Space &,FloatView x,int i)120 MeritActionSize::operator ()(const Space&, FloatView x, int i) { 121 return action[i] / static_cast<double>(x.size()); 122 } 123 forceinline bool notice(void) const124 MeritActionSize::notice(void) const { 125 return true; 126 } 127 forceinline void dispose(Space &)128 MeritActionSize::dispose(Space&) { 129 action.~Action(); 130 } 131 132 133 // CHB Q-score over size merit 134 forceinline MeritCHBSize(Space & home,const VarBranch<Var> & vb)135 MeritCHBSize::MeritCHBSize(Space& home, 136 const VarBranch<Var>& vb) 137 : MeritBase<FloatView,double>(home,vb), chb(vb.chb()) {} 138 forceinline MeritCHBSize(Space & home,MeritCHBSize & m)139 MeritCHBSize::MeritCHBSize(Space& home, 140 MeritCHBSize& m) 141 : MeritBase<FloatView,double>(home,m), chb(m.chb) {} 142 forceinline double operator ()(const Space &,FloatView x,int i)143 MeritCHBSize::operator ()(const Space&, FloatView x, int i) { 144 return chb[i] / static_cast<double>(x.size()); 145 } 146 forceinline bool notice(void) const147 MeritCHBSize::notice(void) const { 148 return true; 149 } 150 forceinline void dispose(Space &)151 MeritCHBSize::dispose(Space&) { 152 chb.~CHB(); 153 } 154 155 }}} 156 157 // STATISTICS: float-branch 158