Generated on Sat Feb 7 2015 02:01:27 for Gecode by doxygen 1.8.9.1
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: 2013-02-18 21:53:58 +0100 (Mon, 18 Feb 2013) $ by $Author: schulte $
11  * $Revision: 13310 $
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 _Val Val;
57  MeritBase(Space& home, const VarBranch& vb);
59  MeritBase(Space& home, bool share, MeritBase& mb);
61  bool notice(void) const;
63  void dispose(Space& home);
64  };
65 
69  template<class View>
70  class MeritFunction : public MeritBase<View,double> {
71  public:
73  typedef typename View::VarType Var;
76  protected:
78  Function f;
79  public:
81  MeritFunction(Space& home, const VarBranch& vb);
83  MeritFunction(Space& home, bool shared, MeritFunction& mf);
85  double operator ()(const Space& home, View x, int i);
86  };
87 
91  template<class View>
92  class MeritDegree : public MeritBase<View,unsigned int> {
93  public:
95  MeritDegree(Space& home, const VarBranch& vb);
97  MeritDegree(Space& home, bool shared, MeritDegree& md);
99  unsigned int operator ()(const Space& home, View x, int i);
100  };
101 
105  template<class View>
106  class MeritAFC : public MeritBase<View,double> {
107  protected:
110  public:
112  MeritAFC(Space& home, const VarBranch& vb);
114  MeritAFC(Space& home, bool shared, MeritAFC& ma);
116  double operator ()(const Space& home, View x, int i);
118  bool notice(void) const;
120  void dispose(Space& home);
121  };
122 
126  template<class View>
127  class MeritActivity : public MeritBase<View,double> {
128  protected:
131  public:
133  MeritActivity(Space& home, const VarBranch& vb);
135  MeritActivity(Space& home, bool shared, MeritActivity& ma);
137  double operator ()(const Space& home, View x, int i);
139  bool notice(void) const;
141  void dispose(Space& home);
142  };
144 
145 
146  // Merit base class
147  template<class View, class Val>
150  template<class View, class Val>
153  template<class View, class Val>
154  forceinline bool
156  return false;
157  }
158  template<class View, class Val>
159  forceinline void
161 
162  // User-defined function merit
163  template<class View>
166  : MeritBase<View,double>(home,vb),
167  f(function_cast<Function>(vb.merit())) {}
168  template<class View>
171  MeritFunction& mf)
172  : MeritBase<View,double>(home,shared,mf), f(mf.f) {}
173  template<class View>
174  forceinline double
176  typename View::VarType y(x.varimp());
177  return f(home,y,i);
178  }
179 
180  // Degree merit
181  template<class View>
184  : MeritBase<View,unsigned int>(home,vb) {}
185  template<class View>
188  MeritDegree& md)
189  : MeritBase<View,unsigned int>(home,shared,md) {}
190  template<class View>
191  forceinline unsigned int
193  return x.degree();
194  }
195 
196  // AFC merit
197  template<class View>
200  : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
201  template<class View>
204  MeritAFC& ma)
205  : MeritBase<View,double>(home,shared,ma) {
206  afc.update(home,shared,ma.afc);
207  }
208  template<class View>
209  forceinline double
211  return x.afc(home);
212  }
213  template<class View>
214  forceinline bool
216  return true;
217  }
218  template<class View>
219  forceinline void
221  afc.~AFC();
222  }
223 
224 
225  // Acitivity merit
226  template<class View>
229  : MeritBase<View,double>(home,vb), activity(vb.activity()) {}
230  template<class View>
233  MeritActivity& ma)
234  : MeritBase<View,double>(home,shared,ma) {
235  activity.update(home, shared, ma.activity);
236  }
237  template<class View>
238  forceinline double
240  return activity[i];
241  }
242  template<class View>
243  forceinline bool
245  return true;
246  }
247  template<class View>
248  forceinline void
250  activity.~Activity();
251  }
252 
253 }
254 
255 // STATISTICS: kernel-branch
void update(int i)
Update activity value at position i.
Definition: activity.hpp:303
BranchTraits< Var >::Merit Function
Corresponding merit function type.
MeritActivity(Space &home, const VarBranch &vb)
Constructor for initialization.
double operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
void dispose(Space &home)
Dispose view selection.
Merit class for degree.
AFC afc
Definition: afc.cpp:139
Base-class for merit class.
~AFC(void)
Destructor.
Definition: afc.hpp:154
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
unsigned int operator()(const Space &home, View x, int i)
Return degree as merit for view x at position i.
Computation spaces.
Definition: core.hpp:1362
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Merit class for activity.
Gecode::IntArgs i(4, 1, 2, 3, 4)
Class for AFC (accumulated failure count) management.
Definition: afc.hpp:44
Merit class for user-defined merit function.
double operator()(const Space &home, View x, int i)
Return activity as merit for view x at position i.
F1 function_cast(F2 f)
Cast function pointer.
Definition: cast.hpp:60
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
MeritFunction(Space &home, const VarBranch &vb)
Constructor for initialization.
Merit class for AFC.
MeritDegree(Space &home, const VarBranch &vb)
Constructor for initialization.
Function f
The user-defined merit function.
Variable branching information.
Definition: branch-var.hpp:55
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
void dispose(Space &home)
Dispose view selection.
AFC afc
AFC information.
#define forceinline
Definition: config.hpp:132
Activity activity
Activity information.
_View View
View type.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
MeritBase(Space &home, const VarBranch &vb)
Constructor for initialization.
Gecode toplevel namespace
void update(Space &home, bool share, AFC &a)
Updating during cloning.
Definition: afc.hpp:157
void dispose(Space &home)
Delete view merit class.
Class for activity management.
Definition: activity.hpp:44
_Val Val
Type of merit.
double operator()(const Space &home, View x, int i)
Return AFC as merit for view x at position i.
Traits for branching.
View::VarType Var
Corresponding variable type.
MeritAFC(Space &home, const VarBranch &vb)
Constructor for initialization.