Skip to content

Commit 2580549

Browse files
authored
Merge pull request #32 from rte-france/feature/new_api
API: add the ability to set LP starting base in SRSoptimize (signed off commits)
2 parents 77d35c9 + 84596d2 commit 2580549

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

.github/workflows/ubuntu-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
os: [windows-latest, ubuntu-20.04, ubuntu-22.04]
24+
os: [windows-latest, ubuntu-22.04]
2525
steps:
2626
- name: is release created
2727
shell: bash

src/SRS/srs_problem.c

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,31 @@ int SRSsetcoefs(SRS_PROBLEM * problem_srs,
363363
return 0;
364364
}
365365

366-
int allocateProblemsAndPropagateParams(SRS_PROBLEM * problem_srs) {
366+
void setStartingBasis(PROBLEME_SIMPLEXE* problem_simplexe, const int* column_basis_status, const int* row_basis_status)
367+
{
368+
if (column_basis_status == NULL || row_basis_status == NULL)
369+
{
370+
return;
371+
}
372+
problem_simplexe->BaseDeDepartFournie = OUI_SPX;
373+
// Column basis
374+
for (int i = 0; i < problem_simplexe->NombreDeVariables; ++i)
375+
{
376+
problem_simplexe->PositionDeLaVariable[i] = column_basis_status[i];
377+
}
378+
// Slack variables basis
379+
problem_simplexe->NbVarDeBaseComplementaires = 0;
380+
for (int i = 0; i < problem_simplexe->NombreDeContraintes; ++i)
381+
{
382+
if (row_basis_status[i] == EN_BASE)
383+
{
384+
problem_simplexe->ComplementDeLaBase[problem_simplexe->NbVarDeBaseComplementaires] = i;
385+
problem_simplexe->NbVarDeBaseComplementaires++;
386+
}
387+
}
388+
}
389+
390+
int allocateProblemsAndPropagateParams(SRS_PROBLEM * problem_srs, const int * column_basis_status, const int * row_basis_status) {
367391
if (problem_srs->is_mip) {
368392
problem_srs->problem_mip = malloc(sizeof(PROBLEME_A_RESOUDRE));
369393
PNE_copy_problem(problem_srs->problem_mps, problem_srs->problem_mip, 0, 0.0);
@@ -428,22 +452,28 @@ int allocateProblemsAndPropagateParams(SRS_PROBLEM * problem_srs) {
428452

429453
problem_simplexe->CoutMax = 0;
430454
problem_simplexe->NbVarDeBaseComplementaires = 0;
455+
456+
setStartingBasis(problem_simplexe, column_basis_status, row_basis_status);
431457
}
432458

433459
return 0;
434460
}
435461

462+
int SRSoptimize(SRS_PROBLEM * problem_srs)
463+
{
464+
return SRSoptimizewithinitialbasis(problem_srs, NULL, NULL);
465+
}
466+
467+
int SRSoptimizewithinitialbasis(SRS_PROBLEM * problem_srs, const int * column_basis_status, const int * row_basis_status) {
436468

437-
int SRSoptimize(SRS_PROBLEM * problem_srs) {
438-
439469
int nbCols = problem_srs->problem_mps->NbVar;
440470
if (problem_srs->maximize) {
441471
for (int idxCol = 0; idxCol < nbCols; ++idxCol) {
442472
problem_srs->problem_mps->L[idxCol] *= -1.0;
443473
}
444474
}
445-
446-
allocateProblemsAndPropagateParams(problem_srs);
475+
476+
allocateProblemsAndPropagateParams(problem_srs, column_basis_status, row_basis_status);
447477

448478
struct timespec debut;
449479
timespec_get(&debut, TIME_UTC);
@@ -702,7 +732,7 @@ int SRSsetintparams(SRS_PROBLEM * problem_srs, const char * paramId, int paramVa
702732
return -1;
703733
}
704734

705-
int SRSsetdoubleparams(SRS_PROBLEM * problem_srs, const char * paramId, double paramValue) {
735+
int SRSsetdoubleparams(SRS_PROBLEM * problem_srs, const char * paramId, double paramValue) {
706736
if (strcmp(SRS_PARAM_RELATIVE_GAP, paramId) == 0) {
707737
problem_srs->relativeGap = paramValue;
708738
return 0;
@@ -779,12 +809,9 @@ int SRSgetrowbasisstatus(SRS_PROBLEM * problem_srs, char ** rowStatuses) {
779809
}
780810

781811
int nbRow = problem_srs->problem_mps->NbCnt;
782-
(*rowStatuses) = malloc(nbRow * sizeof(char));
783-
784812
for (int idx = 0; idx < nbRow; ++idx) {
785813
(*rowStatuses)[idx] = EN_BASE_LIBRE;
786814
}
787-
788815
for (int idx = 0; idx < problem_srs->problem_simplexe->NbVarDeBaseComplementaires; ++idx)
789816
{
790817
(*rowStatuses)[problem_srs->problem_simplexe->ComplementDeLaBase[idx]] = EN_BASE;

src/SRS/srs_problem_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int SRSsetdoubleparams(SRS_PROBLEM * problem_srs, const char * paramId, double p
5555

5656
// *** Optimization ***
5757
int SRSoptimize(SRS_PROBLEM * problem_srs);
58+
int SRSoptimizewithinitialbasis(SRS_PROBLEM * problem_srs, const int * column_basis_status, const int * row_basis_status);
5859

5960
// *** Access solution information ***
6061
int SRSgetobjval(SRS_PROBLEM * problem_srs, double * objVal);

0 commit comments

Comments
 (0)