Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
WeightsFileReader.h
1#ifndef SRC_CPP_LPNAMER_INPUTREADER_WEIGHTSFILEREADER_H
2#define SRC_CPP_LPNAMER_INPUTREADER_WEIGHTSFILEREADER_H
3#include <filesystem>
4#include <stdexcept>
5#include <vector>
6
7#include "antares-xpansion/lpnamer/helper/ProblemGenerationLogger.h"
8#include "antares-xpansion/xpansion_interfaces/LogUtils.h"
9
11{
12private:
13 std::filesystem::path weights_file_path_;
14 size_t number_of_active_years_;
15 std::shared_ptr<ProblemGenerationLog::ProblemGenerationLogger> logger_;
16 bool null_weights = true;
17 std::vector<double> weights_list_;
18
19 int CountValues() const;
20 bool AreAllWeightsNull() const;
21 double GetWeightFromLine(const std::string& line, int idx) const;
22 void CheckValue(const double line, int idx);
23 void CheckFileIsNotEmpty(std::ifstream& file) const;
24
25public:
26 explicit WeightsFileReader(
27 const std::filesystem::path& weights_file_path,
28 const size_t number_of_active_years,
29 std::shared_ptr<ProblemGenerationLog::ProblemGenerationLogger> logger):
30 weights_file_path_(weights_file_path),
31 number_of_active_years_(number_of_active_years),
32 logger_(logger)
33 {
34 }
35
36 class WeightsFileError: public LogUtils::XpansionError<std::runtime_error>
37 {
38 using LogUtils::XpansionError<std::runtime_error>::XpansionError;
39 };
40
42 {
43 using WeightsFileError::WeightsFileError;
44 };
45
47 {
48 using WeightsFileError::WeightsFileError;
49 };
50
52 {
53 using WeightsFileError::WeightsFileError;
54 };
55
57 {
58 using WeightsFileError::WeightsFileError;
59 };
60
62 {
63 using WeightsFileError::WeightsFileError;
64 };
65
68 // column of non-negative weights
69 // sum of weights is positive
70 // nb_weight equal nb_active_yearse
72 bool CheckWeightsFile();
73
74 std::vector<double> WeightsList() const
75 {
76 return weights_list_;
77 }
78};
79#endif // SRC_CPP_LPNAMER_INPUTREADER_WEIGHTSFILEREADER_H
Definition WeightsFileReader.h:52
Definition WeightsFileReader.h:47
Definition WeightsFileReader.h:57
Definition WeightsFileReader.h:37
Definition WeightsFileReader.h:62
Definition WeightsFileReader.h:42
Definition WeightsFileReader.h:11
bool CheckWeightsFile()
checks that the yearly-weights file exists and has correct format:
Definition WeightsFileReader.cpp:9