/Users/kmartin/Documents/files/code/cpp/OScpp/COIN-OS/OS/src/OSModelInterfaces/OSmps2osil.cpp

Go to the documentation of this file.
00001 
00017 #include "OSmps2osil.h"
00018 #include <iostream> 
00019 
00020 
00021 
00022 using std::cout;
00023 using std::endl;
00024 
00025 OSmps2osil::OSmps2osil( std::string mpsfilename)
00026 {
00027         m_MpsData = new CoinMpsIO();
00028         m_MpsData->readMps( &mpsfilename[ 0] ); 
00029         m_CoinPackedMatrix  =  new CoinPackedMatrix( *(m_MpsData->getMatrixByCol()));
00030 }// end constructor
00031 
00032 OSmps2osil::~OSmps2osil(){
00033         delete m_MpsData;
00034         m_MpsData = NULL;
00035         delete m_CoinPackedMatrix;
00036         m_CoinPackedMatrix = NULL;
00037         osinstance->instanceData->linearConstraintCoefficients->value->el = NULL;
00038         osinstance->instanceData->linearConstraintCoefficients->start->el = NULL;
00039         osinstance->instanceData->linearConstraintCoefficients->colIdx->el = NULL;
00040         osinstance->instanceData->linearConstraintCoefficients->rowIdx->el = NULL;
00041         delete osinstance;     
00042         osinstance = NULL;
00043         #ifdef DEBUG
00044         cout << "now delete m_MpsData" << endl;
00045         #endif
00046         delete m_MpsData;
00047 
00048 } // end destructor
00049 
00050 // Kipp-- put in integer programming
00051 bool OSmps2osil::createOSInstance( )
00052 {
00053         osinstance = new OSInstance();
00054         int i;
00055         int numvar =  m_MpsData->getNumCols();
00056         int numrows =  m_MpsData->getNumRows();
00057         int numnonz = m_MpsData->getNumElements();
00058         int numberObj = 1;
00059         int objIndex = -1;
00060         double objWeight = 1.0;
00061         osinstance->setInstanceName( const_cast<char*>(m_MpsData->getProblemName()));
00062         //
00063         // get the variable information
00064         //
00065         std::string initString;
00066         double init = OSNAN;
00067         osinstance->setVariableNumber( numvar);
00068         for(i = 0; i < numvar; i++)
00069         {
00070                 osinstance->addVariable(i, m_MpsData->columnName( i), 
00071                         m_MpsData->getColLower()[ i], m_MpsData->getColUpper()[ i], 
00072                         m_MpsData->isInteger( i)? 'I':'C', init, initString);
00073         }
00074         //
00075         // now create the objective function
00076         //      
00077         SparseVector* objectiveCoefficients = NULL;
00078         objectiveCoefficients = new SparseVector( numvar);
00079         double *p = const_cast<double*>(m_MpsData->getObjCoefficients());
00080         for(i = 0; i < numvar; i++){
00081                 objectiveCoefficients->indexes[i] = i;
00082                 objectiveCoefficients->values[i] = *(p++);
00083         }
00084         // kipp -- check on this -- does MPS assume a min???
00085         osinstance->setObjectiveNumber( numberObj) ;
00086         osinstance->addObjective(objIndex, m_MpsData->getObjectiveName(), 
00087         "min", m_MpsData->objectiveOffset(),  objWeight, objectiveCoefficients) ;
00088         delete objectiveCoefficients;
00089         objectiveCoefficients = NULL;
00090         //
00091         // now fill in row information
00092         //
00093         osinstance->setConstraintNumber( numrows);
00094         double constant = 0.0;
00095         for(i = 0; i < numrows; i++){
00096                 osinstance->addConstraint(i, m_MpsData->rowName( i), m_MpsData->getRowLower()[i], 
00097                 m_MpsData->getRowUpper()[i], constant);
00098         }
00099         //
00100         // now fill in the lp arrays
00101         //
00102         int valuesBegin = 0;
00103         int valuesEnd = numnonz - 1;
00104         int startsBegin = 0;
00105         int indexesBegin = 0;
00106         int indexesEnd = numnonz - 1;
00107         int startsEnd = m_CoinPackedMatrix->isColOrdered()?numvar:numrows;
00108         osinstance->setLinearConstraintCoefficients(numnonz,  m_CoinPackedMatrix->isColOrdered(), 
00109                 const_cast<double*>(m_CoinPackedMatrix->getElements()), valuesBegin,  valuesEnd, 
00110                 const_cast<int*>(m_CoinPackedMatrix->getIndices()),  indexesBegin,  indexesEnd,                         
00111                 const_cast<int*>(m_CoinPackedMatrix->getVectorStarts()),  startsBegin,  startsEnd);
00112         return true;
00113 }
00114 
00115 
00116 
00117 

Generated on Sat Mar 29 22:38:02 2008 by  doxygen 1.5.3