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

- File List
- File Members

# /home/coin/SVN-release/OS-2.3.5/OS/src/OSModelInterfaces/OSmps2osil.cpp

Go to the documentation of this file.

    00001 /* $Id: OSmps2osil.cpp 3175 2010-02-05 07:17:03Z kmartin $ */
    00018 #include "OSmps2osil.h"
    00019 #include <iostream>
    00020
    00021
    00022
    00023 using std::cout;
    00024 using std::endl;
    00025
    00026 OSmps2osil::OSmps2osil( std::string mpsfilename)
    00027 {
    00028         m_MpsData = new CoinMpsIO();
    00029         m_MpsData->readMps( &mpsfilename[ 0] );
    00030         m_CoinPackedMatrix  =  new CoinPackedMatrix( *(m_MpsData->getMatrixByCol()));
    00031 }// end constructor
    00032
    00033 OSmps2osil::~OSmps2osil(){
    00034         delete m_MpsData;
    00035         m_MpsData = NULL;
    00036         delete m_CoinPackedMatrix;
    00037         m_CoinPackedMatrix = NULL;
    00038         osinstance->instanceData->linearConstraintCoefficients->value->el = NULL;
    00039         osinstance->instanceData->linearConstraintCoefficients->start->el = NULL;
    00040         osinstance->instanceData->linearConstraintCoefficients->colIdx->el = NULL;
    00041         osinstance->instanceData->linearConstraintCoefficients->rowIdx->el = NULL;
    00042         delete osinstance;
    00043         osinstance = NULL;
    00044         #ifdef DEBUG
    00045         cout << "now delete m_MpsData" << endl;
    00046         #endif
    00047         //delete m_MpsData;
    00048
    00049 } // end destructor
    00050
    00051 // Kipp-- put in integer programming
    00052 bool OSmps2osil::createOSInstance( )
    00053 {
    00054         osinstance = new OSInstance();
    00055         int i;
    00056         int numvar =  m_MpsData->getNumCols();
    00057         int numrows =  m_MpsData->getNumRows();
    00058         int numnonz = m_MpsData->getNumElements();
    00059         int numberObj = 1;
    00060         int objIndex = -1;
    00061         double objWeight = 1.0;
    00062         osinstance->setInstanceName( const_cast<char*>(m_MpsData->getProblemName()));
    00063         //
    00064         // get the variable information
    00065         //
    00066         osinstance->setVariableNumber( numvar);
    00067         for(i = 0; i < numvar; i++)
    00068         {
    00069                 osinstance->addVariable(i, m_MpsData->columnName( i),
    00070                         m_MpsData->getColLower()[ i], m_MpsData->getColUpper()[ i],
    00071                         m_MpsData->isInteger( i)? 'I':'C');
    00072         }
    00073         //
    00074         // now create the objective function
    00075         //
    00076         SparseVector* objectiveCoefficients = NULL;
    00077         objectiveCoefficients = new SparseVector( numvar);
    00078         double *p = const_cast<double*>(m_MpsData->getObjCoefficients());
    00079         for(i = 0; i < numvar; i++){
    00080                 objectiveCoefficients->indexes[i] = i;
    00081                 objectiveCoefficients->values[i] = *(p++);
    00082         }
    00083         // We will go with the
    00084         // majority on this one and assume minimization by default
    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