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>;
56using SubProblemConstraintMap = std::map<std::string, std::string>;
58using SlaveCutId = std::map<std::string, IntVector>;
59using ActiveCut = std::tuple<int, std::string, int, bool>;
60using ActiveCutStorage = std::vector<ActiveCut>;
62using mps_coupling = std::pair<std::string, std::string>;
63using mps_coupling_list = std::list<mps_coupling>;
65using SubProblemNamesInCut = std::vector<std::pair<std::string, int>>;
66using AddedConstraints = std::map<std::string, std::vector<std::string>>;
70 bool operator()(
const PointPtr& lhs,
const PointPtr& rhs)
const
75 bool operator()(
const Point& lhs,
const Point& rhs)
const
77 Point::const_iterator it1(lhs.begin());
78 Point::const_iterator it2(rhs.begin());
80 Point::const_iterator end1(lhs.end());
81 Point::const_iterator end2(rhs.end());
83 while (it1 != end1 && it2 != end2)
85 if (it1->first != it2->first)
87 return it1->first < it2->first;
91 if (std::fabs(it1->second - it2->second) < EPSILON_PREDICATE)
98 return it1->second < it2->second;
103 if (it1 == end1 && it2 == end2)
109 return (it1 == end1);
121inline std::ostream& operator<<(std::ostream& stream,
const Point& rhs)
123 for (
const auto& kvp: rhs)
135 stream << kvp.second;
139 else if (kvp.second < 0)
141 stream << kvp.second;
148double norm_point(
const Point& x0,
const Point& x1);
150std::ostream& operator<<(std::ostream& stream,
const std::vector<IntVector>& rhs);
152const std::string SUBPROBLEM_WEIGHT_CST_STR(
"CONSTANT");
153const std::string SUBPROBLEM_WEIGHT_UNIFORM_CST_STR(
"UNIFORM");
154const std::string WEIGHT_SUM_CST_STR(
"WEIGHT_SUM");
155const std::string MPS_SUFFIX =
".mps";
156const std::string SAVE_SUFFIX =
".svf";
162 std::string INPUTROOT;
163 std::string OUTPUTROOT;
164 std::string STRUCTURE_FILE;
165 std::string MASTER_NAME;
166 std::string SOLVER_NAME;
168 ProblemsFormat PROBLEMS_FORMAT = ProblemsFormat::MPS_FILE;
181 std::string FULL_DIR;
193 std::string SLAVE_WEIGHT;
194 double SLAVE_WEIGHT_VALUE = 0;
202 bool DO_OUTER_LOOP =
false;
203 std::string OUTER_LOOP_OPTION_FILE;
213 int MAX_ITERATIONS = -1;
215 double ABSOLUTE_GAP = 0;
216 double RELATIVE_GAP = 0;
217 double RELAXED_GAP = 0;
218 double TIME_LIMIT = 0;
219 double SEPARATION_PARAM = 1;
220 double MASTER_SOLUTION_TOLERANCE = 1e-4;
221 double CUT_COEFFICIENT_TOLERANCE = 5e-3;
224 bool MICRO_ITERATIONS =
false;
225 int NB_CUTS_PER_ITER = 0;
227 bool BOUND_ALPHA =
false;
228 bool CACHE_PROBLEMS =
false;
230 MasterFormulation MASTER_FORMULATION;
232 std::string AREA_FILE;
233 std::string CSV_NAME;
234 std::string LAST_MASTER_MPS;
235 std::string LAST_MASTER_BASIS;
236 std::string LAST_ITERATION_JSON_FILE;
245Json::Value get_json_file_content(
const std::filesystem::path& json_file);
247bool mkdir(
const std::filesystem::path& path_to_folder);
251 { os << obj } -> std::same_as<std::ostream&>;
257template<OStreamable MPSPath, OStreamable Cand
idateName, OStreamableIntegral ColId>
258void export_structure_file(
const std::filesystem::path& output_path,
259 const std::map<MPSPath, std::map<CandidateName, ColId>>& structure)
261 std::ofstream structure_file{output_path};
262 for (
const auto& [mps_file_path, candidates_name_and_colId]: structure)
264 for (
const auto& [candidate_name, colId]: candidates_name_and_colId)
268 structure_file << std::setw(50) << mps_file_path;
269 structure_file <<
" " << std::setw(50) << candidate_name;
270 structure_file <<
" " << std::setw(10) << colId;
271 structure_file << std::endl;
274 structure_file.close();