Antares Simulator
Power System Simulator
mps_utils.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #pragma once
22 #include "antares/solver/simulation/sim_structure_probleme_economique.h"
23 #include "antares/study/fwd.h"
24 
25 #include "ortools_utils.h"
26 
27 using namespace Antares;
28 using namespace Antares::Data;
29 using namespace Antares::Optimization;
30 using namespace operations_research;
31 
32 // ======================
33 // MPS files writing
34 // ======================
35 
37 {
38 public:
39  explicit I_MPS_writer(uint currentOptimNumber):
40  current_optim_number_(currentOptimNumber)
41  {
42  }
43 
44  I_MPS_writer() = default;
45  virtual ~I_MPS_writer() = default;
46  virtual void runIfNeeded(Solver::IResultWriter& writer, const std::string& filename) = 0;
47 
48 protected:
49  uint current_optim_number_ = 0;
50 };
51 
53 {
54 public:
55  virtual ~fullOrToolsMPSwriter() = default;
56  fullOrToolsMPSwriter(MPSolver* solver, uint currentOptimNumber);
57  void runIfNeeded(Solver::IResultWriter& writer, const std::string& filename) override;
58 
59 private:
60  MPSolver* solver_ = nullptr;
61 };
62 
64 {
65 public:
66  virtual ~nullMPSwriter() = default;
67  using I_MPS_writer::I_MPS_writer;
68 
69  void runIfNeeded(Solver::IResultWriter& /*writer*/, const std::string& /*filename*/) override
70  {
71  // Does nothing
72  }
73 };
74 
76 {
77 public:
78  virtual ~mpsWriterFactory() = default;
79  mpsWriterFactory(Data::mpsExportStatus exportMPS,
80  bool exportMPSOnError,
81  int current_optim_number,
82  MPSolver* solver);
83 
84  std::unique_ptr<I_MPS_writer> create();
85  std::unique_ptr<I_MPS_writer> createOnOptimizationError();
86 
87 private:
88  // Member functions...
89  std::unique_ptr<I_MPS_writer> createFullmpsWriter();
90  bool doWeExportMPS();
91 
92  // Member data...
93  Data::mpsExportStatus export_mps_;
94  bool export_mps_on_error_;
95  MPSolver* solver_ = nullptr;
96  uint current_optim_number_;
97 };
Definition: i_writer.h:32
Definition: mps_utils.h:37
Definition: mps_utils.h:53
Definition: mps_utils.h:76
Definition: mps_utils.h:64