Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore function 'PNE_EcrireJeuDeDonneesMPS_avecNom' #5

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/PNE/mps_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,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 @@ -129,6 +129,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 @@ -32,7 +32,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 @@ -41,6 +45,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 @@ -59,6 +64,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 @@ -104,21 +110,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 @@ -190,6 +184,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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take into account the maximize attribute value

}
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 @@ -161,6 +161,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
60 changes: 31 additions & 29 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;
problem_srs->objective_offset = 0;
//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,7 +480,7 @@ int SRSgetobjval(SRS_PROBLEM * problem_srs, double * objVal) {
if (problem_srs->maximize)
(*objVal) *= -1.;

*objVal += problem_srs->objective_offset;
*objVal += problem_mps->objective_offset;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should be before line 480 to take into account the min/max

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, not really

argmax {a.x + b} = argmax {a.x} + b = -argmin {-a.x} + b


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

int SRSsetobjoffset(SRS_PROBLEM* problem_srs, double value)
{
problem_srs->objective_offset = value;
problem_srs->problem_mps->objective_offset = value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should take into account the maximize attribute value

return 0;
}

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

int SRScopyvarboundstype(SRS_PROBLEM * problem_srs, int * varBoundsTypeValues)
Expand Down
1 change: 0 additions & 1 deletion src/SRS/srs_problem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ typedef struct SRS_PROBLEM {

bool read_an_mps;
bool is_mip;
double objective_offset;

// params
int verboseSpx;
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