| 1 | // $Id: readconic.cpp 1898 2013-04-09 18:06:04Z stefan $ |
| 2 | // Copyright (C) 2005, International Business Machines |
| 3 | // Corporation and others. All Rights Reserved. |
| 4 | // This code is licensed under the terms of the Eclipse Public License (EPL). |
| 5 | |
| 6 | #include "CoinMpsIO.hpp" |
| 7 | |
| 8 | int main (int argc, const char *argv[]) |
| 9 | { |
| 10 | CoinMpsIO m_MpsData; |
| 11 | int nOfSOS; |
| 12 | CoinSet ** SOS = NULL; |
| 13 | std::string mpsFileName; |
| 14 | #if defined(SAMPLEDIR) |
| 15 | mpsFileName = SAMPLEDIR "/conic.mps"; |
| 16 | #else |
| 17 | if (argc < 2) { |
| 18 | fprintf(stderr, "Do not know where to find sample MPS files.\n"); |
| 19 | exit(1); |
| 20 | } |
| 21 | #endif |
| 22 | if (argc>=2) mpsFileName = argv[1]; |
| 23 | int status = m_MpsData.readMps( mpsFileName.c_str(), "", nOfSOS, SOS ); |
| 24 | assert (!status); |
| 25 | int * columnStart = NULL; |
| 26 | int * columnIdx = NULL; |
| 27 | double * elements = NULL; |
| 28 | status = m_MpsData.readQuadraticMps(NULL, columnStart, columnIdx, elements, 0); |
| 29 | assert (!status); |
| 30 | int nOfCones; |
| 31 | int * coneStart = NULL; |
| 32 | int * coneIdx = NULL; |
| 33 | int * coneType = NULL; |
| 34 | status = m_MpsData.readConicMps(NULL, coneStart, coneIdx, coneType, nOfCones); |
| 35 | assert (!status); |
| 36 | if (nOfSOS) { |
| 37 | printf("%d SOS sets\n",nOfSOS); |
| 38 | for (int iSOS=0;iSOS<nOfSOS;iSOS++) { |
| 39 | int numberEntries = SOS[iSOS]->numberEntries(); |
| 40 | printf("Set %d has %d entries - type %d\n",iSOS,numberEntries,SOS[iSOS]->setType()); |
| 41 | const int * which = SOS[iSOS]->which(); |
| 42 | const double * weights = SOS[iSOS]->weights(); |
| 43 | for (int i=0;i<numberEntries;i++) |
| 44 | printf("(%d wt %g) ",which[i],weights[i]); |
| 45 | printf("\n"); |
| 46 | delete SOS[iSOS]; |
| 47 | } |
| 48 | } |
| 49 | delete [] SOS; |
| 50 | int numberColumns=m_MpsData.getNumCols(); |
| 51 | if (columnStart[numberColumns]) { |
| 52 | printf("Quadratic objective has %d entries\n",columnStart[numberColumns]); |
| 53 | for (int iColumn=0;iColumn<numberColumns;iColumn++) { |
| 54 | if(columnStart[iColumn]<columnStart[iColumn+1]) { |
| 55 | printf("Column %d obj ",iColumn); |
| 56 | for (int j=columnStart[iColumn];j<columnStart[iColumn+1];j++) |
| 57 | printf("(%d,%g) ",columnIdx[j],elements[j]); |
| 58 | printf("\n"); |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | delete [] columnStart; |
| 63 | delete [] columnIdx; |
| 64 | delete [] elements; |
| 65 | if (nOfCones) { |
| 66 | printf("Conic section has %d cones\n",nOfCones); |
| 67 | for (int iCone=0;iCone<nOfCones;iCone++) { |
| 68 | printf("Cone %d has %d entries (type %d) ",iCone,coneStart[iCone+1]-coneStart[iCone], |
| 69 | coneType[iCone]); |
| 70 | for (int j=coneStart[iCone];j<coneStart[iCone+1];j++) |
| 71 | printf("%d ",coneIdx[j]); |
| 72 | printf("\n"); |
| 73 | } |
| 74 | } |
| 75 | delete [] coneStart; |
| 76 | delete [] coneIdx; |
| 77 | delete [] coneType; |
| 78 | return 0; |
| 79 | } |