Skip to content

Commit

Permalink
Simplify calls to solver (after modeler 3.1) : move code where it bel…
Browse files Browse the repository at this point in the history
…ongs more
  • Loading branch information
guilpier-code committed Oct 10, 2024
1 parent f588590 commit 6376a90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 55 deletions.
45 changes: 1 addition & 44 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,48 +164,8 @@ static SimplexResult OPT_TryToCallSimplex(const OptimizationOptions& options,
}
}

Probleme.NombreMaxDIterations = -1;
Probleme.DureeMaxDuCalcul = -1.;

Probleme.CoutLineaire = ProblemeAResoudre->CoutLineaire.data();
Probleme.X = ProblemeAResoudre->X.data();
Probleme.Xmin = ProblemeAResoudre->Xmin.data();
Probleme.Xmax = ProblemeAResoudre->Xmax.data();
Probleme.NombreDeVariables = ProblemeAResoudre->NombreDeVariables;
Probleme.TypeDeVariable = ProblemeAResoudre->TypeDeVariable.data();

Probleme.NombreDeContraintes = ProblemeAResoudre->NombreDeContraintes;
Probleme.IndicesDebutDeLigne = ProblemeAResoudre->IndicesDebutDeLigne.data();
Probleme.NombreDeTermesDesLignes = ProblemeAResoudre->NombreDeTermesDesLignes.data();
Probleme.IndicesColonnes = ProblemeAResoudre->IndicesColonnes.data();
Probleme.CoefficientsDeLaMatriceDesContraintes = ProblemeAResoudre
->CoefficientsDeLaMatriceDesContraintes
.data();
Probleme.Sens = ProblemeAResoudre->Sens.data();
Probleme.SecondMembre = ProblemeAResoudre->SecondMembre.data();

Probleme.ChoixDeLAlgorithme = SPX_DUAL;

Probleme.TypeDePricing = PRICING_STEEPEST_EDGE;

Probleme.FaireDuScaling = (PremierPassage ? OUI_SPX : NON_SPX);

Probleme.StrategieAntiDegenerescence = AGRESSIF;

Probleme.PositionDeLaVariable = ProblemeAResoudre->PositionDeLaVariable.data();
Probleme.NbVarDeBaseComplementaires = 0;
Probleme.ComplementDeLaBase = ProblemeAResoudre->ComplementDeLaBase.data();

Probleme.LibererMemoireALaFin = NON_SPX;

Probleme.UtiliserCoutMax = NON_SPX;
Probleme.CoutMax = 0.0;

Probleme.CoutsMarginauxDesContraintes = ProblemeAResoudre->CoutsMarginauxDesContraintes.data();
Probleme.CoutsReduits = ProblemeAResoudre->CoutsReduits.data();

Probleme.NombreDeContraintesCoupes = 0;

