4#pragma warning(disable : 4267)
13#include <json/reader.h>
25#include "antares-xpansion/core/ProblemFormat.h"
27enum class MasterFormulation
41typedef std::map<std::string, double> Point;
43typedef std::shared_ptr<Point> PointPtr;
45const double EPSILON_PREDICATE = 1e-8;
47using problem_names = std::set<std::string>;
48using VariableMap = std::map<std::string, int>;
49using Int2Str = std::map<int, std::string>;
50using Str2Dbl = std::map<std::string, double>;
51using IntVector = std::vector<int>;
52using CharVector = std::vector<char>;
53using DblVector = std::vector<double>;
54using StrVector = std::vector<std::string>;
55using CouplingMap = std::map<std::string, VariableMap>;
57using SlaveCutId = std::map<std::string, IntVector>;
58using ActiveCut = std::tuple<int, std::string, int, bool>;
59using ActiveCutStorage = std::vector<ActiveCut>;
61using mps_coupling = std::pair<std::string, std::string>;
62using mps_coupling_list = std::list<mps_coupling>;
64using SubProblemNamesInCut = std::vector<std::pair<std::string, int>>;
68 bool operator()(
const PointPtr& lhs,
const PointPtr& rhs)
const
73 bool operator()(
const Point& lhs,
const Point& rhs)
const
75 Point::const_iterator it1(lhs.begin());
76 Point::const_iterator it2(rhs.begin());
78 Point::const_iterator end1(lhs.end());
79 Point::const_iterator end2(rhs.end());
81 while (it1 != end1 && it2 != end2)
83 if (it1->first != it2->first)
85 return it1->first < it2->first;
89 if (std::fabs(it1->second - it2->second) < EPSILON_PREDICATE)
96 return it1->second < it2->second;
101 if (it1 == end1 && it2 == end2)
107 return (it1 == end1);
119inline std::ostream& operator<<(std::ostream& stream,
const Point& rhs)
121 for (
const auto& kvp: rhs)
133 stream << kvp.second;
137 else if (kvp.second < 0)
139 stream << kvp.second;
146double norm_point(
const Point& x0,
const Point& x1);
148std::ostream& operator<<(std::ostream& stream,
const std::vector<IntVector>& rhs);
150const std::string SUBPROBLEM_WEIGHT_CST_STR(
"CONSTANT");
151const std::string SUBPROBLEM_WEIGHT_UNIFORM_CST_STR(
"UNIFORM");
152const std::string WEIGHT_SUM_CST_STR(
"WEIGHT_SUM");
153const std::string MPS_SUFFIX =
".mps";
154const std::string SAVE_SUFFIX =
".svf";
160 std::string INPUTROOT;
161 std::string OUTPUTROOT;
162 std::string STRUCTURE_FILE;
163 std::string MASTER_NAME;
164 std::string SOLVER_NAME;
166 ProblemsFormat PROBLEMS_FORMAT = ProblemsFormat::MPS_FILE;
179 std::string FULL_DIR;
191 std::string SLAVE_WEIGHT;
192 double SLAVE_WEIGHT_VALUE = 0;
200 bool DO_OUTER_LOOP =
false;
201 std::string OUTER_LOOP_OPTION_FILE;
211 int MAX_ITERATIONS = -1;
213 double ABSOLUTE_GAP = 0;
214 double RELATIVE_GAP = 0;
215 double RELAXED_GAP = 0;
216 double TIME_LIMIT = 0;
217 double SEPARATION_PARAM = 1;
218 double MASTER_SOLUTION_TOLERANCE = 1e-4;
219 double CUT_COEFFICIENT_TOLERANCE = 5e-3;
222 int NB_CUTS_PER_ITER = 0;
224 bool BOUND_ALPHA =
false;
225 bool CACHE_PROBLEMS =
false;
227 MasterFormulation MASTER_FORMULATION;
229 std::string AREA_FILE;
230 std::string CSV_NAME;
231 std::string LAST_MASTER_MPS;
232 std::string LAST_MASTER_BASIS;
233 std::string LAST_ITERATION_JSON_FILE;
242Json::Value get_json_file_content(
const std::filesystem::path& json_file);
244bool mkdir(
const std::filesystem::path& path_to_folder);
248 { os << obj } -> std::same_as<std::ostream&>;
254template<OStreamable MPSPath, OStreamable Cand
idateName, OStreamableIntegral ColId>
255void export_structure_file(
const std::filesystem::path& output_path,
256 const std::map<MPSPath, std::map<CandidateName, ColId>>& structure)
258 std::ofstream structure_file{output_path};
259 for (
const auto& [mps_file_path, candidates_name_and_colId]: structure)
261 for (
const auto& [candidate_name, colId]: candidates_name_and_colId)
265 structure_file << std::setw(50) << mps_file_path;
266 structure_file <<
" " << std::setw(50) << candidate_name;
267 structure_file <<
" " << std::setw(10) << colId;
268 structure_file << std::endl;
271 structure_file.close();