//========================================================================== // Restore bounds and type of the first stage variables int DDSIP_RestoreBoundAndType (void) { int status = 0; if ((DDSIP_bb->DDSIP_step == neobj || DDSIP_bb->DDSIP_step == eev) && DDSIP_param->riskvar) DDSIP_UndeleteRiskObj (); // Restore original bounds status = CPXchgbds (DDSIP_env, DDSIP_lp, DDSIP_bb->firstvar, DDSIP_bb->firstindex, DDSIP_bb->lbident, DDSIP_bb->lborg); if (status) { fprintf (stderr, "ERROR: Failed to change lower bounds \n"); return status; } status = CPXchgbds (DDSIP_env, DDSIP_lp, DDSIP_bb->firstvar, DDSIP_bb->firstindex, DDSIP_bb->ubident, DDSIP_bb->uborg); if (status) { fprintf (stderr, "ERROR: Failed to change upper bounds \n"); return status; } // probtype=0 (LP) if (!CPXgetprobtype (DDSIP_env, DDSIP_lp)) { status = CPXchgprobtype (DDSIP_env, DDSIP_lp, CPXPROB_MILP); if (status) { fprintf (stderr, "ERROR: Failed to change problem type (Restore) \n"); return status; } status = CPXchgctype (DDSIP_env, DDSIP_lp, DDSIP_bb->secvar, DDSIP_bb->secondindex, DDSIP_bb->sectype); if (status) { fprintf (stderr, "ERROR: Failed to change types of second-stage variables (Restore) \n"); return status; } } //Restore ctypes if solving was processed with relaxed first stage if (DDSIP_bb->DDSIP_step == solve && DDSIP_param->relax == 1) { status = CPXchgctype (DDSIP_env, DDSIP_lp, DDSIP_bb->firstvar, DDSIP_bb->firstindex, DDSIP_bb->firsttype); if (status) { fprintf (stderr, "ERROR: Failed to change types of first stage variables (Restore) \n"); return status; } } return status; }
void PartitionedColoringModel::changeToBinaryVariables() { // Cambiamos el tipo de variables a binarias. int *indices = new int[this->amountOfVariables]; char *types = new char[this->amountOfVariables]; char *setLower = new char[this->amountOfVariables]; char *setUpper = new char[this->amountOfVariables]; double *lowerBound = new double[this->amountOfVariables]; double *upperBound = new double[this->amountOfVariables]; int i; for(i = 0; i < this->amountOfVariables; i++) { indices[i] = i; types[i] = 'B'; setLower[i] = 'L'; setUpper[i] = 'U'; lowerBound[i] = 0; upperBound[i] = 1; } CPXchgctype(this->cplexEnvironment, this->linearProblem, this->amountOfVariables, indices, types); CPXchgbds(this->cplexEnvironment, this->linearProblem, this->amountOfVariables, indices, setLower, lowerBound); CPXchgbds(this->cplexEnvironment, this->linearProblem, this->amountOfVariables, indices, setUpper, upperBound); delete [] indices; delete [] types; delete [] setLower; delete [] setUpper; delete [] lowerBound; delete [] upperBound; }
void SSCplex::ChgBds(int z, double newval ){ int j; int status; char lu; double bd; assert( newval == 0.0); j = z; bd = newval; lu = 'U'; status = CPXchgbds(env, lp, 1, &j, &lu, &bd); if ( status ) { stop("Failed to change bounds.\n", status); } };
long GenModelCplex::ChangeBulkBounds(int count, int * ind, char * type, double * vals) { if(!bcreated) return ThrowError("ChangeBulkBounds not available : Problem not created yet"); CplexData* d = (CplexData*)solverdata; for(long i = 0; i < count; i++) { if (type[i] == 'L' || type[i] == 'B') { vars.lb[ind[i]] = vals[i]; } if (type[i] == 'U' || type[i] == 'B') { vars.ub[ind[i]] = vals[i]; } } CPXchgbds(d->env, d->lp, count, ind, type, vals); return 0; }
int CPLEXLoadVariables(MFAVariable* InVariable, bool RelaxIntegerVariables,bool UseTightBounds) { int Status = 0; //First I check the number of columns. If it's larger than the index, then this variable already exists and is only being changed int NumberColumns = CPXgetnumcols (CPLEXenv, CPLEXModel); if (NumberColumns <= InVariable->Index) { string StrName = GetMFAVariableName(InVariable); double* LB = new double; LB[0] = InVariable->LowerBound; double* UB = new double; UB[0] = InVariable->UpperBound; if (UseTightBounds) { LB[0] = InVariable->Min; UB[0] = InVariable->Max; } double* Obj = new double; Obj[0] = 0; char* Temp = new char; char** Name = new char*; Name[0] = new char[StrName.length()+1]; strcpy(Name[0],StrName.data()); if (InVariable->Binary && !RelaxIntegerVariables) { Temp[0] = CPX_BINARY; Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name); } else if (InVariable->Integer && !RelaxIntegerVariables) { Temp[0] = CPX_INTEGER; Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name); } else { Temp[0] = CPX_CONTINUOUS; Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name); } delete LB; delete UB; delete Obj; delete Temp; delete [] Name[0]; delete Name; if (Status ) { FErrorFile() << "Could not add variable " << InVariable->Index << endl; FlushErrorFile(); return FAIL; } } else { double* Bounds = new double[2]; Bounds[0] = InVariable->LowerBound; Bounds[1] = InVariable->UpperBound; int* Indices = new int[2]; Indices[0] = InVariable->Index; Indices[1] = InVariable->Index; Status = CPXchgbds (CPLEXenv, CPLEXModel, 2, Indices, "LU", Bounds); delete [] Bounds; delete [] Indices; if (Status) { FErrorFile() << "Could not change bounds on variable " << InVariable->Index << endl; FlushErrorFile(); return FAIL; } } return SUCCESS; }