- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/OS-2.3.5/ApplicationTemplates/osDip/OSDipInterface.cpp

Go to the documentation of this file.

    00001 /* $Id: OSDipInterface.cpp 3038 2009-11-07 11:43:44Z Gassmann $ */
    00018 //===========================================================================//
    00019
    00020
    00021 #include "OSDipInterface.h"
    00022 #include "UtilMacrosDecomp.h"
    00023
    00024 //===========================================================================//
    00025 void OS_DipInterface::readOSiL(string & fileName) {
    00026
    00027         FileUtil *fileUtil = NULL;
    00028         fileUtil = new FileUtil();
    00029
    00030         try {
    00031
    00032                 std::string osil;
    00033                 osil = fileUtil->getFileAsString(fileName.c_str());
    00034                 m_osilreader = new OSiLReader();
    00035                 m_osinstance = m_osilreader->readOSiL(osil);
    00036
    00037                 bool columnMajor = false;
    00038                 double maxGap = 0;
    00039
    00040                 m_coinpm
    00041                                 = new CoinPackedMatrix(
    00042                                                 columnMajor, //Column or Row Major
    00043                                                 columnMajor ? m_osinstance->getConstraintNumber()
    00044                                                                 : m_osinstance->getVariableNumber(), //Minor Dimension
    00045                                                 columnMajor ? m_osinstance->getVariableNumber()
    00046                                                                 : m_osinstance->getConstraintNumber(), //Major Dimension
    00047                                                 m_osinstance->getLinearConstraintCoefficientNumber(), //Number of nonzeroes
    00048                                                 columnMajor ? m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->values
    00049                                                                 : m_osinstance->getLinearConstraintCoefficientsInRowMajor()->values, //Pointer to matrix nonzeroes
    00050                                                 columnMajor ? m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes
    00051                                                                 : m_osinstance->getLinearConstraintCoefficientsInRowMajor()->indexes, //Pointer to start of minor dimension indexes -- change to allow for row storage
    00052                                                 columnMajor ? m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts
    00053                                                                 : m_osinstance->getLinearConstraintCoefficientsInRowMajor()->starts, //Pointers to start of columns.
    00054                                                 0, 0, maxGap);
    00055
    00056                 delete fileUtil;
    00057                 fileUtil = NULL;
    00058                 //kipp  -- worry about garbage collection here -- do I delete m_osinstance
    00059                 //delete  osilreader;
    00060                 //osilreader = NULL;
    00061
    00062
    00063         } catch (const ErrorClass& eclass) {
    00064                 std::cout << "PROBLEM READING OSiL File" << std::endl;
    00065                 delete fileUtil;
    00066                 std::cout << eclass.errormsg << std::endl;
    00067                 fileUtil = NULL;
    00068                 throw ErrorClass(eclass.errormsg);
    00069
    00070         }
    00071
    00072 }//end readOSiL
    00073
    00074
    00075 //===========================================================================//
    00076 void OS_DipInterface::readOSoL(string & fileName) {
    00077
    00078         FileUtil *fileUtil = NULL;
    00079         fileUtil = new FileUtil();
    00080         try {
    00081
    00082                 std::string osol;
    00083                 osol = fileUtil->getFileAsString(fileName.c_str());
    00084                 m_osolreader = new OSoLReader();
    00085                 m_osoption = m_osolreader->readOSoL(osol);
    00086
    00087                 delete fileUtil;
    00088                 fileUtil = NULL;
    00089                 //kipp  -- worry about garbage collection here -- do I delete m_osinstance
    00090                 //delete  osilreader;
    00091                 //osilreader = NULL;
    00092
    00093
    00094         } catch (const ErrorClass& eclass) {
    00095                 std::cout << "Problem reading OSoL File" << std::endl;
    00096                 delete fileUtil;
    00097                 std::cout << eclass.errormsg << std::endl;
    00098                 fileUtil = NULL;
    00099                 throw ErrorClass(eclass.errormsg);
    00100
    00101         }
    00102
    00103 }// end readOSoL
    00104
    00105 CoinPackedMatrix * OS_DipInterface::getCoinPackedMatrix() {
    00106
    00107         return m_coinpm;
    00108 }//end getCoinPackedMatrix
    00109
    00110 CoinPackedVector * OS_DipInterface::getRow(int i) {
    00111
    00112         m_row = new CoinPackedVector();
    00113
    00114         int k;
    00115
    00116         SparseMatrix* sm;
    00117
    00118         sm = m_osinstance->getLinearConstraintCoefficientsInRowMajor();
    00119
    00120         for (k = sm->starts[i]; k < sm->starts[i + 1]; k++) {
    00121
    00122                 m_row->insert(sm->indexes[k], sm->values[k]);
    00123
    00124         }
    00125
    00126         return m_row;
    00127 }//end getRow
    00128
    00129 const char* OS_DipInterface::getIntegerColumns() {
    00130
    00131         int numVars = getVariableNumber();
    00132         m_integerVars = new char[numVars];
    00133         int i;
    00134
    00135         for (i = 0; i < numVars; i++) {
    00136
    00137                 if (m_osinstance->getVariableTypes()[i] == 'B'
    00138                                 || m_osinstance->getVariableTypes()[i] == 'I')
    00139                         m_integerVars[i] = '1';
    00140                 else
    00141                         m_integerVars[i] = '0';
    00142
    00143         }
    00144         return m_integerVars;
    00145
    00146 }// end getIntegerColumns
    00147
    00148
    00149 double OS_DipInterface::getObjectiveOffset() {
    00150
    00151         double offset = 0;
    00152         //assume only one objective function for now
    00153
    00154         if (getObjectiveConstants() != NULL) {
    00155                 offset = getObjectiveConstants()[0];
    00156         }
    00157
    00158         return offset;
    00159 }// end getObjectiveOffset
    00160
    00161
    00162 std::vector<std::string> OS_DipInterface::getBlockFactories() {
    00163
    00164         //get the factory solver for each block in the model
    00165
    00166         if (m_blockFactoriesProcessed == true)
    00167                 return m_blockFactories;
    00168
    00169         try {
    00170                 if (m_osoption == NULL)
    00171                         throw ErrorClass("we have a null osoption");
    00172
    00173                 std::vector<OtherVariableOption*> otherVariableOptions;
    00174                 std::vector<OtherVariableOption*>::iterator vit;
    00175
    00176                 if (m_osoption != NULL && m_osoption->getNumberOfOtherVariableOptions()
    00177                                 > 0) {
    00178
    00179                         otherVariableOptions = m_osoption->getOtherVariableOptions("Dip");
    00180                         //iterate over the vector of variable options
    00181                         for (vit = otherVariableOptions.begin(); vit
    00182                                         != otherVariableOptions.end(); vit++) {
    00183
    00184                                 // right now we assume blocks are ordered  -- we ignor value
    00185                                 if ((*vit)->name.compare("variableBlockSet") == 0) {
    00186
    00187                                         if ((*vit)->value.size() > 0) {
    00188
    00189                                                 m_blockFactories.push_back((*vit)->value);
    00190
    00191                                         } else {
    00192
    00193                                                 m_blockFactories.push_back("");
    00194                                         }
    00195
    00196                                 }
    00197
    00198                         }
    00199                 }
    00200
    00201         }//end try
    00202
    00203         catch (const ErrorClass& eclass) {
    00204
    00205                 std::cout << eclass.errormsg << std::endl;
    00206                 throw ErrorClass(eclass.errormsg);
    00207
    00208         }
    00209         m_blockFactoriesProcessed = true;
    00210         return m_blockFactories;
    00211 }//end getBlockVarIndexes
    00212
    00213 std::vector<std::set<int> > OS_DipInterface::getBlockVarIndexes() {
    00214
    00215         //get the variable indexes for each block in the model
    00216         std::set<int> varSet; //variables indexes in a specific block
    00217         if (m_blockVariableIndexesProcessed == true)
    00218                 return m_blockVariableIndexes;
    00219
    00220         try {
    00221                 if (m_osoption == NULL)
    00222                         throw ErrorClass("we have a null osoption");
    00223
    00224                 int numVar;
    00225                 int i;
    00226                 std::vector<OtherVariableOption*> otherVariableOptions;
    00227                 std::vector<OtherVariableOption*>::iterator vit;
    00228
    00229                 if (m_osoption != NULL && m_osoption->getNumberOfOtherVariableOptions()
    00230                                 > 0) {
    00231
    00232                         otherVariableOptions = m_osoption->getOtherVariableOptions("Dip");
    00233                         //iterate over the vector of variable options
    00234                         for (vit = otherVariableOptions.begin(); vit
    00235                                         != otherVariableOptions.end(); vit++) {
    00236
    00237                                 // right now we assume blocks are ordered  -- we ignor value
    00238                                 if ((*vit)->name.compare("variableBlockSet") == 0) {
    00239
    00240                                         // see if we have a set of block variables
    00241                                         // if so we insert into our vector of sets
    00242                                         varSet.clear();
    00243
    00244                                         numVar = (*vit)->numberOfVar;
    00245
    00246                                         for (i = 0; i < numVar; i++) {
    00247
    00248                                                 if ((*vit)->var[i]->idx
    00249                                                                 >= m_osinstance->getVariableNumber())
    00250                                                         throw ErrorClass(
    00251                                                                         "found an invalid varaible index in OSoL file");
    00252
    00253                                                 varSet.insert((*vit)->var[i]->idx);
    00254
    00255                                         }//end for on variables in this block
    00256
    00257                                         m_blockVariableIndexes.push_back(varSet);
    00258                                 }// end of if
    00259
    00260
    00261                         }//end for over constraint options
    00262                 }// if on ospton null
    00263
    00264
    00265                 if (m_blockVariableIndexes.size() <= 0)
    00266                         throw ErrorClass("someting wrong -- no variables in the blocks");
    00267
    00268         } //end try
    00269
    00270         catch (const ErrorClass& eclass) {
    00271
    00272                 std::cout << eclass.errormsg << std::endl;
    00273                 throw ErrorClass(eclass.errormsg);
    00274
    00275         }
    00276         m_blockVariableIndexesProcessed = true;
    00277         return m_blockVariableIndexes;
    00278 }//end getBlockVarIndexes
    00279
    00280
    00281 std::vector<std::map<int, int> > OS_DipInterface::getBlockConstraintIndexes() {
    00282
    00283         if (m_blockConstraintIndexesProcessed == true)
    00284                 return m_blockConstraintIndexes;
    00285         //get the variable indexes for each block in the model
    00286         std::map<int, int> conMap; //constraint indexes in a specific block
    00287         std::set<int> varSet; //constraint indexes in a specific block
    00288         std::set<int> coreConstraintIndexes;
    00289         std::vector<std::set<int> > blockVariableIndexes;
    00290
    00291         int *starts = NULL;
    00292         int *indexes = NULL;
    00293         int kount;
    00294
    00295         try {
    00296
    00297                 // first get the block variable indexes, these are necessary
    00298                 blockVariableIndexes = getBlockVarIndexes();
    00299                 // get the core constraint indexes
    00300                 coreConstraintIndexes = getCoreConstraintIndexes();
    00301
    00302                 if (blockVariableIndexes.size() <= 0)
    00303                         throw ErrorClass("someting wrong -- no variables in the blocks");
    00304
    00305                 std::vector<std::set<int> >::iterator vit;
    00306                 std::set<int>::iterator sit;
    00307                 int i;
    00308
    00309                 for (vit = blockVariableIndexes.begin(); vit
    00310                                 != blockVariableIndexes.end(); vit++) {
    00311
    00312                         varSet.clear();
    00313                         conMap.clear();
    00314
    00315                         varSet = *vit;
    00316                         //now get the nonzeros for the variables in
    00317                         //varSet and see which nonzeros are in non-core
    00318                         //constraints
    00319                         kount = 0;
    00320                         for (sit = varSet.begin(); sit != varSet.end(); sit++) {
    00321
    00322                                 starts
    00323                                                 = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts;
    00324                                 indexes
    00325                                                 = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes;
    00326
    00327                                 for (i = starts[*sit]; i < starts[*sit + 1]; i++) {
    00328
    00329                                         //add the row index if not in a core constraint
    00330                                         //don't count same index twice
    00331                                         if (coreConstraintIndexes.find(indexes[i])
    00332                                                         == coreConstraintIndexes.end() &&
    00333                                                         (conMap.find(indexes[i] ) == conMap.end()  )
    00334                                         ) {
    00335                                                 //we have a new constraint index
    00336
    00337                                                 conMap.insert(make_pair(indexes[i], kount));
    00338                                                 kount++;
    00339                                         }
    00340                                 }
    00341                         }
    00342
    00343                         m_blockConstraintIndexes.push_back(conMap);
    00344
    00345                 }//end for iterator
    00346
    00347
    00348         } //end try
    00349
    00350         catch (const ErrorClass& eclass) {
    00351
    00352                 std::cout << eclass.errormsg << std::endl;
    00353                 throw ErrorClass(eclass.errormsg);
    00354
    00355         }
    00356         m_blockConstraintIndexesProcessed = true;
    00357         return m_blockConstraintIndexes;
    00358 }//end getBlockConstraintIndexes
    00359
    00360
    00361 std::vector<OSInstance*> OS_DipInterface::getBlockOSInstances() {
    00362         //get the OSInstance for each block
    00363         if (m_blockOSInstancesProcessed == true)
    00364                 return m_blockOSInstances;
    00365
    00366         std::map<int, int> conMap; //constraint indexes in a specific block
    00367         std::set<int> varSet; //constraint indexes in a specific block
    00368         std::vector<std::map<int, int> > blockConstraintIndexes;
    00369         std::set<int> coreConstraintIndexes;
    00370         std::vector<std::set<int> > blockVariableIndexes;
    00371
    00372         int *starts = NULL;
    00373         int *indexes = NULL;
    00374         double *values = NULL;
    00375
    00376         OSInstance *osinstance;
    00377         std::vector<std::set<int> >::iterator vit;
    00378         std::set<int>::iterator sit;
    00379         std::map<int, int>::iterator mit;
    00380         int i;
    00381         int kount;
    00382
    00383         int whichBlock;
    00384         int numNonz;
    00385         int k1, k2;
    00386
    00387         //variable stuff
    00388         int numberVar;
    00389         std::string* varNames = NULL;
    00390         char* varTypes = NULL;
    00391         double* varLowerBounds = NULL;
    00392         double* varUpperBounds = NULL;
    00393
    00394         //constraint stuff
    00395         int numberCon;
    00396         std::string* conNames = NULL;
    00397         double* conLowerBounds = NULL;
    00398         double* conUpperBounds = NULL;
    00399         double* conConstants = NULL;
    00400
    00401         int idx;
    00402
    00403         try {
    00404
    00405                 // first get the block variable indexes, these are necessary
    00406                 blockVariableIndexes = getBlockVarIndexes();
    00407                 // get the core constraint indexes
    00408
    00409                 coreConstraintIndexes = getCoreConstraintIndexes();
    00410                 // get the block constraint indexes
    00411
    00412                 blockConstraintIndexes = getBlockConstraintIndexes();
    00413
    00414                 if (blockVariableIndexes.size() <= 0)
    00415                         throw ErrorClass(
    00416                                         "someting wrong in getBlockOSInstances() -- no variables in the blocks");
    00417
    00418                 //
    00419                 //loop over each block
    00420                 //
    00421                 whichBlock = 0;
    00422                 for (vit = blockVariableIndexes.begin(); vit
    00423                                 != blockVariableIndexes.end(); vit++) {
    00424
    00425                         varSet.clear();
    00426                         conMap.clear();
    00427                         varSet = *vit;
    00428
    00429                         osinstance = new OSInstance();
    00430                         //define variable arrays
    00431                         numberVar = varSet.size();
    00432                         varTypes = new char[numberVar];
    00433                         varNames = new string[numberVar];
    00434                         varLowerBounds = new double[numberVar];
    00435                         varUpperBounds = new double[numberVar];
    00436
    00437                         //now get the nonzeros for the variables in
    00438                         //varSet and see which nonzeros are in non-core
    00439                         //constraints
    00440                         kount = 0;
    00441
    00442                         osinstance->setVariableNumber(numberVar);
    00443
    00444                         SparseVector *objcoeff;
    00445                         objcoeff = new SparseVector(numberVar);
    00446
    00447                         //need to count the number  of nonzero elements
    00448                         //in the block constraints
    00449                         numNonz = 0;
    00450
    00451                         for (sit = varSet.begin(); sit != varSet.end(); sit++) {
    00452
    00453                                 varTypes[kount] = m_osinstance->getVariableTypes()[*sit];
    00454                                 varLowerBounds[kount]
    00455                                                 = m_osinstance->getVariableLowerBounds()[*sit];
    00456                                 varUpperBounds[kount]
    00457                                                 = m_osinstance->getVariableUpperBounds()[*sit];
    00458
    00459                                 varNames[kount] = m_osinstance->getVariableNames()[*sit];
    00460
    00461                                 objcoeff->indexes[kount] = kount;
    00462                                 //objcoeff->values[kount] = 0.0;
    00463                                 objcoeff->values[kount] =  m_osinstance->getDenseObjectiveCoefficients()[0][ *sit];
    00464                                 numNonz
    00465                                                 += m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[*sit + 1]
    00466                                                                 - m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[*sit];
    00467
    00468                                 kount++;
    00469
    00470                         }//end of loop over the variables in this block
    00471
    00472                         osinstance->setVariables(numberVar, varNames, varLowerBounds,
    00473                                         varUpperBounds, varTypes);
    00474
    00475                         // now the objective function
    00476                         osinstance->setObjectiveNumber(1);
    00477                         // now the coefficient
    00478                         osinstance->addObjective(-1, "objfunction",
    00479                                         m_osinstance->getObjectiveMaxOrMins()[0], 0.0, 1.0,
    00480                                         objcoeff);
    00481
    00482                         conMap = blockConstraintIndexes[whichBlock];
    00483                         numberCon = conMap.size();
    00484
    00485                         if (numberCon > 0) {
    00486
    00487                                 starts = new int[numberVar + 1];
    00488                                 indexes = new int[numNonz];
    00489                                 values = new double[numNonz];
    00490                                 kount = 0;
    00491                                 starts[kount] = 0;
    00492
    00493                                 numNonz = 0;
    00494                                 for (sit = varSet.begin(); sit != varSet.end(); sit++) {
    00495
    00496                                         k2
    00497                                                         = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[*sit
    00498                                                                         + 1];
    00499                                         k1
    00500                                                         = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->starts[*sit];
    00501
    00502                                         for (i = k1; i < k2; i++) {
    00503
    00504                                                 idx
    00505                                                                 = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->indexes[i];
    00506
    00507                                                 //check to make sure we are not in a core constraint
    00508                                                 if (coreConstraintIndexes.find(idx)
    00509                                                                 == coreConstraintIndexes.end()) {
    00510
    00511                                                         indexes[numNonz] = conMap[idx];
    00512                                                         values[numNonz]
    00513                                                                         = m_osinstance->getLinearConstraintCoefficientsInColumnMajor()->values[i];
    00514                                                         numNonz++;
    00515                                                 }
    00516
    00517                                         }
    00518                                         starts[kount + 1] = numNonz;
    00519
    00520                                         kount++;
    00521
    00522                                 }
    00523
    00524                                 //now the constraints
    00525
    00526
    00527                                 osinstance->setConstraintNumber(numberCon);
    00528                                 conLowerBounds = new double[numberCon];
    00529                                 conUpperBounds = new double[numberCon];
    00530                                 conConstants = new double[numberCon];
    00531
    00532                                 for (mit = conMap.begin(); mit != conMap.end(); mit++) {
    00533
    00534                                         conLowerBounds[mit->second]
    00535                                                         = m_osinstance->getConstraintLowerBounds()[mit->first];
    00536                                         conUpperBounds[mit->second]
    00537                                                         = m_osinstance->getConstraintUpperBounds()[mit->first];
    00538                                         conConstants[mit->second] = 1.0;
    00539
    00540
    00541
    00542                                 }
    00543
    00544                                 std::cout << "Call setConstraints " << numberCon << std::endl;
    00545
    00546                                 osinstance->setConstraints(numberCon, conNames, conLowerBounds,
    00547                                                 conUpperBounds, conConstants);
    00548
    00549                                 osinstance->setLinearConstraintCoefficients(numNonz, true,
    00550                                                 values, 0, numNonz - 1, indexes, 0, numNonz - 1,
    00551                                                 starts, 0, numberVar);
    00552
    00553                         }
    00554
    00555                         //numNonz--;
    00556
    00557
    00558                         //add the osinstance
    00559                         m_blockOSInstances.push_back(osinstance);
    00560
    00561                         //see what this puppy looks like
    00562
    00563                         //std::cout << osinstance->printModel( ) << std::endl;
    00564
    00565                         objcoeff->bDeleteArrays = true;
    00566                         delete objcoeff;
    00567                         if (varLowerBounds != NULL)
    00568                                 delete[] varLowerBounds;
    00569                         if (varUpperBounds != NULL)
    00570                                 delete[] varUpperBounds;
    00571                         if (varTypes != NULL)
    00572                                 delete[] varTypes;
    00573                         if (varNames != NULL)
    00574                                 delete[] varNames;
    00575
    00576                         //delete []starts;
    00577                         //delete []indexes;
    00578                         //delete []values;
    00579
    00580                         if (conLowerBounds != NULL)
    00581                                 delete[] conLowerBounds;
    00582                         if (conUpperBounds != NULL)
    00583                                 delete[] conUpperBounds;
    00584                         if (conConstants != NULL)
    00585                                 delete[] conConstants;
    00586
    00587                         whichBlock++;
    00588
    00589                 }//end for iterator for the blocks
    00590
    00591
    00592         } //end try
    00593
    00594         catch (const ErrorClass& eclass) {
    00595
    00596                 std::cout << eclass.errormsg << std::endl;
    00597                 throw ErrorClass(eclass.errormsg);
    00598
    00599         }
    00600         m_blockOSInstancesProcessed = true;
    00601         return m_blockOSInstances;
    00602
    00603 }//end getBlockOSInstances()
    00604
    00605 std::set<int> OS_DipInterface::getCoreConstraintIndexes() {
    00606
    00607         //get the indexes of the core constraints
    00608
    00609         if (m_coreConstraintIndexesProcessed == true)
    00610                 return m_coreConstraintIndexes;
    00611         try {
    00612                 if (m_osoption == NULL)
    00613                         throw ErrorClass("we have a null osoption");
    00614
    00615                 int numCoreCon;
    00616                 int i;
    00617                 std::vector<OtherConstraintOption*> otherConstraintOptions;
    00618                 std::vector<OtherConstraintOption*>::iterator vit;
    00619
    00620                 if (m_osoption != NULL
    00621                                 && m_osoption->getNumberOfOtherConstraintOptions() > 0) {
    00622
    00623                         otherConstraintOptions = m_osoption->getOtherConstraintOptions(
    00624                                         "Dip");
    00625                         //iterate over the vector of contraint options
    00626                         for (vit = otherConstraintOptions.begin(); vit
    00627                                         != otherConstraintOptions.end(); vit++) {
    00628
    00629                                 // get the core constraints
    00630                                 // get the indexes of these constraints
    00631                                 if (((*vit)->name.compare("constraintSet") == 0)
    00632                                                 && ((*vit)->type.compare("Core") == 0)) {
    00633
    00634                                         numCoreCon = (*vit)->numberOfCon;
    00635
    00636                                         for (i = 0; i < numCoreCon; i++) {
    00637
    00638                                                 if ((*vit)->con[i]->idx
    00639                                                                 >= m_osinstance->getConstraintNumber())
    00640                                                         throw ErrorClass(
    00641                                                                         "found an invalid constraint index in OSoL file");
    00642
    00643                                                 m_coreConstraintIndexes.insert((*vit)->con[i]->idx);
    00644
    00645                                         }//end for on variables in this block
    00646
    00647                                 }//end iff on core constraints
    00648
    00649
    00650                         }// end of for on constraint options
    00651
    00652
    00653                 }//end of if on osptio null
    00654
    00655                 if (m_coreConstraintIndexes.size() <= 0)
    00656                         throw ErrorClass(
    00657                                         "there were no core constraints listed in the option file");
    00658         }// end of try
    00659
    00660
    00661         catch (const ErrorClass& eclass) {
    00662
    00663                 std::cout << eclass.errormsg << std::endl;
    00664                 throw ErrorClass(eclass.errormsg);
    00665
    00666         }
    00667         m_coreConstraintIndexesProcessed = true;
    00668         return m_coreConstraintIndexes;
    00669
    00670 }//end getCoreConstraintIndexes
    00671
    00672
    00673 double* OS_DipInterface::getObjectiveFunctionCoeff() {
    00674
    00675         //Dip has only one objective function
    00676
    00677         return m_osinstance->getDenseObjectiveCoefficients()[0];
    00678 }// end getObjectiveFunctionCoeff()
    00679
    00680
    00682 OS_DipInterface::OS_DipInterface() :
    00683
    00684         m_isProvenOptimal(false), m_bestKnownLB(-1.e20), m_bestKnownUB(1.e20),
    00685                         m_coinpm(NULL), m_blockVariableIndexesProcessed(false),
    00686                         m_coreConstraintIndexesProcessed(false),
    00687                         m_blockConstraintIndexesProcessed(false),
    00688                         m_blockOSInstancesProcessed(false),
    00689                         m_blockFactoriesProcessed(false) {
    00690
    00691 }
    00692
    00693 OS_DipInterface::~OS_DipInterface() {
    00694         std::cout << "INSIDE OS DIP INTERFACE DESTRUCTOR" << std::endl;
    00695         if (m_osilreader != NULL)
    00696                 delete m_osilreader;
    00697         if (m_osolreader != NULL)
    00698                 delete m_osolreader;
    00699         delete m_coinpm;
    00700
    00701         std::vector<OSInstance*>::iterator vit;
    00702
    00703         if (m_blockOSInstances.size() > 0) {
    00704                 for (vit = m_blockOSInstances.begin(); vit != m_blockOSInstances.end(); vit++) {
    00705
    00706                         delete *vit;
    00707                 }
    00708         }
    00709 }
    00710
    00711
    00712
    00713 std::map<int, std::vector< int> > OS_DipInterface::generateInitialMaster(){
    00714
    00715
    00716         // define the classes
    00717         FileUtil *fileUtil = NULL;
    00718         OSiLReader *osilreader = NULL;
    00719         DefaultSolver *solver  = NULL;
    00720         OSInstance *osinstance = NULL;
    00721         OSOption *osoption = NULL;
    00722
    00723         // end classes
    00724
    00725         std::string testFileName;
    00726         std::string osil;
    00727
    00728
    00729         std::map<int, std::vector< int> > indexMap;
    00730         std::vector< int> indexes;
    00731         fileUtil = new FileUtil();
    00732
    00733
    00734         try {
    00735                 testFileName = "../data/restrictedMaster5.osil";
    00736
    00737                 osil = fileUtil->getFileAsString(testFileName.c_str());
    00738
    00739 #ifdef MY_DEBUG
    00740                 std::cout << "Done reading the file" << std::endl;
    00741 #endif
    00742
    00743                 osilreader = new OSiLReader();
    00744
    00745                 //create the osption
    00746                 osoption = new OSOption();
    00747
    00748 #ifdef MY_DEBUG
    00749                 parsingTestResult << "Reading files successfully" << std::endl;
    00750 #endif
    00751
    00752                 osinstance = osilreader->readOSiL(osil);
    00753
    00754                 solver = new CoinSolver();
    00755                 solver->sSolverName ="cbc";
    00756                 solver->osinstance = osinstance;
    00757                 solver->osoption = osoption;
    00758                 std::cout << "CALLING SOLVE FOR RESTRICTED MASTER" << std::endl;
    00759                 solver->solve();
    00760                 int i;
    00761                 int j;
    00762                 int k;
    00763                 int vecSize;
    00764                 // now get the primal solution
    00765                 std::vector<IndexValuePair*> primalValPair;
    00766                 primalValPair = solver->osresult->getOptimalPrimalVariableValues( 0);
    00767                 vecSize = primalValPair.size();
    00768
    00769
    00770                 int numNodes = 5;
    00771                 int numHubs = 1;
    00772                 int totalDemand = 4;
    00773
    00774
    00775
    00776                 int* routeDemand = NULL;
    00777                 int startPnt;
    00778
    00779                 routeDemand = new int[ numHubs];
    00780                 int kount;
    00781
    00782                 std::string* varNames;
    00783                 varNames =  osinstance->getVariableNames();
    00784
    00785                 //get route demands
    00786                 kount = 0;
    00787                 for(k = 0; k < numHubs; k++){
    00788
    00789                         routeDemand[k ] = primalValPair[ kount]->value;
    00790
    00791                         std::cout << "Route Demand = " << routeDemand[k] << std::endl;
    00792                         kount++;
    00793
    00794                 }
    00795
    00796                 //now get x variable values
    00797
    00798                 for(k = 0; k < numHubs; k++){
    00799
    00800                         startPnt = k*totalDemand*(numNodes*numNodes - numNodes) + (routeDemand[ k] - 1)*(numNodes*numNodes - numNodes);
    00801
    00802                         for(i = 0; i < numNodes; i++){
    00803
    00804
    00805                                 for(j = 0; j < i; j++){
    00806
    00807                                         if( primalValPair[ kount]->value > .1){
    00808
    00809                                                 std::cout << varNames[ kount] << std::endl;
    00810                                                 indexes.push_back(startPnt +  i*(numNodes-1) + j    );
    00811
    00812
    00813                                         }
    00814
    00815                                         kount++;
    00816
    00817                                 }
    00818
    00819                                 for(j = i + 1; j < numNodes; j++){
    00820
    00821
    00822                                         if( primalValPair[ kount]->value > .1){
    00823                                                 std::cout << varNames[ kount] << std::endl;
    00824                                                 indexes.push_back(startPnt +  i*(numNodes-1) + j -1   );
    00825
    00826
    00827                                         }
    00828
    00829
    00830                                         kount++;
    00831
    00832                                 }
    00833
    00834                         }
    00835
    00836                         //create the map
    00837
    00838                         indexMap.insert(make_pair(k, indexes));
    00839
    00840                 }//end loop on k -- hubs
    00841
    00842
    00843                 std::cout << "DONE CALLING SOLVE FOR RESTRICTED MASTER" << std::endl;
    00844
    00845
    00846
    00847                 delete[] routeDemand;
    00848
    00849
    00850                 delete osilreader;
    00851                 osilreader = NULL;
    00852                 delete solver;
    00853                 solver = NULL;
    00854                 delete osoption;
    00855                 osoption = NULL;
    00856
    00857
    00858         } catch (const ErrorClass& eclass) {
    00859                 cout << endl << endl << endl;
    00860                 if (osilreader != NULL)
    00861                         delete osilreader;
    00862                 if (solver != NULL)
    00863                         delete solver;
    00864                 if (osoption != NULL)
    00865                         delete osoption;
    00866                 //  Problem with the parser
    00867                 throw ErrorClass(eclass.errormsg);
    00868         }
    00869
    00870         delete fileUtil;
    00871         fileUtil = NULL;
    00872         return indexMap;
    00873
    00874 }//end generateInitialMaster