/home/coin/SVN-release/OS-2.4.2/examples/osDip/OSDipAppOld.cpp

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the Decomp Solver Framework.                         //
00003 //                                                                           //
00004 // Decomp is distributed under the Common Public License as part of the      //
00005 // COIN-OR repository (http://www.coin-or.org).                              //
00006 //                                                                           //
00007 // Author: Matthew Galati, Lehigh University  
00008 // Heavily edited by Kipp Martin, University of Chicago
00009 //                                                                           //
00010 // Copyright (C) 2002-2009, Lehigh University, Matthew Galati, and Ted Ralphs//
00011 // All Rights Reserved.                                                      //
00012 //===========================================================================//
00013 
00014 //===========================================================================//
00015 #include "OSDipApp.h"
00016 //===========================================================================//
00017 #include "DecompVar.h"
00018 
00019 void OSDipApp::initializeApp(UtilParameters & utilParam) {
00020 
00021         UtilPrintFuncBegin(m_osLog, m_classTag, "initializeApp()",
00022                         m_appParam.LogLevel, 2);
00023 
00024         //---
00025         //--- get application parameters
00026         //---
00027         m_appParam.getSettings(utilParam);
00028         if (m_appParam.LogLevel >= 1)
00029                 m_appParam.dumpSettings(m_osLog);
00030 
00031         try {
00032 
00033                 //---
00034                 //--- read OSiL instance
00035                 //
00036                 if (m_appParam.OSiLFile.size() <= 1)
00037                         throw ErrorClass("An OSiL file not specified in the paramater file");
00038                 std::string osilFile = m_appParam.DataDir + UtilDirSlash()
00039                                 + m_appParam.OSiLFile;
00040                 m_osInterface.readOSiL( osilFile);
00041 
00042                 //---
00043                 //--- read OSoL instance --  it is not necessary, if not there
00044                 //--  all constraints become block constraints
00045                 //
00046                 //if(m_appParam.OSoLFile.size() <=  1) throw ErrorClass("An OSoL file not specified in the paramater file");
00047                 if (m_appParam.OSoLFile.size() > 0) {
00048                         std::string osolFile = m_appParam.DataDir + UtilDirSlash()
00049                                         + m_appParam.OSoLFile;
00050                         m_osInterface.readOSoL( osolFile);
00051                 }
00052 
00053                 //---
00054                 //--- create models
00055                 //---
00056                 createModels();
00057                 
00058                 
00059                 //just temporary playing around
00118                 m_blockOSInstances = m_osInterface.getBlockOSInstances();
00119                 //loop over the instances and generate a solver
00120                 std::vector<OSInstance* >::iterator vit1;
00121                 
00122                 OSDipBlockCoinSolver *coinSolver = NULL;
00123                 
00124                 for (vit1 = m_blockOSInstances.begin(); vit1 != m_blockOSInstances.end(); vit1++) {
00125                         
00126                         coinSolver = new OSDipBlockCoinSolver( *vit1)  ;                        
00127                         m_osDipBlockCoinSolver.push_back( coinSolver ) ;
00128                         
00129                 }
00130                 
00131                 std::vector<std::set<int> >::iterator vit2;
00132                 std::set<int>::iterator sit;
00133                 std::set<int> blockVar;
00134                 std::vector<IndexValuePair*> solIndexValPair;
00135                 std::vector<IndexValuePair*>::iterator vit3;
00136                 double optVal;
00137                 
00138                 double *cost = NULL;
00139                 int index;
00140                 int whichBlock;
00141                 
00142                 m_blockVars = m_osInterface.getBlockVarIndexes();
00143                 whichBlock = 0;
00144                 
00145                 for (vit2 = m_blockVars.begin(); vit2 != m_blockVars.end(); vit2++) {
00146                         
00147                         blockVar = *vit2;
00148                         
00149                         cost = new double[ blockVar.size() ];
00150                         
00151                         index = 0;
00152                         
00153                         for (sit = blockVar.begin(); sit != blockVar.end(); sit++) {
00154                                 
00155                                 cost[index] = m_objective[ *sit];
00156                                 index++;
00157                         
00158                         }
00159                         
00160                         m_osDipBlockCoinSolver[whichBlock++]->solve( cost, &solIndexValPair, &optVal);
00161                         
00162                         std::cout << "OPTIMAL VALUE  = " << optVal  << std::endl;
00163                         
00164                         std::cout << "solIndexValPair SIZE 2 = " << solIndexValPair.size()  << std::endl;
00165                         
00166                         for (vit3 = solIndexValPair.begin(); vit3 != solIndexValPair.end(); vit3++) {
00167                                 
00168                                 std::cout << "IDEX =  " << (*vit3)->idx << std::endl;
00169                                 std::cout << "VALUE =  " << (*vit3)->value << std::endl;
00170                         }
00171                         
00172                         delete []cost;
00173                         
00174                         
00175                 }
00176                 
00177                 
00178         } catch (const ErrorClass& eclass) {
00179 
00180                 throw ErrorClass(eclass.errormsg);
00181 
00182         }
00183 
00184         UtilPrintFuncEnd(m_osLog, m_classTag, "initializeApp()",
00185                         m_appParam.LogLevel, 2);
00186 
00187 }//end initializeApp
00188 
00189 //===========================================================================//
00190 void OSDipApp::createModelPart(DecompConstraintSet * model,
00191                 const int nRowsPart, const int * rowsPart) {
00192 
00193         const int nCols = m_osInterface.getVariableNumber();
00194         const double * rowLB = m_osInterface.getRowLower();
00195         const double * rowUB = m_osInterface.getRowUpper();
00196         const double * colLB = m_osInterface.getColLower();
00197         const double * colUB = m_osInterface.getColUpper();
00198         const char * integerVars = m_osInterface.getIntegerColumns();
00199 
00200         std::cout << "STARTING createModelPart" << std::endl;
00201 
00202         model->M = new CoinPackedMatrix(false, 0.0, 0.0);
00203 
00204         if (!model->M)
00205                 throw UtilExceptionMemory("createModels", "OSDipApp");
00206         model->reserve(nRowsPart, nCols);
00207         model->M->submatrixOf(*m_osInterface.m_coinpm, nRowsPart,
00208                         rowsPart);
00209 
00210         //---
00211         //--- set the row upper and lower bounds
00212         //--- set the col upper and lower bounds
00213         //---
00214         m_appParam.UseNames = true;
00215         int i, r;
00216         for (i = 0; i < nRowsPart; i++) {
00217                 r = rowsPart[i];
00218                 if (m_appParam.UseNames == true) {
00219                         const char * rowName =
00220                                         m_osInterface.getConstraintNames()[r].c_str();
00221                         //              std::cout << "Row Name = " << m_osInterface.getConstraintNames()[r] << std::endl;
00222                         if (rowName)
00223                                 model->rowNames.push_back(rowName);
00224                         
00225                         //std::cout << "Row Name = " << m_osInterface.getConstraintNames()[r] << std::endl;
00226                 }
00227                 model->rowLB.push_back(rowLB[r]);
00228                 model->rowUB.push_back(rowUB[r]);
00229         }
00230         copy(colLB, colLB + nCols, back_inserter(model->colLB));
00231         copy(colUB, colUB + nCols, back_inserter(model->colUB));
00232 
00233         //---
00234         //--- big fat hack... we don't deal with dual rays yet,
00235         //---  so, we assume subproblems are bounded
00236         //---
00237         //--- NOTE: might also need to tighten LBs
00238         //---
00239         //--- Too small - ATM infeasible!
00240         //--- Too big   - round off issues with big coeffs in 
00241         //---             master-only vars
00242         //---
00243         //--- TODO: need extreme rays or bounded subproblems from user
00244         //---
00245 
00246 
00247         if (m_appParam.ColumnUB < 1.0e15) {
00248                 for (i = 0; i < nCols; i++) {
00249                         if (colUB[i] > 1.0e15) {
00250                                 model->colUB[i] = m_appParam.ColumnUB;
00251                         }
00252                 }
00253         }
00254         if (m_appParam.ColumnLB > -1.0e15) {
00255                 for (i = 0; i < nCols; i++) {
00256                         if (colLB[i] < -1.0e15) {
00257                                 model->colLB[i] = m_appParam.ColumnLB;
00258                         }
00259                 }
00260         }
00261 
00262         //---
00263         //--- set the indices of the integer variables of modelRelax
00264         //---  also set the column names, if they exist
00265         //---
00266         for (i = 0; i < nCols; i++) {
00267                 if (m_appParam.UseNames == true) {
00268                         //const char * colName =  m_osInterface.columnName(i);
00269                         const char * colName =
00270                                         m_osInterface.getVariableNames()[i].c_str();
00271 
00272                         if (colName)
00273                                 model->colNames.push_back(colName);
00274                 }
00275                 
00276                 if ( (integerVars != NULL)   && integerVars[i] == '1' ) {
00277                         //std::cout  << "WE HAVE AN INTEGER VARIABLE " << std::endl;
00278                         model->integerVars.push_back(i);
00279                 }
00280         }
00281         
00282                                         
00283          //free local memory
00284          UTIL_DELARR( integerVars);
00285         
00286 }
00287 
00288 //===========================================================================//
00289 void OSDipApp::createModelPartSparse(DecompConstraintSet * model,
00290                 const int nRowsPart, const int * rowsPart) {
00291 
00292         const int nColsOrig = m_osInterface.getVariableNumber();
00293         const double * rowLB = m_osInterface.getRowLower();
00294         const double * rowUB = m_osInterface.getRowUpper();
00295         const double * colLB = m_osInterface.getColLower();
00296         const double * colUB = m_osInterface.getColUpper();
00297         const char * integerVars = m_osInterface.getIntegerColumns();
00298 
00299         //---
00300         //--- set model as sparse
00301         //---
00302         model->setSparse(nColsOrig);
00303         int nCols, origIndex, newIndex;
00304         vector<int>::iterator vit;
00305         newIndex = 0;
00306         for (vit = model->activeColumns.begin(); vit != model->activeColumns.end(); vit++) {
00307                 origIndex = *vit;
00308 
00309                 //std::cout << "lower bound = " << colLB[origIndex] << std::endl;
00310                 //std::cout << "upper bound = " << colUB[origIndex] << std::endl;
00311 
00312                 model->pushCol(colLB[origIndex], colUB[origIndex],
00313                                 integerVars[origIndex] == '0' ? false : true, origIndex);
00314                                 
00315                                 
00316                 if(integerVars[origIndex] == 0)  std::cout << "HERE I AM" << std::endl;
00317                 
00318 
00319                 //---
00320                 //--- big fat hack... we don't deal with dual rays yet,
00321                 //---  so, we assume subproblems are bounded
00322                 //---
00323 
00324                 if (m_appParam.ColumnUB < 1.0e15) {
00325                         if (colUB[origIndex] > 1.0e15) {
00326                                 model->colUB[newIndex] = m_appParam.ColumnUB;
00327                         }
00328                 }
00329                 if (m_appParam.ColumnLB > -1.0e15) {
00330                         if (colLB[origIndex] < -1.0e15) {
00331                                 model->colLB[newIndex] = m_appParam.ColumnLB;
00332                         }
00333                 }
00334 
00335                 if (m_appParam.UseNames) {
00336                         //const char * colName =  m_osInterface.columnName(origIndex);
00337                         const char * colName =
00338                                         m_osInterface.getConstraintNames()[origIndex].c_str();
00339 
00340                         if (colName)
00341                                 model->colNames.push_back(colName);
00342                 }
00343                 newIndex++;
00344         }
00345 
00346         nCols = static_cast<int> (model->activeColumns.size());
00347         assert(static_cast<int> (model->colLB.size()) == nCols);
00348         assert(static_cast<int> (model->colUB.size()) == nCols);
00349 
00350         model->M = new CoinPackedMatrix(false, 0.0, 0.0);
00351         if (!model->M)
00352                 throw UtilExceptionMemory("createModels", "OSDipApp");
00353         model->M->setDimensions(0, nCols);
00354         model->reserve(nRowsPart, nCols);
00355 
00356         //---
00357         //--- for each row in rowsPart, create the row using sparse mapping
00358         //---
00359         int i, k, r, begInd;
00360         const map<int, int> & origToSparse = model->getMapOrigToSparse();
00361         const CoinPackedMatrix * M = m_osInterface.getCoinPackedMatrix();
00362         const int * matInd = M->getIndices();
00363         const CoinBigIndex * matBeg = M->getVectorStarts();
00364         const int * matLen = M->getVectorLengths();
00365         const double * matVal = M->getElements();
00366         const int * matIndI = NULL;
00367         const double * matValI = NULL;
00368 
00369         vector<CoinBigIndex> & rowBeg = model->m_rowBeg;//used as temp
00370         vector<int> & rowInd = model->m_rowInd;//used as temp
00371         vector<double> & rowVal = model->m_rowVal;//used as temp
00372         map<int, int>::const_iterator mit;
00373 
00374         begInd = 0;
00375         rowBeg.push_back(0);
00376         for (i = 0; i < nRowsPart; i++) {
00377                 r = rowsPart[i];
00378                 if (m_appParam.UseNames) {
00379                         const char * rowName =
00380                                         m_osInterface.getConstraintNames()[r].c_str();
00381                         if (rowName)
00382                                 model->rowNames.push_back(rowName);
00383                 }
00384                 model->rowLB.push_back(rowLB[r]);
00385                 model->rowUB.push_back(rowUB[r]);
00386 
00387                 matIndI = matInd + matBeg[r];
00388                 matValI = matVal + matBeg[r];
00389                 for (k = 0; k < matLen[r]; k++) {
00390                         origIndex = matIndI[k];
00391                         mit = origToSparse.find(origIndex);
00392                         assert(mit != origToSparse.end());
00393                         rowInd.push_back(mit->second);
00394                         rowVal.push_back(matValI[k]);
00395                 }
00396                 begInd += matLen[r];
00397                 rowBeg.push_back(begInd);
00398         }
00399         model->M->appendRows(nRowsPart, &rowBeg[0], &rowInd[0], &rowVal[0]);
00400         
00401         //free local memory
00402         rowBeg.clear();
00403         rowInd.clear();
00404         rowVal.clear();
00405         UTIL_DELARR( integerVars);
00406 }
00407 
00408 //===========================================================================//
00409 void OSDipApp::createModels() {
00410 
00411         UtilPrintFuncBegin(m_osLog, m_classTag, "createModels()",
00412                         m_appParam.LogLevel, 2);
00413         int i;
00414         int j;
00415         const int nCols = m_osInterface.getVariableNumber();
00416         const int nRows = m_osInterface.getConstraintNumber();
00417         
00418         try{
00419 
00420                 //First the define the objective function over the entire variable space
00421                 //Create the memory for the objective  function
00422                 m_objective = new double[nCols];
00423                 for (i = 0; i < nCols; i++) {
00424                         m_objective[i] = m_osInterface.getObjectiveFunctionCoeff()[i];
00425                         //std::cout << "obj coeff = " << m_objective[i] << std::endl;
00426                 }
00427                 setModelObjective( m_objective);
00428         
00429                 //---
00430                 //--- Construct the core matrix.
00431                 //---
00432                 int nRowsRelax, nRowsCore;
00433                 nRowsRelax = 0;
00434                 nRowsCore = 0;
00435   
00436         
00437 
00438                 std::vector<OtherConstraintOption*> otherConstraintOptions;
00439                 std::vector<OtherConstraintOption*>::iterator vit;
00440                 
00441                 
00442 
00443                 //
00444                 // Now construct the block matrices
00445                 //
00446                 int *rowsRelax;
00447                 int whichBlock;
00448                 DecompConstraintSet *modelRelax = NULL;
00449 
00450                 std::set<int> blockVars; //variables indexes in the specific block
00451                 std::set<int> blockVarsAll; //all variable indexes that appear in a block
00452                 std::set<int> blockConAll; //all constraint indexes that appear in a block
00453                 std::set<int>::iterator sit;
00454                 CoinPackedVector *row;
00455                 int *rowVars;
00456                 int rowSize;
00457                 if (m_osInterface.m_osoption != NULL
00458                                 && m_osInterface.m_osoption->getNumberOfOtherConstraintOptions()
00459                                                 > 0) {
00460         
00461                         otherConstraintOptions
00462                                         = m_osInterface.m_osoption->getOtherConstraintOptions("Dip");
00463                         
00464                         //iterate over the vector of contraint options
00465                         for (vit = otherConstraintOptions.begin(); vit
00466                                         != otherConstraintOptions.end(); vit++) {
00467         
00468                                 // see if we have a Core Constraint Set
00469         
00470                                 if( ( (*vit)->name.compare("constraintSet") == 0)
00471                                                 && ( (*vit)->type.compare("Block") == 0)) {
00472                                         
00473                                         
00474                                         //get the block number
00475         
00476                                         //ch = new char[(*vit)->value.size() + 1];
00477                                         //ch[(*vit)->value.size()] = 0;
00478                                         //memcpy(ch, (*vit)->value.c_str(), (*vit)->value.size());
00479                                         //whichBlock = atoi(ch);
00480                                         //delete ch;
00481                                         whichBlock = atoi( (*vit)->value.c_str() );
00482                         
00483         
00484                                         
00485                                         // first get the number of constraints in this block
00486                                         nRowsRelax = (*vit)->numberOfCon;
00487                                         rowsRelax = new int[nRowsRelax];
00488         
00489                                         //now get the variable indexes for just this block
00490                                         //first clear indexes from a previous block
00491                                         blockVars.clear();
00492                                         for (i = 0; i < nRowsRelax; i++) {
00493                                                 rowsRelax[i] = (*vit)->con[i]->idx;
00494                                                 
00495                                                 if( (*vit)->con[i]->idx >= nRows) throw ErrorClass( "found an invalid row index in OSoL file");
00496                                                 
00497                                                 m_blocks[ whichBlock].push_back( rowsRelax[i] );
00498                                                 
00499                                                 //also add to the set of all rows
00500                                                 
00501                                                 if (blockConAll.find(  (*vit)->con[i]->idx ) == blockConAll.end()) {
00502                                                         blockConAll.insert(  (*vit)->con[i]->idx );     
00503                                                 }                                       
00504                                                 
00505                                                 //add the variables for this row to the set blockVars
00506                                                 row = m_osInterface.getRow(rowsRelax[i]);
00507                                                 rowSize = row->getNumElements();
00508                                                 rowVars = row->getIndices();
00509         
00510                                                 for (j = 0; j < rowSize; j++) {
00511                                                         
00512                                                         if (blockVars.find(rowVars[j]) == blockVars.end()) {
00513                                                                 blockVars.insert(rowVars[j]);   
00514                                                         }       
00515                                                         
00516                                                 }
00517                                                 
00518                                                 delete row;
00519         
00520                                         }//end for or rows in this block
00521         
00522                                         modelRelax = new DecompConstraintSet();
00523                                         CoinAssertHint(modelRelax, "Error: Out of Memory");
00524         
00525         
00526         
00527                                         //create the active columns in this block
00528                                         for (sit = blockVars.begin(); sit != blockVars.end(); sit++) {
00529         
00530                                                 modelRelax->activeColumns.push_back( *sit);
00531                                                 
00532                                                    
00533                                                 //insert into the all variables set also, but throw an execption
00534                                                 //if already there -- same variable cannot be in more than one block
00535                                                 
00536                                                 if (blockVarsAll.find( *sit) == blockVarsAll.end()) {
00537                                                         blockVarsAll.insert (*sit);     
00538                                                 }else{
00539                                                         
00540                                                         throw ErrorClass("Variable " + UtilIntToStr(*sit) + " appears in more than one block");
00541                                                         
00542                                                 }
00543         
00544                                         }
00545         
00546                                         //
00547                                         //
00548         
00549                                         if (m_appParam.LogLevel >= 3) {
00550                                                 (*m_osLog) << "Active Columns : " << whichBlock << endl;
00551                                                 UtilPrintVector(modelRelax->activeColumns, m_osLog);
00552 
00553                                         }
00554                                         createModelPartSparse(modelRelax, nRowsRelax, rowsRelax);  //does not work for cutting planes
00555                                         //createModelPart(modelRelax, nRowsRelax, rowsRelax);
00556                                         //modelRelax->fixNonActiveColumns();
00557                                         m_modelR.insert(make_pair(whichBlock + 1, modelRelax));
00558                                         setModelRelax(modelRelax, "relax" + UtilIntToStr(whichBlock),
00559                                                         whichBlock);
00560                                         
00561                                         if (m_appParam.LogLevel >= 3) {
00562                                                 (*m_osLog) <<  std::endl <<  std::endl;
00563                                                 (*m_osLog) << "HERE COMES THE DUPLICATION (WHEN createModelPartSparse USED)" << std::endl;
00564                                         }
00565 
00566                                         UtilPrintVector( modelRelax->activeColumns, m_osLog); 
00567                                         
00568                                                                         
00569                                 //free local memory
00570                                 UTIL_DELARR( rowsRelax);
00571         
00572         
00573         
00574                                 }
00575                         }//end for over constraint options
00576                 }// if on ospton null
00577         
00578                 //get the core constraints -- constraints NOT in a block
00579                 int *rowsCore = NULL;
00580                 
00581                 int kount = 0;
00582                 nRowsCore = nRows - blockConAll.size();
00583                 
00584                 if(nRowsCore <= 0) throw ErrorClass("We need at least one coupling constraint");
00585         
00586                 rowsCore = new int[nRowsCore];
00587                         
00588                 for(i = 0; i < nRows; i++){
00589                         
00590                         if (blockConAll.find( i ) == blockConAll.end() ){
00591                                 
00592                                 
00593                                 rowsCore[ kount++] =  i;
00594                                 
00595                                 
00596                                 
00597                         }
00598                 }
00599 
00600                 if( kount  !=  nRowsCore) throw ErrorClass("There was an error counting coupling constraints");
00601                 
00602         
00603                 DecompConstraintSet * modelCore = new DecompConstraintSet();
00604                 createModelPart(modelCore, nRowsCore, rowsCore);
00605         
00606                 setModelCore(modelCore, "core");
00607                 //---
00608                 //--- save a pointer so we can delete it later
00609                 //---
00610                 m_modelC = modelCore;
00611                 
00612 
00613                 //get the master only variables
00614                 //modelCore->masterOnlyCols.push_back(i);
00615                 for (i = 0; i < nCols; i++) {
00616                         if (blockVarsAll.find(i) == blockVarsAll.end()) {
00617                                 modelCore->masterOnlyCols.push_back(i);
00618                                 std::cout << "MASTER ONLY VARIABLE " << i << std::endl;
00619                         }
00620                 }
00621         
00622                 //---
00623                 //--- create an extra "empty" block for the master-only vars
00624                 //---   since I don't know what OSI will do with empty problem
00625                 //---   we will make column bounds explicity rows
00626                 //---
00627                 int nMasterOnlyCols = static_cast<int> (modelCore->masterOnlyCols.size());
00628                 if (nMasterOnlyCols) {
00629                         if (m_appParam.LogLevel >= 1)
00630                                 (*m_osLog) << "Create model part Master-Only." << endl;
00631         
00632                         createModelMasterOnlys2(modelCore->masterOnlyCols);
00633         
00634                 }
00635                 
00636                 
00637                 UtilPrintFuncBegin(m_osLog, m_classTag, "printCurrentProblem()",
00638                                 m_appParam.LogLevel, 2);
00639                                 
00640                                 
00641          //free local memory
00642          UTIL_DELARR( rowsCore);
00643         
00644         
00645         }//end try
00646         
00647         catch(const ErrorClass& eclass){
00648                 
00649                 throw ErrorClass( eclass.errormsg);
00650                 
00651         } 
00652 
00653 }// end createModels()
00654 
00655 
00656 //===========================================================================//
00657 
00658 void OSDipApp::createModelMasterOnlys2(vector<int> & masterOnlyCols) {
00659 
00660         int nBlocks = static_cast<int>(m_blocks.size());
00661         const int nCols = m_osInterface.getVariableNumber();
00662         const double * colLB = m_osInterface.getColLower();
00663         const double * colUB = m_osInterface.getColUpper();
00664         const char * integerVars = m_osInterface.getIntegerColumns();
00665         int nMasterOnlyCols = static_cast<int> (masterOnlyCols.size());
00666 
00667         if (m_appParam.LogLevel >= 1) {
00668                 (*m_osLog) << "nCols = " << nCols << endl;
00669                 (*m_osLog) << "nMasterOnlyCols = " << nMasterOnlyCols << endl;
00670         }
00671 
00672         if (nMasterOnlyCols == 0)
00673                 return;
00674 
00675         int i;
00676         vector<int>::iterator vit;
00677         for (vit = masterOnlyCols.begin(); vit != masterOnlyCols.end(); vit++) {
00678                 i = *vit;
00679 
00680                 //THINK:
00681                 //  what-if master-only var is integer and bound is not at integer?
00682 
00683                 DecompConstraintSet * model = new DecompConstraintSet();
00684                 model->m_masterOnly = true;
00685                 model->m_masterOnlyIndex = i;
00686                 model->m_masterOnlyLB = colLB[i];
00687                 //std::cout << "MASTER ONLY LB =  " << model->m_masterOnlyLB << std::endl;
00688                 model->m_masterOnlyUB = colUB[i];
00689                 //std::cout << "MASTER ONLY UB =  " << model->m_masterOnlyUB << std::endl;
00690                 //0=cont, 1=integer
00691                 if(integerVars[i] == '1') model->m_masterOnlyIsInt = true;
00692                 //model->m_masterOnlyIsInt = integerVars[i] ? true : false;
00693                 if (m_appParam.ColumnUB < 1.0e15)
00694                         if (colUB[i] > 1.0e15)
00695                                 model->m_masterOnlyUB = m_appParam.ColumnUB;
00696                 if (m_appParam.ColumnLB > -1.0e15)
00697                         if (colLB[i] < -1.0e15)
00698                                 model->m_masterOnlyLB = m_appParam.ColumnLB;
00699 
00700                 m_modelMasterOnly.insert(make_pair(i, model)); //keep track for garbage collection
00701                 setModelRelax(model, "master_only" + UtilIntToStr(i), nBlocks);
00702                 nBlocks++;
00703         }
00704         //free local memory
00705         UTIL_DELARR( integerVars);
00706         return;
00707 }//end createModelMasterOnlys2
00708 
00709 
00710 int OSDipApp::generateInitVars(DecompVarList & initVars) {
00711 
00712         //---
00713         //--- generateInitVars is a virtual method and can be overriden
00714         //---   if the user has some idea how to initialize the list of 
00715         //---   initial variables (columns in the DW master)
00716         //---
00717         std::cout << "GENERATE INIT VARS" << std::endl;
00718         UtilPrintFuncBegin(m_osLog, m_classTag, "generateInitVars()",
00719                         m_appParam.LogLevel, 2);
00720 
00721         //---
00722         //--- Get the initial solution from the OSOption object
00723         //--- we want the variable other option where name="initialCol"
00724         //---
00725 
00726         //std::vector<OtherVariableOption*> getOtherVariableOptions(std::string solver_name); 
00727         std::vector<OtherVariableOption*> otherVarOptions;
00728         std::vector<OtherVariableOption*>::iterator vit;
00729         int *index = NULL;
00730         double *value = NULL;
00731         int i;
00732         double objValue;
00733         int whichBlock;
00734         DecompVar *var;
00735 
00736         try{
00737                 if (m_osInterface.m_osoption != NULL
00738                                 && m_osInterface.m_osoption->getNumberOfOtherVariableOptions() > 0) {
00739                         std::cout << "Number of other variable options = "
00740                                         << m_osInterface.m_osoption->getNumberOfOtherVariableOptions()
00741                                         << std::endl;
00742                         otherVarOptions = m_osInterface.m_osoption->getOtherVariableOptions(
00743                                         "Dip");
00744                         //iterate over the vector
00745         
00746                         for (vit = otherVarOptions.begin(); vit != otherVarOptions.end(); vit++) {
00747         
00748                                 // see if we have an initialCol option
00749         
00750                                 if ((*vit)->name.compare("initialCol") == 0) {
00751         
00752                                         index = new int[(*vit)->numberOfVar];
00753                                         value = new double[(*vit)->numberOfVar];
00754         
00755                                         objValue = 0.0;
00756         
00757                                         for (i = 0; i < (*vit)->numberOfVar; i++) {
00758         
00759                                                 index[i] = (*vit)->var[i]->idx;
00760         
00761                                                 //convert the string to integer
00762                                                 value[ i] = atoi((*vit)->var[i]->value.c_str());
00763                                                 objValue += m_objective[index[i]];
00764         
00765                                         }
00766                                         
00767                                         whichBlock = atoi( (*vit)->value.c_str() );
00768                                         var = new DecompVar((*vit)->numberOfVar, index, value, objValue);
00769                                         var->setBlockId(whichBlock);
00770                                         initVars.push_back(var);
00771                                         
00772                                         //free local memory
00773                                         UTIL_DELARR( index);
00774                                         UTIL_DELARR( value);
00775                                         
00776         
00777                                 }
00778         
00779                         }
00780         
00781                 }
00782         
00783         }//end try
00784         catch(const ErrorClass& eclass){
00785                 
00786                 throw ErrorClass( eclass.errormsg);
00787                 
00788         } 
00789 
00790         UtilPrintFuncEnd(m_osLog, m_classTag, "generateInitVars()",
00791                         m_appParam.LogLevel, 2);
00792         return static_cast<int> (initVars.size());
00793 }

Generated on Wed Nov 30 03:04:10 2011 by  doxygen 1.4.7