Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
linearProblem.h
1/*
2 * Copyright 2007-2024, 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
22#pragma once
23
24#include <antares/optimisation/linear-problem-api/linearProblem.h>
25#include <antares/optimisation/linear-problem-mpsolver-impl/mipConstraint.h>
26#include <antares/optimisation/linear-problem-mpsolver-impl/mipSolution.h>
27#include <antares/optimisation/linear-problem-mpsolver-impl/mipVariable.h>
28
29namespace operations_research
30{
31class MPSolver;
32class MPSolverParameters;
33class MPObjective;
34} // namespace operations_research
35
36namespace Antares::Optimisation::LinearProblemMpsolverImpl
37{
38
40{
41public:
42 OrtoolsLinearProblem(bool isMip, const std::string& solverName);
43 ~OrtoolsLinearProblem() override = default;
44
45 OrtoolsMipVariable* addNumVariable(double lb, double ub, const std::string& name) override;
46
47 OrtoolsMipVariable* addIntVariable(double lb, double ub, const std::string& name) override;
48
50 double ub,
51 bool integer,
52 const std::string& name) override;
53
54 OrtoolsMipVariable* getVariable(const std::string& name) const override;
55 int variableCount() const override;
56
57 OrtoolsMipConstraint* addConstraint(double lb, double ub, const std::string& name) override;
58
59 OrtoolsMipConstraint* getConstraint(const std::string& name) const override;
60 int constraintCount() const override;
61
62 void setObjectiveCoefficient(LinearProblemApi::IMipVariable* var, double coefficient) override;
63 double getObjectiveCoefficient(const LinearProblemApi::IMipVariable* var) const override;
64
65 void setMinimization() override;
66 void setMaximization() override;
67
68 bool isMinimization() const override;
69 bool isMaximization() const override;
70
71 OrtoolsMipSolution* solve(bool verboseSolver) override;
72 void WriteLP(const std::string& filename) override;
73
74 double infinity() const override;
75
76protected:
77 operations_research::MPSolver* MpSolver() const;
78
79private:
80 operations_research::MPSolver* mpSolver_;
81 operations_research::MPObjective* objective_;
82 operations_research::MPSolverParameters params_;
83
84 std::map<std::string, std::unique_ptr<OrtoolsMipVariable>> variables_;
85 std::map<std::string, std::unique_ptr<OrtoolsMipConstraint>> constraints_;
86
87 std::unique_ptr<OrtoolsMipSolution> solution_;
88};
89
90} // namespace Antares::Optimisation::LinearProblemMpsolverImpl
OrtoolsMipVariable * addVariable(double lb, double ub, bool integer, const std::string &name) override
Create a continuous or integer variable.
Definition linearProblem.cpp:49
OrtoolsMipVariable * addNumVariable(double lb, double ub, const std::string &name) override
Create a continuous variable.
Definition linearProblem.cpp:71
OrtoolsMipConstraint * addConstraint(double lb, double ub, const std::string &name) override
Add a bounded constraint to the problem.
Definition linearProblem.cpp:95
OrtoolsMipSolution * solve(bool verboseSolver) override
Solve the problem, returns a IMipSolution.
Definition linearProblem.cpp:185
void setMinimization() override
Sets the optimization direction to minimize.
Definition linearProblem.cpp:152
void setObjectiveCoefficient(LinearProblemApi::IMipVariable *var, double coefficient) override
Set the objective coefficient for a given variable.
Definition linearProblem.cpp:140
void setMaximization() override
Sets the optimization direction to maximize.
Definition linearProblem.cpp:157
OrtoolsMipVariable * addIntVariable(double lb, double ub, const std::string &name) override
Create a integer variable.
Definition linearProblem.cpp:78