OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
SampleRandomizedSequence.h
Go to the documentation of this file.
1//
2// Class SampleRandomizedSequence
3// This class creates randomized sequences, i.e., it randomly picks values from
4// a sequence.
5//
6// Copyright (c) 2019, Matthias Frey, Paul Scherrer Institut, Villigen PSI, Switzerland
7// All rights reserved
8//
9// Implemented as part of the PhD thesis
10// "Precise Simulations of Multibunches in High Intensity Cyclotrons"
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_WEIGHTED_SEQUENCE_H
23#define OPAL_SAMPLE_WEIGHTED_SEQUENCE_H
24
25#include "Sample/Uniform.h"
26
27template <typename T>
29{
30
31public:
32
33 SampleRandomizedSequence(T lower, T upper, double step)
34 : unif_m(0, size_t((upper - lower) / step))
35 , lower_m(lower)
36 , step_m(step)
37 { }
38
39 SampleRandomizedSequence(T lower, T upper, double step, size_t seed)
40 : unif_m(0, size_t((upper - lower) / step), seed)
41 , lower_m(lower)
42 , step_m(step)
43 { }
44
45 void create(boost::shared_ptr<SampleIndividual>& ind, size_t i) {
46 size_t idx = unif_m.getNext();
47 ind->genes[i] = static_cast<T>(lower_m + idx * step_m);
48 }
49
50 void allocate(const CmdArguments_t& args, const Comm::Bundle_t& comm) {
51 unif_m.allocate(args, comm);
52 }
53
54private:
55 std::vector<T> points_m;
58 double step_m;
59};
60
61#endif
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:176
int seed
The current random seed.
Definition: Options.cpp:37
void create(boost::shared_ptr< SampleIndividual > &ind, size_t i)
SampleRandomizedSequence(T lower, T upper, double step)
SampleRandomizedSequence(T lower, T upper, double step, size_t seed)
void allocate(const CmdArguments_t &args, const Comm::Bundle_t &comm)
T getNext()
Definition: Uniform.h:66
void allocate(const CmdArguments_t &, const Comm::Bundle_t &comm)
Definition: Uniform.h:61
bundles all communicators for a specific role/pid
Definition: types.h:32