Skip to content

Commit

Permalink
Pass typeVar instead of &Probleme, remove unused function argument (#388
Browse files Browse the repository at this point in the history
)

* Pass typeVar instead of &Probleme, remove unused function argument

* change_MPSolver_variables_bounds doesn't need PROBLEME_SIMPLEXE*
  problemeSimplexe, only its member TypeDeVariable. Pass it directly.

* ORTOOLS_CorrigerLesBornes no longer needs argument Probleme, remove it

* Remove function change_MPSolver_variables_bounds

It is no longer needed.
  • Loading branch information
flomnes authored Sep 27, 2021
1 parent 18caed3 commit 6b99169
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
3 changes: 1 addition & 2 deletions src/solver/optimisation/opt_appel_solveur_lineaire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ bool OPT_AppelDuSimplexe(PROBLEME_HEBDO* ProblemeHebdo, uint numSpace, int NumIn
ProblemeAResoudre->Xmin,
ProblemeAResoudre->Xmax,
ProblemeAResoudre->TypeDeVariable,
ProblemeAResoudre->NombreDeVariables,
&Probleme);
ProblemeAResoudre->NombreDeVariables);
}
else
{
Expand Down
48 changes: 15 additions & 33 deletions src/solver/utils/ortools_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ void extract_from_MPSolver(MPSolver* solver, PROBLEME_A_RESOUDRE* problemeSimple

void change_MPSolver_objective(MPSolver* solver, double* costs, int nbVar);
void change_MPSolver_rhs(MPSolver* solver, double* rhs, char* sens, int nbRow);
void change_MPSolver_variables_bounds(MPSolver* solver,
double* bMin,
double* bMax,
int nbVar,
PROBLEME_SIMPLEXE* problemeSimplexe);

void transferVariables(MPSolver* solver, double* bMin, double* bMax, double* costs, int nbVar)
{
Expand Down Expand Up @@ -204,30 +199,6 @@ void change_MPSolver_objective(MPSolver* solver, double* costs, int nbVar)
}
}

void change_MPSolver_variables_bounds(MPSolver* solver,
double* bMin,
double* bMax,
int nbVar,
PROBLEME_SIMPLEXE* problemeSimplexe)
{
auto& variables = solver->variables();
for (int idxVar = 0; idxVar < nbVar; ++idxVar)
{
double min_l
= ((problemeSimplexe->TypeDeVariable[idxVar] == VARIABLE_NON_BORNEE)
|| (problemeSimplexe->TypeDeVariable[idxVar] == VARIABLE_BORNEE_SUPERIEUREMENT)
? -MPSolver::infinity()
: bMin[idxVar]);
double max_l
= ((problemeSimplexe->TypeDeVariable[idxVar] == VARIABLE_NON_BORNEE)
|| (problemeSimplexe->TypeDeVariable[idxVar] == VARIABLE_BORNEE_INFERIEUREMENT)
? MPSolver::infinity()
: bMax[idxVar]);
auto& var = variables[idxVar];
var->SetBounds(min_l, max_l);
}
}

void change_MPSolver_rhs(MPSolver* solver, double* rhs, char* sens, int nbRow)
{
auto& constraints = solver->constraints();
Expand Down Expand Up @@ -354,11 +325,22 @@ extern "C"
double* bMin,
double* bMax,
int* typeVar,
int nbVar,
PROBLEME_SIMPLEXE* Probleme)
int nbVar)
{
Probleme->TypeDeVariable = typeVar;
change_MPSolver_variables_bounds(solver, bMin, bMax, nbVar, Probleme);
auto& variables = solver->variables();
for (int idxVar = 0; idxVar < nbVar; ++idxVar)
{
double min_l = ((typeVar[idxVar] == VARIABLE_NON_BORNEE)
|| (typeVar[idxVar] == VARIABLE_BORNEE_SUPERIEUREMENT)
? -MPSolver::infinity()
: bMin[idxVar]);
double max_l = ((typeVar[idxVar] == VARIABLE_NON_BORNEE)
|| (typeVar[idxVar] == VARIABLE_BORNEE_INFERIEUREMENT)
? MPSolver::infinity()
: bMax[idxVar]);
auto& var = variables[idxVar];
var->SetBounds(min_l, max_l);
}
}

void ORTOOLS_LibererProbleme(MPSolver* solver)
Expand Down
3 changes: 1 addition & 2 deletions src/solver/utils/ortools_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ void ORTOOLS_CorrigerLesBornes(MPSolver* ProbSpx,
double* bMin,
double* bMax,
int* typeVar,
int nbVar,
PROBLEME_SIMPLEXE* Probleme);
int nbVar);
void ORTOOLS_LibererProbleme(MPSolver* ProbSpx);

#endif

0 comments on commit 6b99169

Please sign in to comment.