Skip to content

Commit

Permalink
Merge pull request #14 from rte-france/metrix-mps-write
Browse files Browse the repository at this point in the history
Metrix mps write + objective offset
  • Loading branch information
klorel authored Nov 23, 2022
2 parents abae9a8 + 9df6a78 commit 8e51c72
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 42 deletions.
1 change: 1 addition & 0 deletions src/PNE/mps_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ int * NomCntSuivant;
int * FirstNomVar;
int * NomVarSuivant;

double objective_offset;
} PROBLEME_MPS;
1 change: 1 addition & 0 deletions src/PNE/pne_definition_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ La matrice des contrainte est decrite par les 4 vecteurs qui suivent. Elle doit
couteux.
- Mettre OUI_PNE si le probleme est difficile a resoudre.
*/
double objective_offset;
} PROBLEME_A_RESOUDRE;


Expand Down
30 changes: 15 additions & 15 deletions src/PNE/pne_ecrire_jeu_de_donnees_mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

/*----------------------------------------------------------------------------*/

void PNE_EcrireJeuDeDonneesMPS( PROBLEME_PNE * Pne, PROBLEME_A_RESOUDRE * Probleme )
void PNE_EcrireJeuDeDonneesMPS(PROBLEME_PNE * Pne, PROBLEME_A_RESOUDRE * Probleme) {
PNE_EcrireJeuDeDonneesMPS_avecNom(Pne, Probleme, "Donnees_Probleme_Solveur.mps");
}

