#include "cplex.h" #include using namespace std; #ifdef DEBUG_CPLEX #define DEBUG_CPLEX_PRINT(a) std::cout< > vclique(nbColonnes); vector vbc; contrainte14 ( vclique, vbc); contrainte15 ( vclique, vbc); contrainte16 ( vclique, vbc); contrainte17 ( vclique, vbc); contrainte18 ( vclique, vbc); contrainte19 ( vclique, vbc); contrainte20 ( vclique, vbc); contrainte21 ( vclique, vbc); nbClique = vbc.size(); // Nombre de contraintes de clique clique = new int*[nbColonnes]; // Contraintes de clique. Taille = nbColonnes x nbCliques for ( int i=0 ; i < nbColonnes ; i++ ) { clique[i] = new int[nbClique]; for ( int j=0 ; j < nbClique ; j++ ) { clique[i][j] = vclique[j][i]; } } bc = new int[nbClique]; // Second membre des contraintes de clique. Taille = nbClique for ( int i=0 ; i < nbClique ; i++ ) { /* clique[i] = new int[nbColonnes]; for ( int j=0 ; j < nbColonnes ; j++ ) { clique[i][j] = vclique[i][j]; }//*/ bc[i] = vbc[i]; } } void Cplex::contrainte14 (std::vector >& vclique, std::vector& vbc) { #ifdef TEST_CC14 for ( int subset=0 ; subset < 1 ; subset++ ) #else for ( int subset=0 ; subset < CInstance::M((constraint_t) 14) ; subset++ ) #endif { #ifdef TEST_CC14 vector test; test.push_back((powerplants2_t) 0); test.push_back((powerplants2_t) 1);test.push_back((powerplants2_t) 2); vector centralesDuSubset = test; wlen_t Se = (wlen_t) 1; #else vector centralesDuSubset = CInstance::m_constraints14[subset].C(); wlen_t Se = CInstance::m_constraints14[subset].Se() ; #endif int nbCentralesDuSubset = centralesDuSubset.size(); for ( powerplants2_t i=(powerplants2_t) 0 ; i < nbCentralesDuSubset ; i = (powerplants2_t) (i+1) ) { DEBUG_CPLEX_PRINT("powerplant i "< contrainte(nbColonnes, 0); contrainte[idx_colonne] = contrainte[idx_colonneprime] = 1; vclique.push_back(contrainte); vbc.push_back(1); DEBUG_CPLEX_PRINT("\t\t\t\t\t Fin de l'ajout de la contrainte"); } } } } } } } } } void Cplex::contrainte15(vector >& vclique, vector& vbc) { for ( int subset=0 ; subset < CInstance::M((constraint_t) 15) ; subset++ ) { vector centralesDuSubset = CInstance::m_constraints15[subset].C(); wlen_t Se = CInstance::m_constraints15[subset].Se() ; week_t IDm = CInstance::m_constraints15[subset].ID() ; week_t IFm = CInstance::m_constraints15[subset].IF() ; int nbCentralesDuSubset = centralesDuSubset.size(); for ( powerplants2_t i=(powerplants2_t) 0 ; i < nbCentralesDuSubset ; i = (powerplants2_t) (i+1) ) { int idx_i = centralesDuSubset[i]; for ( powerplants2_t iprime= (powerplants2_t) 0 ; iprime < nbCentralesDuSubset ; iprime = (powerplants2_t) (iprime+1) ) { if ( i == iprime ){ continue; } int idx_iprime = centralesDuSubset[iprime]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( int i_colonneprime=0 ; i_colonneprime < Clique::annuaire[idx_iprime].size() ; i_colonneprime++ ) { int idx_colonneprime = Clique::annuaire[idx_iprime][i_colonneprime]; for ( int k=0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k++ ) { for ( int kprime=0 ; kprime < Clique::dateDebutOutageCampagneK[idx_colonneprime].size() ; kprime++ ) { int DAk = CInstance::type2((powerplants2_t) idx_i).DA((campaign_t) k); int DAkprime = CInstance::type2((powerplants2_t) idx_iprime).DA((campaign_t) kprime); // Ajout du test pour valider la contrainte if ( (IDm - DAk+1 <=Clique::dateDebutOutageCampagneK[idx_colonne][k]) &&( Clique::dateDebutOutageCampagneK[idx_colonne][k]<= IFm ) &&(IDm - DAkprime+1 <=Clique::dateDebutOutageCampagneK[idx_colonneprime][kprime]) &&( Clique::dateDebutOutageCampagneK[idx_colonneprime][kprime]<= IFm ) ) { if ( (Clique::dateDebutOutageCampagneK[idx_colonne][k] - Clique::dateFinOutageCampagneK[idx_colonneprime][kprime] < Se) && (Clique::dateDebutOutageCampagneK[idx_colonneprime][kprime] - Clique::dateFinOutageCampagneK[idx_colonne][k] < Se) ) { vector contrainte(nbColonnes, 0); contrainte[idx_colonne] = contrainte[idx_colonneprime] = 1; vclique.push_back(contrainte); vbc.push_back(1); } } } } } } } } } } void Cplex::contrainte16(vector >& vclique, vector& vbc) { for ( int subset=0 ; subset < CInstance::M((constraint_t) 16) ; subset++ ) { vector centralesDuSubset = CInstance::m_constraints16[subset].C(); wlen_t Se = CInstance::m_constraints16[subset].Se() ; int nbCentralesDuSubset = centralesDuSubset.size(); for ( powerplants2_t i=(powerplants2_t) 0 ; i < nbCentralesDuSubset ; i = (powerplants2_t) (i+1) ) { int idx_i = centralesDuSubset[i]; for ( powerplants2_t iprime= (powerplants2_t) 0 ; iprime < nbCentralesDuSubset ; iprime = (powerplants2_t) (iprime+1) ) { if ( i == iprime ){ continue; } int idx_iprime = centralesDuSubset[iprime]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( int i_colonneprime=0 ; i_colonneprime < Clique::annuaire[idx_iprime].size() ; i_colonneprime++ ) { int idx_colonneprime = Clique::annuaire[idx_iprime][i_colonneprime]; for ( int k=0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k++ ) { for ( int kprime=0 ; kprime < Clique::dateDebutOutageCampagneK[idx_colonneprime].size() ; kprime++ ) { if ( abs(Clique::dateDebutOutageCampagneK[idx_colonne][k] - Clique::dateDebutOutageCampagneK[idx_colonneprime][kprime]) < Se) { vector contrainte(nbColonnes, 0); contrainte[idx_colonne] = contrainte[idx_colonneprime] = 1; vclique.push_back(contrainte); vbc.push_back(1); } } } } } } } } } void Cplex::contrainte17(vector >& vclique, vector& vbc) { for ( int subset=0 ; subset < CInstance::M((constraint_t) 17) ; subset++ ) { vector centralesDuSubset = CInstance::m_constraints17[subset].C(); wlen_t Se = CInstance::m_constraints17[subset].Se() ; int nbCentralesDuSubset = centralesDuSubset.size(); for ( powerplants2_t i=(powerplants2_t) 0 ; i < nbCentralesDuSubset ; i = (powerplants2_t) (i+1) ) { int idx_i = centralesDuSubset[i]; for ( powerplants2_t iprime= (powerplants2_t) 0 ; iprime < nbCentralesDuSubset ; iprime = (powerplants2_t) (iprime+1) ) { if ( i == iprime ){ continue; } int idx_iprime = centralesDuSubset[iprime]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( int i_colonneprime=0 ; i_colonneprime < Clique::annuaire[idx_iprime].size() ; i_colonneprime++ ) { int idx_colonneprime = Clique::annuaire[idx_iprime][i_colonneprime]; for ( int k=0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k++ ) { for ( int kprime=0 ; kprime < Clique::dateDebutOutageCampagneK[idx_colonneprime].size() ; kprime++ ) { if ( abs(Clique::dateFinOutageCampagneK[idx_colonne][k] - Clique::dateFinOutageCampagneK[idx_colonneprime][kprime]) < Se) { vector contrainte(nbColonnes, 0); contrainte[idx_colonne] = contrainte[idx_colonneprime] = 1; vclique.push_back(contrainte); vbc.push_back(1); } } } } } } } } } void Cplex::contrainte18(vector >& vclique, vector& vbc) { for ( int subset=0 ; subset < CInstance::M((constraint_t) 18) ; subset++ ) { vector centralesDuSubset = CInstance::m_constraints18[subset].C(); wlen_t Se = CInstance::m_constraints18[subset].Se() ; int nbCentralesDuSubset = centralesDuSubset.size(); for ( powerplants2_t i=(powerplants2_t) 0 ; i < nbCentralesDuSubset ; i = (powerplants2_t) (i+1) ) { int idx_i = centralesDuSubset[i]; for ( powerplants2_t iprime= (powerplants2_t) 0 ; iprime < nbCentralesDuSubset ; iprime = (powerplants2_t) (iprime+1) ) { if ( i == iprime ){ continue; } int idx_iprime = centralesDuSubset[iprime]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( int i_colonneprime=0 ; i_colonneprime < Clique::annuaire[idx_iprime].size() ; i_colonneprime++ ) { int idx_colonneprime = Clique::annuaire[idx_iprime][i_colonneprime]; for ( int k=0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k++ ) { for ( int kprime=0 ; kprime < Clique::dateDebutOutageCampagneK[idx_colonneprime].size() ; kprime++ ) { if ( abs(Clique::dateFinOutageCampagneK[idx_colonne][k] - Clique::dateDebutOutageCampagneK[idx_colonneprime][kprime]) < Se) { vector contrainte(nbColonnes, 0); contrainte[idx_colonne] = contrainte[idx_colonneprime] = 1; vclique.push_back(contrainte); vbc.push_back(1); } } } } } } } } } void Cplex::contrainte19(vector >& vclique, vector& vbc) { #ifdef TEST_CC19 for ( int c19=0 ; c19 < 1 ; c19++ ) #else for ( int c19=0 ; c19 < CInstance::M((constraint_t) 19) ; c19++ ) #endif { #ifdef TEST_CC19 vector test; test.push_back((powerplants2_t) 0); test.push_back((powerplants2_t) 1);test.push_back((powerplants2_t) 2); vector centralesDuSubset = test; vector > utilisationRessource (10, vector (Cplex::nbColonnes, 0) ) ;// utilisationRessource[w][c] si la colonne c utilise la ressource int nbCentralesDuSubset = centralesDuSubset.size(); int nbRessources = 2; #else vector centralesDuSubset = CInstance::m_constraints19[c19].C(); vector > utilisationRessource (CInstance::H(), vector (Cplex::nbColonnes, 0) ) ;// utilisationRessource[w][c] si la colonne c utilise la ressource int nbCentralesDuSubset = centralesDuSubset.size(); int nbRessources = CInstance::m_constraints19[c19].Q(); #endif for ( int i= 0 ; i < nbCentralesDuSubset ; i++ ) { powerplants2_t idx_i = centralesDuSubset[i]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[(int) idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( campaign_t k=(campaign_t) 0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k=(campaign_t) (k+1) ) { #ifdef TEST_CC19 int start = 0; int duree = 2; #else int start = CInstance::m_constraints19[c19].L(idx_i,k); int duree = CInstance::m_constraints19[c19].TU(idx_i,k); #endif for ( int w=0 ; (w nbRessources ) { vclique.push_back(utilisationRessource[w]); vbc.push_back(nbRessources); } } } } void Cplex::contrainte20(vector >& vclique, vector& vbc) { #ifdef TEST_CC20 for ( int c20=0 ; c20 < 1 ; c20++ ) #else for ( int c20=0 ; c20 < CInstance::M((constraint_t) 20) ; c20++ ) #endif { #ifdef TEST_CC20 vector test; test.push_back((powerplants2_t) 0); test.push_back((powerplants2_t) 1);test.push_back((powerplants2_t) 2); vector centralesDuSubset = test; vector centralesAuRepos (Cplex::nbColonnes, 0 ) ;// centralesAuRepos[c] si la colonne c est en outage int nbCentralesDuSubset = centralesDuSubset.size(); int nbOutageMax = 2; week_t semaineConsideree = (week_t) 9; #else vector centralesDuSubset = CInstance::m_constraints20[c20].C(); vector centralesAuRepos (Cplex::nbColonnes, 0 ) ;// centralesAuRepos[c] si la colonne c est en outage int nbCentralesDuSubset = centralesDuSubset.size(); int nbOutageMax = CInstance::m_constraints20[c20].N(); week_t semaineConsideree = CInstance::m_constraints20[c20].h(); #endif int compteurCentralesAuRepos = 0; for ( int i= 0 ; i < nbCentralesDuSubset ; i++ ) { powerplants2_t idx_i = centralesDuSubset[i]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[(int) idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; for ( campaign_t k=(campaign_t) 0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k=(campaign_t) (k+1) ) { if ( (Clique::dateDebutOutageCampagneK[idx_colonne][k] <= semaineConsideree) && ( Clique::dateFinOutageCampagneK[idx_colonne][k] > semaineConsideree) ) { centralesAuRepos[idx_colonne] =1; compteurCentralesAuRepos++; break; } if ( Clique::dateDebutOutageCampagneK[idx_colonne][k] > semaineConsideree) { break; } } } } if (compteurCentralesAuRepos > nbOutageMax) { vclique.push_back(centralesAuRepos); vbc.push_back(nbOutageMax); } } } void Cplex::contrainte21(vector >& vclique, vector& vbc) { #ifdef TEST_CC21 for ( int c21=0 ; c21 < 1 ; c21++ ) #else for ( int c21=0 ; c21 < CInstance::M((constraint_t) 21) ; c21++ ) #endif { #ifdef TEST_CC21 vector test; test.push_back((powerplants2_t) 0); test.push_back((powerplants2_t) 1);test.push_back((powerplants2_t) 2); vector centralesDuSubset = test; CIntervalle intervalle; intervalle.start = (week_t) 2; intervalle.end = (week_t) 5 ; vector > puissanceAuRepos ((int) (intervalle.end-intervalle.start+1), vector (Cplex::nbColonnes, 0) ) ;// puissanceAuRepos[w-intervalle.start][c] = 0 si la colonne 'c' est utilisée, et sa PMAX sinon, int nbCentralesDuSubset = centralesDuSubset.size(); double puissanceMaxAuRepos = 5.0 ; #else vector centralesDuSubset = CInstance::m_constraints21[c21].C(); CIntervalle intervalle = CInstance::m_constraints21[c21].IT(); vector > puissanceAuRepos ((int) (intervalle.end-intervalle.start+1), vector (Cplex::nbColonnes, 0) ) ;// puissanceAuRepos[w-intervalle.start][c] = 0 si la colonne 'c' est utilisée, et sa PMAX sinon, int nbCentralesDuSubset = centralesDuSubset.size(); double puissanceMaxAuRepos = CInstance::m_constraints21[c21].IMAX(); #endif vector compteur(intervalle.end-intervalle.start+1, 0.0); //Boucle sur les centrales du subset for ( int i= 0 ; i < nbCentralesDuSubset ; i++ ) { //Boucle sur les colonnes relatives à la centrale courante powerplants2_t idx_i = centralesDuSubset[i]; for ( int i_colonne=0 ; i_colonne < Clique::annuaire[(int) idx_i].size() ; i_colonne++ ) { int idx_colonne = Clique::annuaire[idx_i][i_colonne]; //Boucle sur les campagnes de la colonne active for ( campaign_t k=(campaign_t) 0 ; k < Clique::dateDebutOutageCampagneK[idx_colonne].size() ; k=(campaign_t) (k+1) ) { if ( Clique::dateFinOutageCampagneK[idx_colonne][k] < intervalle.start ) { continue; } for ( week_t w = max(intervalle.start,Clique::dateDebutOutageCampagneK[idx_colonne][k]) ; w <= min(intervalle.end, Clique::dateFinOutageCampagneK[idx_colonne][k]) ;w=(week_t) (w+1) ) { #ifdef TEST_CC21 puissanceAuRepos[w-intervalle.start][idx_colonne] = (int) (2.1 + 0.995); compteur[w-intervalle.start] += 2.1; #else puissanceAuRepos[w-intervalle.start][idx_colonne] = (int) (CInstanceReduite::EMAX(idx_i, w) + 0.995); compteur[w-intervalle.start] += CInstanceReduite::EMAX(idx_i, w); #endif } if ( Clique::dateDebutOutageCampagneK[idx_colonne][k] > intervalle.end ) { break; } } } } //Ajout éventuel aux contraintes de clique for ( int w = 0 ; w < compteur.size() ; w++) { if ( compteur[w] > puissanceMaxAuRepos ) // Ajout de la contrainte avec arrondis par passage en int from double { vclique.push_back(puissanceAuRepos[w]); vbc.push_back((int) puissanceMaxAuRepos ); } } } } /* This simple routine frees up the pointer *ptr, and sets *ptr to NULL */ void Cplex::free_and_null (char **ptr) { if ( *ptr != NULL ) { free (*ptr); *ptr = NULL; } } /* END free_and_null */ int Cplex::setproblemdata (char **probname_p, int *numcols_p, int *numrows_p, int *objsen_p, double **obj_p, double **rhs_p, char **sense_p, int **matbeg_p, int **matcnt_p, int **matind_p, double **matval_p, double **lb_p, double **ub_p, char **ctype_p) { char *zprobname = NULL; /* Problem name <= 16 characters */ double *zobj = NULL; double *zrhs = NULL; char *zsense = NULL; int *zmatbeg = NULL; int *zmatcnt = NULL; int *zmatind = NULL; double *zmatval = NULL; double *zlb = NULL; double *zub = NULL; char *zctype = NULL; int status = 0; int i,j; zprobname = (char *) malloc (16 * sizeof(char)); zobj = (double *) malloc (NUMCOLS * sizeof(double)); zrhs = (double *) malloc (NUMROWS * sizeof(double)); zsense = (char *) malloc (NUMROWS * sizeof(char)); zmatbeg = (int *) malloc (NUMCOLS * sizeof(int)); zmatcnt = (int *) malloc (NUMCOLS * sizeof(int)); zmatind = (int *) malloc (NUMNZ * sizeof(int)); zmatval = (double *) malloc (NUMNZ * sizeof(double)); zlb = (double *) malloc (NUMCOLS * sizeof(double)); zub = (double *) malloc (NUMCOLS * sizeof(double)); zctype = (char *) malloc (NUMCOLS * sizeof(char)); if ( zprobname == NULL || zobj == NULL || zrhs == NULL || zsense == NULL || zmatbeg == NULL || zmatcnt == NULL || zmatind == NULL || zmatval == NULL || zctype == NULL || zlb == NULL || zub == NULL ) { status = 1; goto TERMINATE; } strcpy (zprobname, "mip"); /* The code is formatted to make a visual correspondence between the mathematical linear program and the specific data items. */ /* This function fills in the data structures for the linear program: */ for(i=0;i= zrhs[i] = dt[i]; } else if(i>=NUMTps && i<(NUMTps+NUMAff)) { zsense[i] = 'E'; zrhs[i] = 1.0; } else { zsense[i] = 'L'; zrhs[i] = (double)bc[i-(NUMTps+NUMAff)]; } } for(i=0;i=NUMTps) { if(jEPSILON)//MODIF pour accepter la contrainte 21 { zmatval[zmatbeg[i]+j] = clique[i][j-(NUMTps+NUMAff)];// A revoir contrainte 21cl } else { zmatval[zmatbeg[i]+j] = 0.0; } } // printf("1)i=%d j=%d zmatbeg=%d zmatval=%lf\n", i, j, zmatbeg[i], zmatval[zmatbeg[i]+j]); } else if(i>=NUMNucl && j Cplex::resolution() { /* Declare pointers for the variables and arrays that will contain the data which define the LP problem. The setproblemdata() routine allocates space for the problem data. */ vector result; char *probname = NULL; int numcols; int numrows; int objsen; double *obj = NULL; double *rhs = NULL; char *sense = NULL; int *matbeg = NULL; int *matcnt = NULL; int *matind = NULL; double *matval = NULL; double *lb = NULL; double *ub = NULL; char *ctype = NULL; /* Declare and allocate space for the variables and arrays where we will store the optimization results including the status, objective value, variable values, dual values, row slacks and variable reduced costs. */ // init(); NUMNucl = nbColonnes; NUMTps = H(); NUMAff = I(); NUMCliq = nbClique; NUMCOLS = NUMNucl+NUMTps; NUMROWS = NUMTps+NUMAff+NUMCliq; NUMNZ = NUMROWS * NUMCOLS; int solstat; double objval; double x[NUMCOLS]; double pi[NUMROWS]; double slack[NUMROWS]; double dj[NUMCOLS]; CPXENVptr env = NULL; CPXLPptr lp = NULL; int status; int i, j; int cur_numrows, cur_numcols; /* Initialize the CPLEX environment */ env = CPXopenCPLEX (&status); /* If an error occurs, the status value indicates the reason for failure. A call to CPXgeterrorstring will produce the text of the error message. Note that CPXopenCPLEX produces no output, so the only way to see the cause of the error is to use CPXgeterrorstring. For other CPLEX routines, the errors will be seen if the CPX_PARAM_SCRIND indicator is set to CPX_ON. */ if ( env == NULL ) { char errmsg[1024]; fprintf (stderr, "Could not open CPLEX environment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, "%s", errmsg); goto TERMINATE; } /* Turn on output to the screen */ status = CPXsetintparam (env, CPX_PARAM_SCRIND, CPX_ON); if ( status ) { fprintf (stderr, "Failure to turn on screen indicator, error %d.\n", status); goto TERMINATE; } /* Allocate memory and fill in the data for the problem. */ status = setproblemdata (&probname, &numcols, &numrows, &objsen, &obj, &rhs, &sense, &matbeg, &matcnt, &matind, &matval, &lb, &ub, &ctype); if ( status ) { fprintf (stderr, "Failed to build problem data arrays.\n"); goto TERMINATE; } /* Create the problem. */ lp = CPXcreateprob (env, &status, probname); /* A returned pointer of NULL may mean that not enough memory was available or there was some other problem. In the case of failure, an error message will have been written to the error channel from inside CPLEX. In this example, the setting of the parameter CPX_PARAM_SCRIND causes the error message to appear on stdout. */ if ( lp == NULL ) { fprintf (stderr, "Failed to create LP.\n"); goto TERMINATE; } /* Now copy the problem data into the lp */ status = CPXcopylp (env, lp, numcols, numrows, objsen, obj, rhs, sense, matbeg, matcnt, matind, matval, lb, ub, NULL); if ( status ) { fprintf (stderr, "Failed to copy problem data.\n"); goto TERMINATE; } /* Now copy the ctype array */ status = CPXcopyctype (env, lp, ctype); if ( status ) { fprintf (stderr, "Failed to copy ctype\n"); goto TERMINATE; } /* Finally, write a copy of the problem to a file. */ status = CPXwriteprob (env, lp, "mip.lp", NULL); if ( status ) { fprintf (stderr, "Failed to write LP to disk.\n"); goto TERMINATE; } /* Optimize the problem and obtain solution. */ status = CPXmipopt (env, lp); if ( status ) { fprintf (stderr, "Failed to optimize LP.\n"); goto TERMINATE; } solstat = CPXgetstat (env, lp); /* Write the output to the screen. */ printf ("\nSolution status = %d\n", solstat); status = CPXgetmipobjval (env, lp, &objval); if ( status ) { fprintf (stderr,"No MIP objective value available. Exiting...\n"); goto TERMINATE; } printf ("Solution value = %f\n\n", objval); /* The size of the problem should be obtained by asking CPLEX what the actual size is, rather than using what was passed to CPXcopylp. cur_numrows and cur_numcols store the current number of rows and columns, respectively. */ cur_numrows = CPXgetnumrows (env, lp); cur_numcols = CPXgetnumcols (env, lp); status = CPXgetmipx (env, lp, x, 0, cur_numcols-1); if ( status ) { fprintf (stderr, "Failed to get optimal integer x_cplex.\n"); goto TERMINATE; } status = CPXgetmipslack (env, lp, slack, 0, cur_numrows-1); if ( status ) { fprintf (stderr, "Failed to get optimal slack values.\n"); goto TERMINATE; } for (i = 0; i < cur_numrows; i++) { printf ("Row %d: Slack = %10f\n", i, slack[i]); } for (j = 0; j < cur_numcols; j++) { printf ("Column %d: Value = %10f\n", j, x[j]); } for ( int i=0 ; i < cur_numcols ; i++ ) { result.push_back(x[i]); } TERMINATE: /* Free up the problem as allocated by CPXcreateprob, if necessary */ if ( lp != NULL ) { status = CPXfreeprob (env, &lp); if ( status ) { fprintf (stderr, "CPXfreeprob failed, error code %d.\n", status); } } /* Free up the CPLEX environment, if necessary */ if ( env != NULL ) { status = CPXcloseCPLEX (&env); /* Note that CPXcloseCPLEX produces no output, so the only way to see the cause of the error is to use CPXgeterrorstring. For other CPLEX routines, the errors will be seen if the CPX_PARAM_SCRIND indicator is set to CPX_ON. */ if ( status ) { char errmsg[1024]; fprintf (stderr, "Could not close CPLEX environment.\n"); CPXgeterrorstring (env, status, errmsg); fprintf (stderr, "%s", errmsg); } } /* Free up the problem data arrays, if necessary. */ free_and_null ((char **) &probname); free_and_null ((char **) &obj); free_and_null ((char **) &rhs); free_and_null ((char **) &sense); free_and_null ((char **) &matbeg); free_and_null ((char **) &matcnt); free_and_null ((char **) &matind); free_and_null ((char **) &matval); free_and_null ((char **) &lb); free_and_null ((char **) &ub); free_and_null ((char **) &ctype); return (result); } Cplex::~Cplex() { #ifndef TEST_CC14 #ifndef TEST_CC19 #ifndef TEST_CC20 #ifndef TEST_CC21 DEBUG_CPLEX_PRINT("deletage de cl"); delete[] cl; DEBUG_CPLEX_PRINT("deletage de ct"); delete[] ct; DEBUG_CPLEX_PRINT("deletage du contenu de dlt, affect et clique"); for ( int i=0 ; i < nbColonnes ; i++ ){ delete[] dlt[i]; delete[] affect[i]; delete[] clique[i]; } DEBUG_CPLEX_PRINT("deletage de dlt"); delete[] dlt; DEBUG_CPLEX_PRINT("deletage de affect"); delete[] affect; DEBUG_CPLEX_PRINT("deletage de clique"); delete[] clique; DEBUG_CPLEX_PRINT("deletage de dt"); delete[] dt; DEBUG_CPLEX_PRINT("deletage de Mint"); delete[] Mint; DEBUG_CPLEX_PRINT("deletage de Maxt"); delete[] Maxt; DEBUG_CPLEX_PRINT("deletage de bc"); delete[] bc; #endif #endif #endif #endif }