Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
MergeMasterMPS.h
1#pragma once
2
3#include "antares-xpansion/benders/merge_master_mps/MasterStructureKeys.h"
4#include "antares-xpansion/benders/merge_master_mps/NodeLpDataLocation.h"
5#include "antares-xpansion/benders/merge_mps/MergeMPS.h"
6
7constexpr char TRAJECTORY_LOGGER_CONTEXT[] = "MergeMasterTrajectoryMPS";
8
9// Probably needs to be changed
10class InvalidMasterStructureFileException: public std::runtime_error
11{
12public:
13 explicit InvalidMasterStructureFileException(const std::string& arg):
14 std::runtime_error(arg)
15 {
16 }
17};
18
20{
21public:
22 // Data structures
23 enum CandidateVariableType
24 {
25 CAPACITY,
26 DX_PLUS,
27 DX_MINUS
28 };
29
30 static CandidateVariableType parse_variable_type(const std::string& s);
31 static char parse_constraint_type(const std::string& s);
32
33 // This structure contains the position of the variables in the merged problem
34 // Its capacity, corresponding dx_plus and dx_minus
36 {
37 int capacity{-1};
38 int dx_plus{-1};
39 int dx_minus{-1};
40
41 int get(CandidateVariableType t) const;
42 void set(CandidateVariableType t, int i);
43 };
44
45 // candidate_name -> node_name -> variable_positions
46 using CandidatesCouplingMap = std::map<std::string, std::map<std::string, VariablePositions>>;
47
48 // Contains the cost data of a candidate
50 {
51 explicit CandidateCosts(const Json::Value& data);
52 double operation_maintenance{0.};
53 double investment{0.};
54 double retirement{0.};
55
56 // Get the cost associated with one of the types of variable
57 double get(CandidateVariableType t) const;
58 };
59
60 // Reference to a candidate
61 using VariableRef = std::tuple<std::string, std::string, CandidateVariableType>;
62
63 // Trajectory constraints
65 {
66 explicit TrajectoryConstraint(const Json::Value& data);
67
68 std::map<VariableRef, double> coefficients_map;
69 double rhs{0.};
70 char constraint_type;
71 };
72
74 {
75 TrajectoryGlobalData() = default;
76 explicit TrajectoryGlobalData(const Json::Value& data);
77
78 std::map<std::string, double> initial_capacities;
79
80 std::vector<TrajectoryConstraint> trajectory_constraints;
81 };
82
84 {
85 TrajectoryNode() = default;
86 TrajectoryNode(std::string node, const Json::Value& data);
87
88 std::string name;
89
90 std::optional<std::string> parent{std::nullopt};
91
92 // Stores the costs of each candidates' three associated variable at this node.
93 std::map<std::string, CandidateCosts> candidates_costs;
94 };
95
96 using TrajectoryTree = std::vector<TrajectoryNode>;
97
99 Logger logger,
100 std::shared_ptr<Output::OutputWriter> writer,
101 std::filesystem::path tree_filename,
102 std::filesystem::path annual_lp_filename);
103
104 void launch() override;
105
106private:
107 void read_master_merge_info_file();
108 void read_node_lp_paths();
109
110 void check_nodes_have_lp_folder();
111
112 void build_problem();
113 void add_coupling_constraints();
114 void add_delta_variables();
115 void add_delta_variables_constraints();
116 void set_objective_from_data();
117
118 std::string make_prefix_from_node(const std::string& node_name) const;
119 double get_candidate_initial_value(const std::string& candidate) const;
120
121 bool variable_is_present_in_node(const TrajectoryNode& node,
122 const std::string& candidate) const;
123 bool variable_is_present_in_parent(const TrajectoryNode& node,
124 const std::string& candidate) const;
125
126 std::filesystem::path tree_path_;
127 std::filesystem::path lp_reference_file_filepath_;
128 TrajectoryTree tree_; // Contains each node's information
129 TrajectoryGlobalData trajectory_data_{}; // Contains the global trajectory data
130 CandidatesCouplingMap candidates_coupling_; // Links the same candidates in different nodes
131 NodesToLpDataLocationMap nodes_lp_info_; // Info on the lp folder & files for each node
132 CouplingMap structure_;
133 double scaling_; // Scaling factor to divide the costs by.
134};
Definition MergeMPS.h:13
Definition MergeMasterMPS.h:11
Definition MergeMasterMPS.h:20
void launch() override
Merge and solve master and subproblems.
Definition MergeMasterMPS.cpp:830
Definition MergeMasterMPS.h:50
Definition MergeMasterMPS.h:84
Definition MergeMasterMPS.h:36
Definition common.h:181