|
OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
|
Sampling method that reads design variable values from a text file. More...
#include <FromFile.h>
Public Member Functions | |
| FromFile (const std::string &filename, const std::string &dvarName, std::size_t modulo) | |
| ~FromFile () override=default | |
| Destructor. | |
| FromFile (const FromFile &)=delete | |
| FromFile & | operator= (const FromFile &)=delete |
| FromFile (FromFile &&) noexcept=default | |
| FromFile & | operator= (FromFile &&) noexcept=default |
| void | create (std::shared_ptr< SampleIndividual > &ind, std::size_t i) override |
| Assign a sampled value to an individual's gene. | |
| void | allocate (const CmdArguments_t &args, const Comm::Bundle_t &comm) override |
| Parses and loads the data from the file into memory. | |
| double | getNext (unsigned int id) |
| Returns the next value for the given individual ID. | |
| unsigned int | getSize () const |
| Get the number of lines in the file (including the header). | |
| Expressions::Result_t | operator() (client::function::arguments_t args) |
| virtual void | create (std::shared_ptr< SampleIndividual > &ind, size_t i)=0 |
Static Public Attributes | |
| static const std::string | name |
Private Member Functions | |
| void | readValues () |
| reads a simple list of double values | |
Private Attributes | |
| std::vector< double > | chain_m |
| The values for the selected design variable loaded from the file. | |
| std::size_t | mod_m |
| Modulo used to wrap indices. | |
| std::string | filename_m |
| File name where samples are read from. | |
| std::string | dvarName_m |
| Name of the design variable to extract. | |
| std::size_t | globalSize_m |
| Number of lines in the file (including header). | |
| std::vector< double > | values_ |
| std::string | filename_ |
Sampling method that reads design variable values from a text file.
This class parses a file containing design variable samples. Each column corresponds to a variable, and the first line must contain the names of the variables. It supports selecting a specific column and accessing values sequentially or cyclically.
The expected file format is:
where "a", "b", "c" are variable names and subsequent lines are numerical values.
Definition at line 50 of file src/Sample/FromFile.h.
|
explicit |
Definition at line 34 of file src/Sample/FromFile.cpp.
References dvarName_m, filename_m, globalSize_m, and mod_m.
Referenced by FromFile(), FromFile(), operator=(), and operator=().
|
overridedefault |
Destructor.
|
delete |
|
defaultnoexcept |
|
overridevirtual |
Parses and loads the data from the file into memory.
| args | Command-line arguments (unused here). |
| comm | Communication context (unused here). |
| OpalException | if the file is invalid or the variable is missing. |
Reimplemented from SamplingMethod.
Definition at line 64 of file src/Sample/FromFile.cpp.
References chain_m, dvarName_m, filename_m, and globalSize_m.
Referenced by operator=().
|
override |
Assign a sampled value to an individual's gene.
| ind | The individual to modify. |
| i | Index of the gene (design variable) to assign. |
Definition at line 60 of file src/Sample/FromFile.cpp.
References getNext().
Referenced by operator=().
|
pure virtualinherited |
Implemented in Normal, SampleGaussianSequence, SampleRandomizedSequence< T >, SampleSequence< T >, Uniform< T >, and Uniform< size_t >.
| double FromFile::getNext | ( | unsigned int | id | ) |
Returns the next value for the given individual ID.
The value is selected cyclically from the chain.
| id | The individual's ID. |
Definition at line 126 of file src/Sample/FromFile.cpp.
References chain_m, dvarName_m, filename_m, globalSize_m, and mod_m.
Referenced by create(), and operator=().
| unsigned int FromFile::getSize | ( | ) | const |
Get the number of lines in the file (including the header).
Definition at line 137 of file src/Sample/FromFile.cpp.
References globalSize_m.
Referenced by OpalSample::initialize(), and operator=().
|
inline |
Definition at line 48 of file optimizer/Expression/FromFile.h.
References filename_, readValues(), sum(), and values_.
References allocate(), create(), FromFile(), getNext(), and getSize().
|
private |
reads a simple list of double values
Definition at line 29 of file optimizer/Expression/FromFile.cpp.
References filename_, and values_.
Referenced by operator()().
|
private |
The values for the selected design variable loaded from the file.
Definition at line 103 of file src/Sample/FromFile.h.
Referenced by allocate(), and getNext().
|
private |
Name of the design variable to extract.
Definition at line 112 of file src/Sample/FromFile.h.
Referenced by allocate(), FromFile(), and getNext().
|
private |
Definition at line 76 of file optimizer/Expression/FromFile.h.
Referenced by operator()(), and readValues().
|
private |
File name where samples are read from.
Definition at line 109 of file src/Sample/FromFile.h.
Referenced by allocate(), FromFile(), and getNext().
|
private |
Number of lines in the file (including header).
Definition at line 115 of file src/Sample/FromFile.h.
Referenced by allocate(), FromFile(), getNext(), and getSize().
|
private |
Modulo used to wrap indices.
Definition at line 106 of file src/Sample/FromFile.h.
Referenced by FromFile(), and getNext().
|
static |
Definition at line 46 of file optimizer/Expression/FromFile.h.
|
private |
Definition at line 74 of file optimizer/Expression/FromFile.h.
Referenced by operator()(), and readValues().