void PNE_EcrireJeuDeDonneesMPS_avecNom(PROBLEME_PNE * Pne, PROBLEME_A_RESOUDRE * Probleme, const char * const nomFichier)
{
FILE * Flot;
int Cnt; int Var; int il; int ilk; int ilMax; char * Nombre;
Expand All @@ -25,6 +29,7 @@ int * Cder; int * Cdeb; int * NumeroDeContrainte; int * Csui;
/* */
int NombreDeVariables; int * TypeDeVariable; int * TypeDeBorneDeLaVariable;
double * Xmax; double * Xmin; double * CoutLineaire; int NombreDeContraintes;
double objective_offset;
double * SecondMembre; char * Sens; int * IndicesDebutDeLigne;
int * NombreDeTermesDesLignes; double * CoefficientsDeLaMatriceDesContraintes;
int * IndicesColonnes;
Expand All @@ -43,6 +48,7 @@ IndicesDebutDeLigne = Probleme->IndicesDebutDeLigne;
NombreDeTermesDesLignes = Probleme->NombreDeTermesDesLignes;
CoefficientsDeLaMatriceDesContraintes = Probleme->CoefficientsDeLaMatriceDesContraintes;
IndicesColonnes = Probleme->IndicesColonnes;
objective_offset = Probleme->objective_offset;

/* Chainage de la transposee */
for ( ilMax = -1 , Cnt = 0 ; Cnt < NombreDeContraintes; Cnt++ ) {
Expand Down Expand Up @@ -88,21 +94,9 @@ for ( Cnt = 0 ; Cnt < NombreDeContraintes ; Cnt++ ) {
free( Cder );
/* Fin chainage de la transposee */

/* Fichier qui contiendra le jeu de donnees */
printf("***************************************************************************\n");
printf("*** Vous avez demande la creation d'un fichier contenant la description ***\n");
printf("*** du probleme en cours de resolution. Le fichier de donnees se trouve ***\n");
printf("*** dans le repertoire d'execution. Il s'appelle: ***\n");
printf("*** ***\n");
printf("*** Donnees_Probleme_Solveur.mps ***\n");
printf("*** ***\n");
printf("*** Si un fichier de ce nom existait deja, il sera ecrase par avec les ***\n");
printf("*** nouvelles donnees. ***\n");
printf("***************************************************************************\n");

Flot = fopen( "Donnees_Probleme_Solveur.mps", "w" );
Flot = fopen( nomFichier, "w" );
if( Flot == NULL ) {
printf("Erreur ouverture du fichier pour l'ecriture du jeu de donnees \n");
printf("Erreur ouverture du fichier pour l'ecriture du jeu de donnees %s\n", nomFichier);
exit(0);
}

Expand Down Expand Up @@ -174,6 +168,12 @@ for ( Var = 0 ; Var < NombreDeVariables ; Var++ ) {

/* RHS */
fprintf(Flot,"RHS\n");
// Objective offset
// see https://www.ibm.com/docs/en/icos/20.1.0?topic=standard-records-in-mps-format
// NOTE: By convention, we write here the negative objective value
if (objective_offset != 0.0) {
fprintf(Flot," RHSVAL OBJECTIF %f\n", -objective_offset);
}
for ( Cnt = 0 ; Cnt < NombreDeContraintes ; Cnt++ ) {
if ( SecondMembre[Cnt] != 0.0 ) {
sprintf(Nombre,"%-.9lf",SecondMembre[Cnt]);
Expand Down
1 change: 1 addition & 0 deletions src/PNE/pne_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void PNE_LireJeuDeDonneesMPS( void );

void PNE_PrendreEnCompteLesContraintesRangeMPS( void );

void PNE_EcrireJeuDeDonneesMPS_avecNom(PROBLEME_PNE *, PROBLEME_A_RESOUDRE *, const char * const);
void PNE_EcrireJeuDeDonneesMPS( PROBLEME_PNE * , PROBLEME_A_RESOUDRE * );

void PNE_EcrirePresolvedMPS( PROBLEME_PNE * );
Expand Down
67 changes: 41 additions & 26 deletions src/SRS/srs_problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void PNE_copy_problem(PROBLEME_MPS * Mps, PROBLEME_A_RESOUDRE * Probleme, int To
Probleme->CoupesLiftAndProject = NON_PNE;
Probleme->AffichageDesTraces = OUI_PNE;
Probleme->FaireDuPresolve = OUI_PNE /* OUI_PNE */;
Probleme->objective_offset = Mps->objective_offset;
if (Probleme->FaireDuPresolve == NON_PNE) printf("!!!!!!!!!!!!!! Attention pas de presolve !!!!!!!!!\n");

Probleme->TempsDExecutionMaximum = 0;
Expand Down Expand Up @@ -124,30 +125,32 @@ int computeColBoundType(double lb, double ub) {
// *** Enf of Utility functions ***

int initProblemMpsPointer(SRS_PROBLEM * problem_srs) {
problem_srs->problem_mps = (PROBLEME_MPS *)malloc(sizeof(PROBLEME_MPS));
problem_srs->problem_mps->LabelDeLObjectif = NULL;
problem_srs->problem_mps->NbVar = 0;
problem_srs->problem_mps->NbCnt = 0;
problem_srs->problem_mps->Msui = NULL;
problem_srs->problem_mps->Mder = NULL;
problem_srs->problem_mps->Nuvar = NULL;
problem_srs->problem_mps->BRange = NULL;
problem_srs->problem_mps->LabelDeLaContrainte = NULL;
problem_srs->problem_mps->LabelDuSecondMembre = NULL;
problem_srs->problem_mps->A = NULL;
problem_srs->problem_mps->Mdeb = NULL;
problem_srs->problem_mps->NbTerm = NULL;
problem_srs->problem_mps->B = NULL;
problem_srs->problem_mps->SensDeLaContrainte = NULL;
problem_srs->problem_mps->VariablesDualesDesContraintes = NULL;
problem_srs->problem_mps->TypeDeVariable = NULL;
problem_srs->problem_mps->TypeDeBorneDeLaVariable = NULL;
problem_srs->problem_mps->U = NULL;
problem_srs->problem_mps->L = NULL;
problem_srs->problem_mps->Umin = NULL;
problem_srs->problem_mps->Umax = NULL;
problem_srs->problem_mps->LabelDeLaVariable = NULL;

PROBLEME_MPS* mps = (PROBLEME_MPS *)malloc(sizeof(PROBLEME_MPS));
mps->LabelDeLObjectif = NULL;
mps->NbVar = 0;
mps->NbCnt = 0;
mps->Msui = NULL;
mps->Mder = NULL;
mps->Nuvar = NULL;
mps->BRange = NULL;
mps->LabelDeLaContrainte = NULL;
mps->LabelDuSecondMembre = NULL;
mps->A = NULL;
mps->Mdeb = NULL;
mps->NbTerm = NULL;
mps->B = NULL;
mps->SensDeLaContrainte = NULL;
mps->VariablesDualesDesContraintes = NULL;
mps->TypeDeVariable = NULL;
mps->TypeDeBorneDeLaVariable = NULL;
mps->U = NULL;
mps->L = NULL;
mps->Umin = NULL;
mps->Umax = NULL;
mps->LabelDeLaVariable = NULL;
mps->objective_offset = 0;

problem_srs->problem_mps = mps;
return 0;
}

Expand All @@ -160,7 +163,6 @@ SRS_PROBLEM * SRScreateprob() {
problem_srs->read_an_mps = false;
problem_srs->is_mip = false;
problem_srs->maximize = false;

//params
problem_srs->verboseSpx = 0;
problem_srs->verbosePne = 0;
Expand Down Expand Up @@ -229,7 +231,7 @@ int SRSwritempsprob(PROBLEME_MPS * problem_mps, const char * fileName) {
PROBLEME_A_RESOUDRE problem_a_resoudre;
PROBLEME_PNE problem_pne;
PNE_copy_problem(problem_mps, &problem_a_resoudre, 0, 0.0);
//FIXME PNE_EcrireJeuDeDonneesMPS_avecNom(&problem_pne, &problem_a_resoudre, fileName);
PNE_EcrireJeuDeDonneesMPS_avecNom(&problem_pne, &problem_a_resoudre, fileName);

return 0;
}
Expand Down Expand Up @@ -478,6 +480,8 @@ int SRSgetobjval(SRS_PROBLEM * problem_srs, double * objVal) {
if (problem_srs->maximize)
(*objVal) *= -1.;

*objVal += problem_mps->objective_offset;

return 0;
}

Expand Down Expand Up @@ -730,6 +734,17 @@ int SRSchgrangeval(SRS_PROBLEM * problem_srs, size_t nbRowIndexes, const int * r
return 0;
}

int SRSsetobjoffset(SRS_PROBLEM* problem_srs, double value)
{
problem_srs->problem_mps->objective_offset = value;
return 0;
}

double SRSgetobjoffset(const SRS_PROBLEM* problem_srs)
{
return problem_srs->problem_mps->objective_offset;
}

int SRScopyvarboundstype(SRS_PROBLEM * problem_srs, int * varBoundsTypeValues)
{
PROBLEME_MPS * problem_mps = problem_srs->problem_mps;
Expand Down
2 changes: 2 additions & 0 deletions src/SRS/srs_problem_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ int SRSchgobj(SRS_PROBLEM * problem_srs, size_t nbColIndexes, const int * colInd
int SRSchgrhs(SRS_PROBLEM * problem_srs, size_t nbRowIndexes, const int * rowIndexes, const double * newRhs);
int SRSchgsens(SRS_PROBLEM * problem_srs, size_t nbRowIndexes, const int * rowIndexes, const char * newSense);
int SRSchgrangeval(SRS_PROBLEM * problem_srs, size_t nbRowIndexes, const int * rowIndexes, const double * newRngVal);
int SRSsetobjoffset(SRS_PROBLEM* problem_srs, double value);
double SRSgetobjoffset(const SRS_PROBLEM* problem_srs);
int SRScopyvarboundstype(SRS_PROBLEM * problem_srs, int * varBoundsTypeValues);
int SRSsetxvalue(SRS_PROBLEM * problem_srs, int varIndex, double xValue);

Expand Down
3 changes: 2 additions & 1 deletion src/TEST_API/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ int main(int argc, char ** argv) {
SRScreatecols(srsProb, nbCols, obj, colTypesMip, lbMip, ubMip, colNames);
SRScreaterows(srsProb, nbRows, rhsMip, range, sense, rowNames);
SRSsetcoefs(srsProb, rowDebInds, nbCoefPerRow, colInds, coefs);
//SRSwritempsprob(srsProb->problem_mps, "problemMip.mps");
SRSsetobjoffset(srsProb, 121.);
SRSwritempsprob(srsProb->problem_mps, "problemMip.mps");

SRSoptimize(srsProb);

Expand Down

0 comments on commit 8e51c72

Please sign in to comment.