Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
merit.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2012
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34namespace Gecode { namespace Int { namespace Branch {
35
36 // Minimum merit
37 template<class View>
40 (Space& home, const VarBranch<MeritMin<View>::Var>& vb)
41 : MeritBase<View,int>(home,vb) {}
42 template<class View>
45 : MeritBase<View,int>(home,m) {}
46 template<class View>
47 forceinline int
48 MeritMin<View>::operator ()(const Space&, View x, int) {
49 return x.min();
50 }
51
52 // Maximum merit
53 template<class View>
56 (Space& home, const VarBranch<MeritMax<View>::Var>& vb)
57 : MeritBase<View,int>(home,vb) {}
58 template<class View>
61 : MeritBase<View,int>(home,m) {}
62 template<class View>
63 forceinline int
64 MeritMax<View>::operator ()(const Space&, View x, int) {
65 return x.max();
66 }
67
68 // Size merit
69 template<class View>
72 (Space& home, const VarBranch<MeritSize<View>::Var>& vb)
73 : MeritBase<View,unsigned int>(home,vb) {}
74 template<class View>
77 : MeritBase<View,unsigned int>(home,m) {}
78 template<class View>
79 forceinline unsigned int
81 return x.size();
82 }
83
84 // Degree over size merit
85 template<class View>
89 : MeritBase<View,double>(home,vb) {}
90 template<class View>
94 template<class View>
95 forceinline double
97 return static_cast<double>(x.degree()) / static_cast<double>(x.size());
98 }
99
100 // AFC over size merit
101 template<class View>
104 (Space& home, const VarBranch<MeritAFCSize<View>::Var>& vb)
105 : MeritBase<View,double>(home,vb), afc(vb.afc()) {}
106 template<class View>
109 : MeritBase<View,double>(home,m), afc(m.afc) {}
110 template<class View>
111 forceinline double
113 return x.afc() / static_cast<double>(x.size());
114 }
115 template<class View>
116 forceinline bool
118 return false;
119 }
120 template<class View>
121 forceinline void
123 // Not needed
124 afc.~AFC();
125 }
126
127 // Action over size merit
128 template<class View>
131 (Space& home, const VarBranch<MeritActionSize<View>::Var>& vb)
132 : MeritBase<View,double>(home,vb), action(vb.action()) {}
133 template<class View>
136 : MeritBase<View,double>(home,m), action(m.action) {}
137 template<class View>
138 forceinline double
140 return action[i] / static_cast<double>(x.size());
141 }
142 template<class View>
143 forceinline bool
145 return true;
146 }
147 template<class View>
148 forceinline void
150 action.~Action();
151 }
152
153 // CHB over size merit
154 template<class View>
157 (Space& home, const VarBranch<MeritCHBSize<View>::Var>& vb)
158 : MeritBase<View,double>(home,vb), chb(vb.chb()) {}
159 template<class View>
162 : MeritBase<View,double>(home,m), chb(m.chb) {}
163 template<class View>
164 forceinline double
166 return chb[i] / static_cast<double>(x.size());
167 }
168 template<class View>
169 forceinline bool
171 return true;
172 }
173 template<class View>
174 forceinline void
176 chb.~CHB();
177 }
178
179 // Minimum regret merit
180 template<class View>
183 (Space& home, const VarBranch<MeritRegretMin<View>::Var>& vb)
184 : MeritBase<View,unsigned int>(home,vb) {}
185 template<class View>
188 : MeritBase<View,unsigned int>(home,m) {}
189 template<class View>
190 forceinline unsigned int
192 return x.regret_min();
193 }
194
195 // Maximum regret merit
196 template<class View>
199 (Space& home, const VarBranch<MeritRegretMax<View>::Var>& vb)
200 : MeritBase<View,unsigned int>(home,vb) {}
201 template<class View>
204 : MeritBase<View,unsigned int>(home,m) {}
205 template<class View>
206 forceinline unsigned int
208 return x.regret_max();
209 }
210
211}}}
212
213// STATISTICS: int-branch
Merit class for AFC over size.
Definition branch.hh:141
void dispose(Space &home)
Dispose view selection.
Definition merit.hpp:122
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition merit.hpp:117
double operator()(const Space &home, View x, int i)
Return AFC over size as merit for view x at position i.
Definition merit.hpp:112
MeritAFCSize(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Merit class for action over size.
Definition branch.hh:166
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition merit.hpp:144
MeritActionSize(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
double operator()(const Space &home, View x, int i)
Return action over size as merit for view x at position i.
Definition merit.hpp:139
void dispose(Space &home)
Dispose view selection.
Definition merit.hpp:149
Merit class for CHB over size.
Definition branch.hh:191
void dispose(Space &home)
Dispose view selection.
Definition merit.hpp:175
double operator()(const Space &home, View x, int i)
Return size over action as merit for view x at position i.
Definition merit.hpp:165
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition merit.hpp:170
MeritCHBSize(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Merit class for degree over size.
Definition branch.hh:123
double operator()(const Space &home, View x, int i)
Return degree over size as merit for view x at position i.
Definition merit.hpp:96
MeritDegreeSize(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
Merit class for maximum.
Definition branch.hh:87
MeritMax(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
int operator()(const Space &home, View x, int i)
Return maximum as merit for view x at position i.
Definition merit.hpp:64
Merit class for mimimum of integer views.
Definition branch.hh:69
MeritMin(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
int operator()(const Space &home, View x, int i)
Return minimum as merit for view x at position i.
Definition merit.hpp:48
Merit class for maximum regret.
Definition branch.hh:234
MeritRegretMax(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
unsigned int operator()(const Space &home, View x, int i)
Return maximum regret as merit for view x at position i.
Definition merit.hpp:207
Merit class for minimum regret.
Definition branch.hh:216
MeritRegretMin(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
unsigned int operator()(const Space &home, View x, int i)
Return minimum regret as merit for view x at position i.
Definition merit.hpp:191
Merit class for size.
Definition branch.hh:105
MeritSize(Space &home, const VarBranch< Var > &vb)
Constructor for initialization.
unsigned int operator()(const Space &home, View x, int i)
Return size as merit for view x at position i.
Definition merit.hpp:80
Base-class for merit class.
Definition merit.hpp:46
Computation spaces.
Definition core.hpp:1742
Variable branching information.
Definition var.hpp:55
unsigned int degree(void) const
Return degree (number of subscribed propagators and advisors)
Definition var.hpp:101
double afc(void) const
Return accumulated failure count.
Definition var.hpp:106
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:767
#define forceinline
Definition config.hpp:187