17 #include "DecompVar.h"
25 UtilPrintFuncBegin(m_osLog,
m_classTag,
"initializeApp()",
41 throw ErrorClass(
"An OSiL file not specified in the parameter file");
74 std::vector<OSInstance*>::iterator vit1;
76 std::string solverFactory;
110 std::vector<std::set<int> >::iterator vit;
111 std::set<int>::iterator sit;
112 std::set<int> blockVar;
118 for (sit = blockVar.begin(); sit != blockVar.end(); sit++) {
191 UtilPrintFuncEnd(m_osLog,
m_classTag,
"initializeApp()",
198 const int nRowsPart,
const int * rowsPart) {
207 std::cout <<
"STARTING createModelPart" << std::endl;
209 model->M =
new CoinPackedMatrix(
false, 0.0, 0.0);
212 throw UtilExceptionMemory(
"createModels",
"OSDipApp");
213 model->reserve(nRowsPart, nCols);
222 for (i = 0; i < nRowsPart; i++) {
225 const char * rowName =
229 model->rowNames.push_back(rowName);
233 model->rowLB.push_back(rowLB[r]);
234 model->rowUB.push_back(rowUB[r]);
236 copy(colLB, colLB + nCols, back_inserter(model->colLB));
237 copy(colUB, colUB + nCols, back_inserter(model->colUB));
254 for (i = 0; i < nCols; i++) {
255 if (colUB[i] > 1.0e15) {
261 for (i = 0; i < nCols; i++) {
262 if (colLB[i] < -1.0e15) {
272 for (i = 0; i < nCols; i++) {
278 model->colNames.push_back(colName);
281 if ((integerVars != NULL) && integerVars[i] ==
'1') {
283 model->integerVars.push_back(i);
288 UTIL_DELARR(integerVars);
295 UtilPrintFuncBegin(m_osLog,
m_classTag,
"createModels()",
300 int *rowsCore = NULL;
304 std::set<int>::iterator sit;
305 std::string modelName;
312 for (i = 0; i < nCols; i++) {
320 for (i = 0; i < numBlocks; i++) {
322 modelName =
"Block" + UtilIntToStr(i);
323 setModelRelax(NULL, modelName, i);
330 throw ErrorClass(
"We need at least one coupling constraint");
332 rowsCore =
new int[nRowsCore];
339 rowsCore[coreRowIndex++] = *sit;
343 if (coreRowIndex != nRowsCore)
344 throw ErrorClass(
"There was an error counting coupling constraints");
346 DecompConstraintSet * modelCore =
new DecompConstraintSet();
349 setModelCore(modelCore,
"core");
361 for (i = 0; i < nCols; i++) {
364 modelCore->masterOnlyCols.push_back(i);
374 int nMasterOnlyCols =
375 static_cast<int> (modelCore->masterOnlyCols.size());
376 if (nMasterOnlyCols) {
378 (*m_osLog) <<
"Create model part Master-Only." << std::endl;
384 UtilPrintFuncBegin(m_osLog,
m_classTag,
"printCurrentProblem()",
389 UTIL_DELARR(rowsCore);
406 int nBlocks =
static_cast<int> (
m_blockVars.size());
411 int nMasterOnlyCols =
static_cast<int> (masterOnlyCols.size());
414 (*m_osLog) <<
"nCols = " << nCols << std::endl;
415 (*m_osLog) <<
"nMasterOnlyCols = " << nMasterOnlyCols << std::endl;
418 if (nMasterOnlyCols == 0)
422 std::vector<int>::iterator vit;
423 for (vit = masterOnlyCols.begin(); vit != masterOnlyCols.end(); vit++) {
429 DecompConstraintSet * model =
new DecompConstraintSet();
430 model->m_masterOnly =
true;
431 model->m_masterOnlyIndex = i;
432 model->m_masterOnlyLB = colLB[i];
434 model->m_masterOnlyUB = colUB[i];
437 if (integerVars[i] ==
'1')
438 model->m_masterOnlyIsInt =
true;
441 if (colUB[i] > 1.0e15)
444 if (colLB[i] < -1.0e15)
448 setModelRelax(model,
"master_only" + UtilIntToStr(i), nBlocks);
452 UTIL_DELARR(integerVars);
464 std::cout <<
"GENERATE INIT VARS" << std::endl;
465 UtilPrintFuncBegin(m_osLog,
m_classTag,
"generateInitVars()",
474 std::vector<OtherVariableOption*> otherVarOptions;
475 std::vector<OtherVariableOption*>::iterator vit;
477 double *value = NULL;
487 std::cout <<
"Number of other variable options = "
494 for (vit = otherVarOptions.begin(); vit != otherVarOptions.end(); vit++) {
498 if ((*vit)->name.compare(
"initialCol") == 0) {
500 index =
new int[(*vit)->numberOfVar];
501 value =
new double[(*vit)->numberOfVar];
505 for (i = 0; i < (*vit)->numberOfVar; i++) {
507 index[i] = (*vit)->var[i]->idx;
510 value[i] = atoi((*vit)->var[i]->value.c_str());
515 whichBlock = atoi((*vit)->value.c_str());
516 var =
new DecompVar((*vit)->numberOfVar, index, value,
518 var->setBlockId(whichBlock);
519 initVars.push_back(var);
585 UtilPrintFuncEnd(m_osLog,
m_classTag,
"generateInitVars()",
587 return static_cast<int> (initVars.size());
591 const double * redCostX,
const double convexDual,
592 std::list<DecompVar*> & vars) {
594 UtilPrintFuncBegin(m_osLog,
m_classTag,
"solveRelaxed()",
597 std::vector<int> solInd;
598 std::vector<double> solEls;
599 double varRedCost = 0.0;
600 double varOrigCost = 0.0;
603 std::set<int> blockVar;
609 std::set<int>::iterator sit;
610 std::vector<IndexValuePair*> solIndexValPair;
611 std::vector<IndexValuePair*>::iterator vit;
618 cost =
new double[ blockVar.size()];
622 int reverseMapSize = blockVar.size();
623 reverseMap =
new int[ reverseMapSize];
625 for (sit = blockVar.begin(); sit != blockVar.end(); sit++) {
627 cost[index] = redCostX[*sit];
628 reverseMap[ index] = *sit;
661 for (vit = solIndexValPair.begin(); vit != solIndexValPair.end(); vit++) {
664 solInd.push_back( reverseMap[ (*vit)->idx] ) ;
665 solEls.push_back( (*vit)->value ) ;
667 varOrigCost +=
m_objective[ reverseMap[ (*vit)->idx]]*(*vit)->value;
684 std::cout <<
"WHICH BLOCK " << whichBlock << std::endl;
685 std::cout <<
"Convex Dual = " << convexDual << std::endl;
686 std::cout <<
"ORIGINAL COST = = " << varOrigCost << std::endl;
687 std::cout <<
"SUPROBLEM OPT VAL = " << varRedCost << std::endl;
688 printf(
"PUSH var with RC = %g\n", varRedCost - convexDual);
692 DecompVar * var =
new DecompVar(solInd, solEls, varRedCost - convexDual,
695 var->setBlockId( whichBlock);
698 UtilPrintFuncEnd(m_osLog,
m_classTag,
"APPsolveRelaxed()",
705 return DecompSolStatOptimal;
710 DecompCutList & newCuts){
712 std::cout <<
"I AM INSIDE GENERATE CUTS, IT WAS CALLED" << std::endl;
722 const double tolZero){
724 std::cout <<
"I AM INSIDE APPIS USER FEASIBLE, IT WAS CALLED" << std::endl;
bool APPisUserFeasible(const double *x, const int n_cols, const double tolZero)
void getSettings(UtilParameters &utilParam)
DecompConstraintSet * m_modelC
The model constraint systems used for different algos.
int m_whichBlock
m_whichBlock is the index of the subproblem we are working with
const int getVariableNumber() const
Get variable number.
void dumpSettings(std::ostream *os=&std::cout)
std::string errormsg
errormsg is the error that is causing the exception to be thrown
const std::string m_classTag
Class id tag (for log / debugging).
const double * getColLower() const
Get variable lower bounds.
CoinPackedMatrix * m_coinpm
double * getObjectiveFunctionCoeff()
Returns array[getNumCols()] specifying if a variable is integer.
void createModelMasterOnlys2(std::vector< int > &masterOnlyCols)
std::vector< OSDipBlockSolver * > m_osDipBlockSolver
m_osDipBlockSolver is a vector OSDipBlockSolvers
OSDipParam m_appParam
Application specific parameters.
void initializeApp(UtilParameters &utilParam)
Initialize application.
const double * getColUpper() const
Get variable upper bounds.
void createModels()
Create model parts.
std::set< int > m_blockVarsAll
m_blockVarsAll is the set of all variables that appear in a block
std::string solverFactory
const std::string * getConstraintNames() const
Get constraint names.
std::vector< std::set< int > > getBlockVarIndexes()
Returns array[getNumCols()] specifying if a variable is integer.
void readOSiL(std::string &filename)
Returns array[getNumCols()] specifying if a variable is integer.
static std::map< std::string, OSDipBlockSolverFactory * > factories
std::map< int, DecompConstraintSet * > m_modelMasterOnly
The model constraint system used master only vars.
const double * getRowUpper() const
Get constraint upper bounds.
void createModelPart(DecompConstraintSet *model, const int nRowsPart, const int *rowsPart)
std::vector< OSInstance * > m_blockOSInstances
m_blockOSInstances is a vector with an osinstance for each block
double * m_objective
The model objective coefficients (original space).
void fint fint fint real fint real real real real real real real * r
int generateCuts(const double *x, DecompCutList &newCuts)
const double * getRowLower() const
Get constraint lower bounds.
OS_DipInterface m_osInterface
the OS interface
std::set< int > getCoreConstraintIndexes()
Returns array[getNumCols()] specifying if a variable is integer.
std::vector< std::set< int > > m_blockVars
m_blockVars is a vector with the set of variables for each block
void readOSoL(std::string &filename)
Returns array[getNumCols()] specifying if a variable is integer.
DecompSolverStatus solveRelaxed(const int whichBlock, const double *redCostX, const double convexDual, std::list< DecompVar * > &vars)
Solve the relaxed problem.
std::vector< OSInstance * > getBlockOSInstances()
Returns array[getNumCols()] specifying if a variable is integer.
std::set< int > m_coreConstraintIndexes
m_coreConstraintIndexes is the set core constraint indexes
const std::string * getVariableNames() const
Get variable names.
std::vector< std::string > getBlockFactories()
Returns array[getNumCols()] specifying if a variable is integer.
OSDipFactoryInitializer * factoryInit
const char * getIntegerColumns()
Returns array[getNumCols()] specifying if a variable is integer.
int generateInitVars(DecompVarList &initVars)
int getNumberOfOtherVariableOptions()
Get the number of other variable options.
std::vector< std::string > m_blockFactories
m_blockFactories is a vector solver factory for each block
used for throwing exceptions.
void fint fint fint real fint real * x
std::vector< OtherVariableOption * > getOtherVariableOptions(std::string solver_name)
Get the <other> variable options associated with a particular solver.