Ignore:
Timestamp:
Jan 6, 2019 6:17:46 PM (8 months ago)
Author:
unxusr
Message:

formatting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/examples/longthin.cpp

    r1898 r2469  
    66#include <cassert>
    77#include <iomanip>
    8 
    98
    109#include "CoinPragma.hpp"
     
    3433
    3534*/
    36 int main (int argc, const char *argv[])
     35int main(int argc, const char *argv[])
    3736{
    3837
    3938  // Define a Solver for long thin problems
    40  
     39
    4140  CbcSolver2 solver1;
    4241
     
    5251  }
    5352#endif
    54   if (argc>=2) mpsFileName = argv[1];
    55   int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
    56   if( numMpsReadErrors != 0 )
    57   {
    58      printf("%d errors reading MPS file\n", numMpsReadErrors);
    59      return numMpsReadErrors;
     53  if (argc >= 2)
     54    mpsFileName = argv[1];
     55  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(), "");
     56  if (numMpsReadErrors != 0) {
     57    printf("%d errors reading MPS file\n", numMpsReadErrors);
     58    return numMpsReadErrors;
    6059  }
    6160  double time1 = CoinCpuTime();
     
    6362  solver1.initialSolve();
    6463  // Reduce printout
    65   solver1.setHintParam(OsiDoReducePrint,true,OsiHintTry);
    66 
    67   OsiSolverInterface * solver2=&solver1;
     64  solver1.setHintParam(OsiDoReducePrint, true, OsiHintTry);
     65
     66  OsiSolverInterface *solver2 = &solver1;
    6867  CbcModel model(*solver2);
    6968  // Point to solver
    70   OsiSolverInterface * solver3 = model.solver();
    71   CbcSolver2 * osiclp = dynamic_cast< CbcSolver2*> (solver3);
    72   assert (osiclp);
    73   osiclp->initialize(&model,NULL);
     69  OsiSolverInterface *solver3 = model.solver();
     70  CbcSolver2 *osiclp = dynamic_cast< CbcSolver2 * >(solver3);
     71  assert(osiclp);
     72  osiclp->initialize(&model, NULL);
    7473  osiclp->setAlgorithm(2);
    7574  osiclp->setMemory(1000);
     
    8887  generator1.setRowCuts(3);
    8988
    90  
    9189  // Add in generators
    9290  // Experiment with -1 and -99 etc
    93   model.addCutGenerator(&generator1,-99,"Probing");
     91  model.addCutGenerator(&generator1, -99, "Probing");
    9492  // Allow rounding heuristic
    9593
     
    9795  model.addHeuristic(&heuristic1);
    9896
    99   // And Greedy heuristic 
     97  // And Greedy heuristic
    10098
    10199  CbcHeuristicGreedyCover heuristic2(model);
     
    115113  int numberColumns = solver3->getNumCols();
    116114  // do pseudo costs
    117   CbcObject ** objects = new CbcObject * [numberColumns];
    118   const CoinPackedMatrix * matrix = solver3->getMatrixByCol();
     115  CbcObject **objects = new CbcObject *[numberColumns];
     116  const CoinPackedMatrix *matrix = solver3->getMatrixByCol();
    119117  // Column copy
    120   const int * columnLength = matrix->getVectorLengths();
    121   const double * objective = model.getObjCoefficients();
    122   int numberIntegers=0;
    123   for (iColumn=0;iColumn<numberColumns;iColumn++) {
     118  const int *columnLength = matrix->getVectorLengths();
     119  const double *objective = model.getObjCoefficients();
     120  int numberIntegers = 0;
     121  for (iColumn = 0; iColumn < numberColumns; iColumn++) {
    124122    if (solver3->isInteger(iColumn)) {
    125123      /*  Branching up gets us much closer to an integer solution so we want
     
    130128          on a variable with many coefficients.  This leads to the computation below.
    131129      */
    132       double cost = objective[iColumn]*(1.0 + 0.2*((double) columnLength[iColumn]));
    133       CbcSimpleIntegerPseudoCost * newObject =
    134         new CbcSimpleIntegerPseudoCost(&model,iColumn,
    135                                        2.0*cost,cost);
     130      double cost = objective[iColumn] * (1.0 + 0.2 * ((double)columnLength[iColumn]));
     131      CbcSimpleIntegerPseudoCost *newObject = new CbcSimpleIntegerPseudoCost(&model, iColumn,
     132        2.0 * cost, cost);
    136133      newObject->setMethod(3);
    137       objects[numberIntegers++]= newObject;
     134      objects[numberIntegers++] = newObject;
    138135    }
    139136  }
    140   model.addObjects(numberIntegers,objects);
    141   for (iColumn=0;iColumn<numberIntegers;iColumn++)
     137  model.addObjects(numberIntegers, objects);
     138  for (iColumn = 0; iColumn < numberIntegers; iColumn++)
    142139    delete objects[iColumn];
    143   delete [] objects;
     140  delete[] objects;
    144141
    145142  // Do initial solve to continuous
     
    153150  osiclp->setSpecialOptions(16);
    154151  // We had better allow a lot
    155   model.solver()->setIntParam(OsiMaxNumIterationHotStart,10000);
     152  model.solver()->setIntParam(OsiMaxNumIterationHotStart, 10000);
    156153  // So use strategy to keep rows
    157154  osiclp->setStrategy(1);
    158155
    159156  // Switch off most output
    160   if (model.getNumCols()<3000) {
     157  if (model.getNumCols() < 3000) {
    161158    model.messageHandler()->setLogLevel(1);
    162159    //model.solver()->messageHandler()->setLogLevel(0);
     
    170167  try {
    171168    model.branchAndBound();
    172   }
    173   catch (CoinError e) {
     169  } catch (CoinError e) {
    174170    e.print();
    175     if (e.lineNumber()>=0)
    176       std::cout<<"This was from a CoinAssert"<<std::endl;
     171    if (e.lineNumber() >= 0)
     172      std::cout << "This was from a CoinAssert" << std::endl;
    177173    exit(0);
    178174  }
    179175  //void printHowMany();
    180176  //printHowMany();
    181   std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
    182            <<model.getNodeCount()<<" nodes with objective "
    183            <<model.getObjValue()
    184            <<(!model.status() ? " Finished" : " Not finished")
    185            <<std::endl;
     177  std::cout << mpsFileName << " took " << CoinCpuTime() - time1 << " seconds, "
     178            << model.getNodeCount() << " nodes with objective "
     179            << model.getObjValue()
     180            << (!model.status() ? " Finished" : " Not finished")
     181            << std::endl;
    186182
    187183  // Print solution if finished - we can't get names from Osi!
    188184
    189   if (model.getMinimizationObjValue()<1.0e50) {
     185  if (model.getMinimizationObjValue() < 1.0e50) {
    190186    int numberColumns = model.solver()->getNumCols();
    191    
    192     const double * solution = model.solver()->getColSolution();
    193    
     187
     188    const double *solution = model.solver()->getColSolution();
     189
    194190    int iColumn;
    195     std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
    196    
    197     std::cout<<"--------------------------------------"<<std::endl;
    198     for (iColumn=0;iColumn<numberColumns;iColumn++) {
    199       double value=solution[iColumn];
    200       if (fabs(value)>1.0e-7&&model.solver()->isInteger(iColumn))
    201         std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
     191    std::cout << std::setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14);
     192
     193    std::cout << "--------------------------------------" << std::endl;
     194    for (iColumn = 0; iColumn < numberColumns; iColumn++) {
     195      double value = solution[iColumn];
     196      if (fabs(value) > 1.0e-7 && model.solver()->isInteger(iColumn))
     197        std::cout << std::setw(6) << iColumn << " " << value << std::endl;
    202198    }
    203     std::cout<<"--------------------------------------"<<std::endl;
    204  
    205     std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
     199    std::cout << "--------------------------------------" << std::endl;
     200
     201    std::cout << std::resetiosflags(std::ios::fixed | std::ios::showpoint | std::ios::scientific);
    206202  }
    207203  return 0;
    208 }   
     204}
Note: See TracChangeset for help on using the changeset viewer.