OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SampleSequence.h
Go to the documentation of this file.
1//
2// Class SampleSequence
3// This class provides a sequence of equidistant sampling points. It
4// can't be garanteed that the sampling is equidistant if
5// an integer type is chosen and the difference between
6// the upper and lower limit isn't divisible by the number
7// of sampling points.
8//
9// Copyright (c) 2018, Christof Metzger-Kraus, Open Sourcerer
10// All rights reserved
11//
12// This file is part of OPAL.
13//
14// OPAL is free software: you can redistribute it and/or modify
15// it under the terms of the GNU General Public License as published by
16// the Free Software Foundation, either version 3 of the License, or
17// (at your option) any later version.
18//
19// You should have received a copy of the GNU General Public License
20// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
21//
22#ifndef OPAL_SAMPLE_SEQUENCE_H
23#define OPAL_SAMPLE_SEQUENCE_H
24
26
27template <typename T>
29{
30
31public:
32
33 SampleSequence(T lower, T upper, size_t modulo, int nSample)
34 : lowerLimit_m(lower)
35 , stepSize_m( (upper - lower) / double(nSample - 1) )
36 , numSamples_m(nSample)
38 { }
39
40 void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) {
41
42 unsigned int id = ind->id;
43
44 int bin = int(id / volumeLowerDimensions_m) % numSamples_m;
45
46 ind->genes[i] = static_cast<T>(lowerLimit_m + stepSize_m * bin);
47 }
48
49private:
51 double stepSize_m;
52 unsigned int numSamples_m; // size of this "dimension"
53 size_t volumeLowerDimensions_m; // the "volume" of the sampling space of the lower "dimensions"
54};
55
56#endif
SampleSequence(T lower, T upper, size_t modulo, int nSample)
void create(boost::shared_ptr< SampleIndividual > &ind, size_t i)
size_t volumeLowerDimensions_m
unsigned int numSamples_m