auto ortoolsProblem = std::make_unique<OrtoolsLinearProblem>(Probleme.isMIP(), options.ortoolsSolver);
auto legacyOrtoolsFiller = std::make_unique<LegacyOrtoolsFiller>(ortoolsProblem->MPSolver(), &Probleme);
std::vector<LinearProblemFiller*> fillersCollection = {legacyOrtoolsFiller.get()};
Expand Down Expand Up @@ -290,10 +250,7 @@ bool OPT_AppelDuSimplexe(const OptimizationOptions& options,
IResultWriter& writer)
{
const auto& ProblemeAResoudre = problemeHebdo->ProblemeAResoudre;
Optimization::PROBLEME_SIMPLEXE_NOMME Probleme(ProblemeAResoudre->NomDesVariables,
ProblemeAResoudre->NomDesContraintes,
ProblemeAResoudre->VariablesEntieres,
ProblemeAResoudre->basisStatus,
Optimization::PROBLEME_SIMPLEXE_NOMME Probleme(ProblemeAResoudre.get(),
problemeHebdo->NamedProblems,
options.solverLogs);

Expand Down
7 changes: 3 additions & 4 deletions src/solver/utils/include/antares/solver/utils/named_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "spx_definition_arguments.h"
#include "spx_fonctions.h"

#include "antares/solver/simulation/sim_structure_probleme_economique.h"

namespace Antares
{
namespace Optimization
Expand All @@ -37,10 +39,7 @@ class BasisStatus;
struct PROBLEME_SIMPLEXE_NOMME: public PROBLEME_SIMPLEXE
{
public:
PROBLEME_SIMPLEXE_NOMME(const std::vector<std::string>& NomDesVariables,
const std::vector<std::string>& NomDesContraintes,
const std::vector<bool>& VariablesEntieres,
BasisStatus& basisStatus,
PROBLEME_SIMPLEXE_NOMME(PROBLEME_ANTARES_A_RESOUDRE* ProblemeAResoudre,
bool UseNamedProblems,
bool SolverLogs);

Expand Down
41 changes: 34 additions & 7 deletions src/solver/utils/named_problem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,46 @@

namespace Antares::Optimization
{
PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(const std::vector<std::string>& NomDesVariables,
const std::vector<std::string>& NomDesContraintes,
const std::vector<bool>& VariablesEntieres,
BasisStatus& basisStatus,
PROBLEME_SIMPLEXE_NOMME::PROBLEME_SIMPLEXE_NOMME(PROBLEME_ANTARES_A_RESOUDRE* problemeAResoudre,
bool UseNamedProblems,
bool SolverLogs):
NomDesVariables(NomDesVariables),
NomDesContraintes(NomDesContraintes),
NomDesVariables(problemeAResoudre->NomDesVariables),
NomDesContraintes(problemeAResoudre->NomDesContraintes),
VariablesEntieres(problemeAResoudre->VariablesEntieres),
useNamedProblems_(UseNamedProblems),
VariablesEntieres(VariablesEntieres),
basisStatus(basisStatus)
{
AffichageDesTraces = SolverLogs ? OUI_SPX : NON_SPX;
NombreMaxDIterations = -1;
DureeMaxDuCalcul = -1.;
CoutLineaire = problemeAResoudre->CoutLineaire.data();
X = problemeAResoudre->X.data();
Xmin = problemeAResoudre->Xmin.data();
Xmax = problemeAResoudre->Xmax.data();
NombreDeVariables = problemeAResoudre->NombreDeVariables;
TypeDeVariable = problemeAResoudre->TypeDeVariable.data();

NombreDeContraintes = problemeAResoudre->NombreDeContraintes;
IndicesDebutDeLigne = problemeAResoudre->IndicesDebutDeLigne.data();
NombreDeTermesDesLignes = problemeAResoudre->NombreDeTermesDesLignes.data();
IndicesColonnes = problemeAResoudre->IndicesColonnes.data();
CoefficientsDeLaMatriceDesContraintes = problemeAResoudre
->CoefficientsDeLaMatriceDesContraintes
.data();
Sens = problemeAResoudre->Sens.data();
SecondMembre = problemeAResoudre->SecondMembre.data();
ChoixDeLAlgorithme = SPX_DUAL;
TypeDePricing = PRICING_STEEPEST_EDGE;
StrategieAntiDegenerescence = AGRESSIF;
PositionDeLaVariable = problemeAResoudre->PositionDeLaVariable.data();
NbVarDeBaseComplementaires = 0;
ComplementDeLaBase = problemeAResoudre->ComplementDeLaBase.data();
LibererMemoireALaFin = NON_SPX;
UtiliserCoutMax = NON_SPX;
CoutMax = 0.0;
CoutsMarginauxDesContraintes = problemeAResoudre->CoutsMarginauxDesContraintes.data();
CoutsReduits = problemeAResoudre->CoutsReduits.data();
NombreDeContraintesCoupes = 0;
}

bool PROBLEME_SIMPLEXE_NOMME::isMIP() const
Expand Down

0 comments on commit 6376a90

Please sign in to comment.