8 #ifndef TRSL_IS_PICKED_SYSTEMATIC_HPP
9 #define TRSL_IS_PICKED_SYSTEMATIC_HPP
20 #include <boost/static_assert.hpp>
75 typename WeightType = double,
76 typename WeightAccessor = mp_weight_accessor<WeightType, ElementType>
80 BOOST_STATIC_ASSERT((std::numeric_limits<WeightType>::is_integer ==
false));
82 typedef ElementType element_type;
83 typedef WeightType weight_type;
84 typedef WeightAccessor weight_accessor_type;
125 WeightType populationWeight,
126 WeightAccessor
const& wac = WeightAccessor()) :
127 wac_(wac), sampleSize_(sampleSize),
128 populationWeight_(populationWeight)
130 initialize( rand_gen::uniform_01<WeightType>() );
165 WeightType populationWeight,
166 WeightType uniform01,
167 WeightAccessor
const& wac = WeightAccessor()) :
168 wac_(wac), sampleSize_(sampleSize),
169 populationWeight_(populationWeight)
171 initialize(uniform01);
183 if (sampleSize_ == 0)
return false;
185 #ifdef TRSL_USE_SYSTEMATIC_INTUITIVE_ALGORITHM
191 WeightType arrow = k_*step_;
192 assert(cumulative_ <= arrow);
193 if (arrow < cumulative_ + wac_(e))
198 cumulative_ += wac_(e);
204 assert(position_ >= 0);
205 if (position_ < wac_(e))
210 position_ -= wac_(e);
228 if (wac_(e) <= step_)
return true;
229 #ifdef TRSL_USE_SYSTEMATIC_INTUITIVE_ALGORITHM
230 return k_*step_ - cumulative_ < 2*step_;
232 return position_ < 2*step_;
245 if (sampleSize_ != p.sampleSize_ ||
246 populationWeight_ != p.populationWeight_)
return false;
248 #ifdef TRSL_USE_SYSTEMATIC_INTUITIVE_ALGORITHM
249 if (cumulative_ != p.cumulative_ ||
250 k_ != p.k_)
return false;
252 if (position_ != p.position_)
return false;
259 void initialize(WeightType randomReal)
277 if (sampleSize_ != 0)
278 step_ = populationWeight_ / sampleSize_;
285 WeightType randomWeight = randomReal * step_;
286 #ifdef TRSL_USE_SYSTEMATIC_INTUITIVE_ALGORITHM
287 cumulative_ = -randomWeight;
290 position_ = randomWeight;
297 WeightType populationWeight_;
300 #ifdef TRSL_USE_SYSTEMATIC_INTUITIVE_ALGORITHM
301 WeightType cumulative_;
304 WeightType position_;
320 template<
class Iterator>
323 return i.predicate().is_first_pick(*i);
328 #endif // include guard