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

Go to the documentation of this file.
00001 /* $Id: OSmps2osil.cpp 4292 2011-09-21 05:47:18Z kmartin $ */
00016 #include "OSmps2osil.h"
00017 #include <iostream>
00018 
00019 
00020 
00021 using std::cout;
00022 using std::endl;
00023 
00024 OSmps2osil::OSmps2osil( std::string mpsfilename)
00025 {
00026     m_MpsData = new CoinMpsIO();
00027     m_MpsData->readMps( &mpsfilename[ 0] );
00028     m_CoinPackedMatrix  =  new CoinPackedMatrix( *(m_MpsData->getMatrixByCol()));
00029 }// end constructor
00030 
00031 OSmps2osil::~OSmps2osil()
00032 {
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     osinstance->setVariableNumber( numvar);
00066     for(i = 0; i < numvar; i++)
00067     {
00068         osinstance->addVariable(i, m_MpsData->columnName( i),
00069                                 m_MpsData->getColLower()[ i], m_MpsData->getColUpper()[ i],
00070                                 m_MpsData->isInteger( i)? 'I':'C');
00071     }
00072     //
00073     // now create the objective function
00074     //
00075     SparseVector* objectiveCoefficients = NULL;
00076     objectiveCoefficients = new SparseVector( numvar);
00077     double *p = const_cast<double*>(m_MpsData->getObjCoefficients());
00078     for(i = 0; i < numvar; i++)
00079     {
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     {
00097         osinstance->addConstraint(i, m_MpsData->rowName( i), m_MpsData->getRowLower()[i],
00098                                   m_MpsData->getRowUpper()[i], constant);
00099     }
00100     //
00101     // now fill in the lp arrays
00102     //
00103     int valuesBegin = 0;
00104     int valuesEnd = numnonz - 1;
00105     int startsBegin = 0;
00106     int indexesBegin = 0;
00107     int indexesEnd = numnonz - 1;
00108     int startsEnd = m_CoinPackedMatrix->isColOrdered()?numvar:numrows;
00109     osinstance->setLinearConstraintCoefficients(numnonz,  m_CoinPackedMatrix->isColOrdered(),
00110             const_cast<double*>(m_CoinPackedMatrix->getElements()), valuesBegin,  valuesEnd,
00111             const_cast<int*>(m_CoinPackedMatrix->getIndices()),  indexesBegin,  indexesEnd,
00112             const_cast<int*>(m_CoinPackedMatrix->getVectorStarts()),  startsBegin,  startsEnd);
00113     return true;
00114 }
00115 
00116 
00117 
00118 

Generated on Thu Nov 10 03:05:49 2011 by  doxygen 1.4.7