/usr/include/gecode/kernel/brancher-merit.hpp is in libgecode-dev 5.1.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main author:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2012
*
* Last modified:
* $Date: 2017-03-01 04:28:36 +0100 (Wed, 01 Mar 2017) $ by $Author: schulte $
* $Revision: 15541 $
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
namespace Gecode {
/**
* \defgroup TaskBranchMerit Generic merit for branchers based on view and value selection
*
* \ingroup TaskBranchViewVal
*/
//@{
/**
* \brief Base-class for merit class
*/
template<class _View, class _Val>
class MeritBase {
public:
/// View type
typedef _View View;
/// Corresponding variable type
typedef typename View::VarType Var;
/// Type of merit
typedef _Val Val;
/// Constructor for initialization
MeritBase(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritBase(Space& home, bool share, MeritBase& mb);
/// Whether dispose must always be called (that is, notice is needed)
bool notice(void) const;
/// Delete view merit class
void dispose(Space& home);
};
/**
* \brief Merit class for user-defined merit function
*/
template<class View>
class MeritFunction : public MeritBase<View,double> {
using typename MeritBase<View,double>::Var;
public:
/// Corresponding merit function type
typedef typename BranchTraits<Var>::Merit Function;
protected:
/// The user-defined merit function
SharedData<Function> f;
public:
/// Constructor for initialization
MeritFunction(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritFunction(Space& home, bool shared, MeritFunction& mf);
/// Return degree as merit for view \a x at position \a i
double operator ()(const Space& home, View x, int i);
/// Whether dispose must always be called (that is, notice is needed)
bool notice(void) const;
/// Delete view merit class
void dispose(Space& home);
};
/**
* \brief Merit class for degree
*/
template<class View>
class MeritDegree : public MeritBase<View,unsigned int> {
using typename MeritBase<View,unsigned int>::Var;
public:
/// Constructor for initialization
MeritDegree(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritDegree(Space& home, bool shared, MeritDegree& md);
/// Return degree as merit for view \a x at position \a i
unsigned int operator ()(const Space& home, View x, int i);
};
/**
* \brief Merit class for AFC
*/
template<class View>
class MeritAFC : public MeritBase<View,double> {
using typename MeritBase<View,double>::Var;
protected:
/// AFC information
AFC afc;
public:
/// Constructor for initialization
MeritAFC(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritAFC(Space& home, bool shared, MeritAFC& ma);
/// Return AFC as merit for view \a x at position \a i
double operator ()(const Space& home, View x, int i);
/// Whether dispose must always be called (that is, notice is needed)
bool notice(void) const;
/// Dispose view selection
void dispose(Space& home);
};
/**
* \brief Merit class for action
*/
template<class View>
class MeritAction : public MeritBase<View,double> {
using typename MeritBase<View,double>::Var;
protected:
/// Action information
Action action;
public:
/// Constructor for initialization
MeritAction(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritAction(Space& home, bool shared, MeritAction& ma);
/// Return action as merit for view \a x at position \a i
double operator ()(const Space& home, View x, int i);
/// Whether dispose must always be called (that is, notice is needed)
bool notice(void) const;
/// Dispose view selection
void dispose(Space& home);
};
//@}
/**
* \brief Merit class for CHB
*/
template<class View>
class MeritCHB : public MeritBase<View,double> {
using typename MeritBase<View,double>::Var;
protected:
/// CHB information
CHB chb;
public:
/// Constructor for initialization
MeritCHB(Space& home, const VarBranch<Var>& vb);
/// Constructor for cloning
MeritCHB(Space& home, bool shared, MeritCHB& ma);
/// Return action as merit for view \a x at position \a i
double operator ()(const Space& home, View x, int i);
/// Whether dispose must always be called (that is, notice is needed)
bool notice(void) const;
/// Dispose view selection
void dispose(Space& home);
};
//@}
// Merit base class
template<class View, class Val>
forceinline
MeritBase<View,Val>::MeritBase(Space&, const VarBranch<Var>&) {}
template<class View, class Val>
forceinline
MeritBase<View,Val>::MeritBase(Space&, bool, MeritBase&) {}
template<class View, class Val>
forceinline bool
MeritBase<View,Val>::notice(void) const {
return false;
}
template<class View, class Val>
forceinline void
MeritBase<View,Val>::dispose(Space&) {}
// User-defined function merit
template<class View>
forceinline
MeritFunction<View>::MeritFunction(Space& home, const VarBranch<Var>& vb)
: MeritBase<View,double>(home,vb), f(vb.merit()) {
if (!f())
throw InvalidFunction("MeritFunction::MeritFunction");
}
template<class View>
forceinline
MeritFunction<View>::MeritFunction(Space& home, bool shared,
MeritFunction& mf)
: MeritBase<View,double>(home,shared,mf) {
f.update(home,shared,mf.f);
}
template<class View>
forceinline double
MeritFunction<View>::operator ()(const Space& home, View x, int i) {
typename View::VarType y(x.varimp());
GECODE_VALID_FUNCTION(f());
return f()(home,y,i);
}
template<class View>
forceinline bool
MeritFunction<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
MeritFunction<View>::dispose(Space&) {
f.~SharedData<Function>();
}
// Degree merit
template<class View>
forceinline
MeritDegree<View>::MeritDegree(Space& home, const VarBranch<Var>& vb)
: MeritBase<View,unsigned int>(home,vb) {}
template<class View>
forceinline
MeritDegree<View>::MeritDegree(Space& home, bool shared,
MeritDegree& md)
: MeritBase<View,unsigned int>(home,shared,md) {}
template<class View>
forceinline unsigned int
MeritDegree<View>::operator ()(const Space&, View x, int) {
return x.degree();
}
// AFC merit
template<class View>
forceinline
MeritAFC<View>::MeritAFC(Space& home, const VarBranch<Var>& vb)
: MeritBase<View,double>(home,vb), afc(vb.afc()) {}
template<class View>
forceinline
MeritAFC<View>::MeritAFC(Space& home, bool shared,
MeritAFC& ma)
: MeritBase<View,double>(home,shared,ma) {
afc.update(home,shared,ma.afc);
}
template<class View>
forceinline double
MeritAFC<View>::operator ()(const Space&, View x, int) {
return x.afc();
}
template<class View>
forceinline bool
MeritAFC<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
MeritAFC<View>::dispose(Space&) {
afc.~AFC();
}
// Action merit
template<class View>
forceinline
MeritAction<View>::MeritAction(Space& home, const VarBranch<Var>& vb)
: MeritBase<View,double>(home,vb), action(vb.action()) {}
template<class View>
forceinline
MeritAction<View>::MeritAction(Space& home, bool shared,
MeritAction& ma)
: MeritBase<View,double>(home,shared,ma) {
action.update(home, shared, ma.action);
}
template<class View>
forceinline double
MeritAction<View>::operator ()(const Space&, View, int i) {
return action[i];
}
template<class View>
forceinline bool
MeritAction<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
MeritAction<View>::dispose(Space&) {
action.~Action();
}
// CHB merit
template<class View>
forceinline
MeritCHB<View>::MeritCHB(Space& home, const VarBranch<Var>& vb)
: MeritBase<View,double>(home,vb), chb(vb.chb()) {}
template<class View>
forceinline
MeritCHB<View>::MeritCHB(Space& home, bool shared,
MeritCHB& ma)
: MeritBase<View,double>(home,shared,ma) {
chb.update(home, shared, ma.chb);
}
template<class View>
forceinline double
MeritCHB<View>::operator ()(const Space&, View, int i) {
return chb[i];
}
template<class View>
forceinline bool
MeritCHB<View>::notice(void) const {
return true;
}
template<class View>
forceinline void
MeritCHB<View>::dispose(Space&) {
chb.~CHB();
}
}
// STATISTICS: kernel-branch
|