Changeset 838 for branches


Ignore:
Timestamp:
Jul 12, 2006 4:06:07 PM (13 years ago)
Author:
forrest
Message:

modify example

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Clp/examples/addRows.cpp

    r560 r838  
    77#include "CoinHelperFunctions.hpp"
    88#include "CoinTime.hpp"
     9#include "CoinMpsIO.hpp"
    910#include "CoinBuild.hpp"
    1011#include "CoinModel.hpp"
    1112#include <iomanip>
    1213#include <cassert>
    13 
    1414int main (int argc, const char *argv[])
    1515{
     
    194194    }
    195195    std::cout<<"--------------------------------------"<<std::endl;
     196
     197#ifndef NDEBUG
    196198    // Test CoinAssert
    197199    std::cout<<"If Clp compiled with -g below should give assert, if with -O1 or COIN_ASSERT CoinError"<<std::endl;
     
    210212    }
    211213    model.addRows(buildObject3,true);
     214#endif
    212215  }
    213216  catch (CoinError e) {
     
    216219      std::cout<<"This was from a CoinAssert"<<std::endl;
    217220  }
     221  {
     222    // Get a model
     223    CoinMpsIO m;
     224    const char dirsep =  CoinFindDirSeparator();
     225    // Set directory containing mps data files.
     226    std::string mpsDir = dirsep == '/' ? "../../Data/Sample/" : "..\\..\\Data\\Sample\\";
     227    std::string fn = mpsDir+"exmip1";
     228    int numErr = m.readMps(fn.c_str(),"mps");
     229    assert( numErr== 0 );
     230   
     231    int numberRows = m.getNumRows();
     232    int numberColumns = m.getNumCols();
     233   
     234    // Build by row from scratch
     235    CoinPackedMatrix matrixByRow = * m.getMatrixByRow();
     236    const double * element = matrixByRow.getElements();
     237    const int * column = matrixByRow.getIndices();
     238    const CoinBigIndex * rowStart = matrixByRow.getVectorStarts();
     239    const int * rowLength = matrixByRow.getVectorLengths();
     240    const double * rowLower = m.getRowLower();
     241    const double * rowUpper = m.getRowUpper();
     242    const double * columnLower = m.getColLower();
     243    const double * columnUpper = m.getColUpper();
     244    const double * objective = m.getObjCoefficients();
     245    int i;
     246    CoinModel coinModel;
     247    for (i=0;i<numberRows;i++) {
     248      coinModel.addRow(rowLength[i],column+rowStart[i],
     249                  element+rowStart[i],rowLower[i],rowUpper[i],m.rowName(i));
     250    }
     251    // Now do column part
     252    for (i=0;i<numberColumns;i++) {
     253      coinModel.setColumnBounds(i,columnLower[i],columnUpper[i]);
     254      coinModel.setColumnObjective(i,objective[i]);
     255      if (m.isInteger(i))
     256        coinModel.setColumnIsInteger(i,true);;
     257    }
     258    ClpSimplex model;
     259    model.loadProblem(coinModel,true);
     260    model.dual();
     261    double objectiveValue = model.objectiveValue();
     262    // Now replace -1.0 by -1.0
     263    for (i=0;i<numberRows;i++) {
     264      CoinModelLink triple=coinModel.firstInRow(i);
     265      while (triple.column()>=0) {
     266        if (triple.value()==-1.0) {
     267          // replace by string
     268          coinModel(i,triple.column(),"minusOne");
     269        }
     270        triple=coinModel.next(triple);
     271      }
     272    }
     273    // associate -1.0 with -1.0
     274    coinModel.associateElement("minusOne",-1.0);
     275    model.loadProblem(coinModel,true);
     276    model.dual();
     277    // result should be same
     278    CoinRelFltEq eq;
     279    assert (eq(objectiveValue,model.objectiveValue()));
     280    // now go round changing -1.0 wherever it occurs
     281    double value=-1.0;
     282    while (model.isProvenOptimal()) {
     283      value -= 0.2;
     284      coinModel.associateElement("minusOne",value);
     285      model.loadProblem(coinModel,true);
     286      printf("solving for -1.0 -> %g\n",value);
     287      model.dual();
     288    }
     289  }
    218290  return 0;
    219291}   
Note: See TracChangeset for help on using the changeset viewer.