Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
merit.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main author:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2012
8  *
9  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 {
39 
49  template<class _View, class _Val>
50  class MeritBase {
51  public:
53  typedef _View View;
55  typedef typename View::VarType Var;
57  typedef _Val Val;
59  MeritBase(Space& home, const VarBranch<Var>& vb);
61  MeritBase(Space& home, MeritBase& mb);
63  bool notice(void) const;
65  void dispose(Space& home);
66  };
67 
71  template<class View>
72  class MeritFunction : public MeritBase<View,double> {
73  using typename MeritBase<View,double>::Var;
74  public:
77  protected:
80  public:
82  MeritFunction(Space& home, const VarBranch<Var>& vb);
84  MeritFunction(Space& home, MeritFunction& mf);
86  double operator ()(const Space& home, View x, int i);
88  bool notice(void) const;
90  void dispose(Space& home);
91  };
92 
96  template<class View>
97  class MeritDegree : public MeritBase<View,unsigned int> {
98  using typename MeritBase<View,unsigned int>::Var;
99  public:
101  MeritDegree(Space& home, const VarBranch<Var>& vb);
103  MeritDegree(Space& home, MeritDegree& md);
105  unsigned int operator ()(const Space& home, View x, int i);
106  };
107 
111  template<class View>
112  class MeritAFC : public MeritBase<View,double> {
113  using typename MeritBase<View,double>::Var;
114  protected:
117  public:
119  MeritAFC(Space& home, const VarBranch<Var>& vb);
121  MeritAFC(Space& home, MeritAFC& ma);
123  double operator ()(const Space& home, View x, int i);
125  bool notice(void) const;
127  void dispose(Space& home);
128  };
129 
133  template<class View>
134  class MeritAction : public MeritBase<View,double> {
135  using typename MeritBase<View,double>::Var;
136  protected:
139  public:
141  MeritAction(Space& home, const VarBranch<Var>& vb);
143  MeritAction(Space& home, MeritAction& ma);
145  double operator ()(const Space& home, View x, int i);
147  bool notice(void) const;
149  void dispose(Space& home);
150  };
152 
156  template<class View>
157  class MeritCHB : public MeritBase<View,double> {
158  using typename MeritBase<View,double>::Var;
159  protected:
162  public:
164  MeritCHB(Space& home, const VarBranch<Var>& vb);
166  MeritCHB(Space& home, MeritCHB& ma);
168  double operator ()(const Space& home, View x, int i);
170  bool notice(void) const;
172  void dispose(Space& home);
173  };
175 
176 
177  // Merit base class
178  template<class View, class Val>
181  template<class View, class Val>
184  template<class View, class Val>
185  forceinline bool
187  return false;
188  }
189  template<class View, class Val>
190  forceinline void
192 
193  // User-defined function merit
194  template<class View>
197  : MeritBase<View,double>(home,vb), f(vb.merit()) {
198  if (!f())
199  throw InvalidFunction("MeritFunction::MeritFunction");
200  }
201  template<class View>
204  : MeritBase<View,double>(home,mf), f(mf.f) {
205  }
206  template<class View>
207  forceinline double
209  typename View::VarType y(x.varimp());
211  return f()(home,y,i);
212  }
213  template<class View>
214  forceinline bool
216  return true;
217  }
218  template<class View>
219  forceinline void
222  }
223 
224 
225  // Degree merit
226  template<class View>
229  : MeritBase<View,unsigned int>(home,vb) {}
230  template<class View>
233  : MeritBase<View,unsigned int>(home,md) {}
234  template<class View>
235  forceinline unsigned int
237  return x.degree();
238  }
239 
240  // AFC merit
241  template<class View>
244  : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
245  template<class View>
248  : MeritBase<View,double>(home,ma), afc(ma.afc) {}
249  template<class View>
250  forceinline double
252  return x.afc();
253  }
254  template<class View>
255  forceinline bool
257  // Given that AFC is just a fake, this not really necessary
258  return false;
259  }
260  template<class View>
261  forceinline void
263  // Given that AFC is just a fake, this not really necessary
264  afc.~AFC();
265  }
266 
267 
268  // Action merit
269  template<class View>
272  : MeritBase<View,double>(home,vb), action(vb.action()) {}
273  template<class View>
276  : MeritBase<View,double>(home,ma), action(ma.action) {}
277  template<class View>
278  forceinline double
280  return action[i];
281  }
282  template<class View>
283  forceinline bool
285  return true;
286  }
287  template<class View>
288  forceinline void
290  action.~Action();
291  }
292 
293  // CHB merit
294  template<class View>
297  : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
298  template<class View>
301  : MeritBase<View,double>(home,ma), chb(ma.chb) {}
302  template<class View>
303  forceinline double
305  return chb[i];
306  }
307  template<class View>
308  forceinline bool
310  return true;
311  }
312  template<class View>
313  forceinline void
315  chb.~CHB();
316  }
317 
318 }
319 
320 // STATISTICS: kernel-branch
void dispose(Space &home)
Dispose view selection.
Definition: merit.hpp:314
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: merit.hpp:284
MeritDegree(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:228
BranchTraits< Var >::Merit Function
Corresponding merit function type.
Definition: merit.hpp:76
double operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
Definition: merit.hpp:208
CHB chb
CHB information.
Definition: merit.hpp:161
~Action(void)
Destructor.
Definition: action.cpp:59
Merit class for degree.
Definition: merit.hpp:97
AFC afc
Definition: afc.cpp:139
View::VarType Var
Corresponding variable type.
Definition: merit.hpp:55
MeritAction(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:271
Base-class for merit class.
Definition: merit.hpp:50
~AFC(void)
Destructor.
Definition: afc.hpp:161
unsigned int operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
Definition: merit.hpp:236
#define forceinline
Definition: config.hpp:182
MeritCHB(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:296
Computation spaces.
Definition: core.hpp:1668
Action action
Action information.
Definition: merit.hpp:138
Gecode::IntArgs i(4, 1, 2, 3, 4)
Class for AFC (accumulated failure count) management.
Definition: afc.hpp:44
~SharedData(void)
Destructors.
MeritFunction(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:196
double operator()(const Space &home, View x, int i)
Return action as merit for view x at position i.
Definition: merit.hpp:304
SharedData< Function > f
The user-defined merit function.
Definition: merit.hpp:79
Merit class for user-defined merit function.
Definition: merit.hpp:72
Class for CHB management.
Definition: chb.hpp:50
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: merit.hpp:309
~CHB(void)
Destructor.
Definition: chb.cpp:59
Exception: invalid function
Definition: exception.hpp:118
double operator()(const Space &home, View x, int i)
Return action as merit for view x at position i.
Definition: merit.hpp:279
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: merit.hpp:186
Merit class for AFC.
Definition: merit.hpp:112
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Variable branching information.
Definition: var.hpp:59
Set variables
Definition: set.hh:131
void dispose(Space &home)
Dispose view selection.
Definition: merit.hpp:289
void dispose(Space &home)
Dispose view selection.
Definition: merit.hpp:262
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: merit.hpp:215
AFC afc
AFC information.
Definition: merit.hpp:116
MeritBase(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:180
Post propagator for SetVar x
Definition: set.hh:769
MeritAFC(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Definition: merit.hpp:243
_View View
View type.
Definition: merit.hpp:53
void dispose(Space &home)
Delete view merit class.
Definition: merit.hpp:220
Gecode toplevel namespace
Class for action management.
Definition: action.hpp:46
void dispose(Space &home)
Delete view merit class.
Definition: merit.hpp:191
_Val Val
Type of merit.
Definition: merit.hpp:57
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: merit.hpp:256
double operator()(const Space &home, View x, int i)
Return AFC as merit for view x at position i.
Definition: merit.hpp:251
Traits for branching.
Definition: traits.hpp:59
Merit class for action.
Definition: merit.hpp:134
Merit class for CHB.
Definition: merit.hpp:157