Generated on Sat Jan 20 2018 22:21:16 for Gecode by doxygen 1.8.13
brancher-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: 2017-03-01 04:28:36 +0100 (Wed, 01 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15541 $
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, bool share, 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, bool shared, 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, bool shared, 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, bool shared, 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, bool shared, 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, bool shared, 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  MeritFunction& mf)
205  : MeritBase<View,double>(home,shared,mf) {
206  f.update(home,shared,mf.f);
207  }
208  template<class View>
209  forceinline double
211  typename View::VarType y(x.varimp());
213  return f()(home,y,i);
214  }
215  template<class View>
216  forceinline bool
218  return true;
219  }
220  template<class View>
221  forceinline void
224  }
225 
226 
227  // Degree merit
228  template<class View>
231  : MeritBase<View,unsigned int>(home,vb) {}
232  template<class View>
235  MeritDegree& md)
236  : MeritBase<View,unsigned int>(home,shared,md) {}
237  template<class View>
238  forceinline unsigned int
240  return x.degree();
241  }
242 
243  // AFC merit
244  template<class View>
247  : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
248  template<class View>
251  MeritAFC& ma)
252  : MeritBase<View,double>(home,shared,ma) {
253  afc.update(home,shared,ma.afc);
254  }
255  template<class View>
256  forceinline double
258  return x.afc();
259  }
260  template<class View>
261  forceinline bool
263  return true;
264  }
265  template<class View>
266  forceinline void
268  afc.~AFC();
269  }
270 
271 
272  // Action merit
273  template<class View>
276  : MeritBase<View,double>(home,vb), action(vb.action()) {}
277  template<class View>
280  MeritAction& ma)
281  : MeritBase<View,double>(home,shared,ma) {
282  action.update(home, shared, ma.action);
283  }
284  template<class View>
285  forceinline double
287  return action[i];
288  }
289  template<class View>
290  forceinline bool
292  return true;
293  }
294  template<class View>
295  forceinline void
297  action.~Action();
298  }
299 
300  // CHB merit
301  template<class View>
304  : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
305  template<class View>
308  MeritCHB& ma)
309  : MeritBase<View,double>(home,shared,ma) {
310  chb.update(home, shared, ma.chb);
311  }
312  template<class View>
313  forceinline double
315  return chb[i];
316  }
317  template<class View>
318  forceinline bool
320  return true;
321  }
322  template<class View>
323  forceinline void
325  chb.~CHB();
326  }
327 
328 }
329 
330 // STATISTICS: kernel-branch
void dispose(Space &home)
Dispose view selection.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
MeritDegree(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
BranchTraits< Var >::Merit Function
Corresponding merit function type.
void update(Space &home, bool share, SharedHandle &sh)
Update during cloning.
double operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
CHB chb
CHB information.
~Action(void)
Destructor.
Definition: action.cpp:74
void update(int i)
Update chb value at position i.
Merit class for degree.
AFC afc
Definition: afc.cpp:139
View::VarType Var
Corresponding variable type.
MeritAction(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Base-class for merit class.
~AFC(void)
Destructor.
Definition: afc.hpp:152
unsigned int operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
MeritCHB(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Computation spaces.
Definition: core.hpp:1748
Action action
Action information.
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.
double operator()(const Space &home, View x, int i)
Return action as merit for view x at position i.
void update(int i)
Update action value at position i.
Definition: action.hpp:306
SharedData< Function > f
The user-defined merit function.
Merit class for user-defined merit function.
Class for CHB management.
Definition: chb.hpp:50
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
~CHB(void)
Destructor.
Definition: chb.cpp:74
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.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Merit class for AFC.
#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:784
Variable branching information.
Definition: branch-var.hpp:59
Set variables
Definition: set.hh:131
void dispose(Space &home)
Dispose view selection.
void dispose(Space &home)
Dispose view selection.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
AFC afc
AFC information.
MeritBase(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
MeritAFC(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
_View View
View type.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
void dispose(Space &home)
Delete view merit class.
Gecode toplevel namespace
Class for action management.
Definition: action.hpp:46
void update(Space &home, bool share, AFC &a)
Updating during cloning.
Definition: afc.hpp:155
void dispose(Space &home)
Delete view merit class.
_Val Val
Type of merit.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
double operator()(const Space &home, View x, int i)
Return AFC as merit for view x at position i.
Traits for branching.
Merit class for action.
Merit class for CHB.