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

formatting

File:
1 edited

Legend:

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

    r1898 r2469  
    2424
    2525*/
    26 int main (int argc, const char *argv[])
     26int main(int argc, const char *argv[])
    2727{
    2828
    2929  // Define a Solver for long thin problems
    30  
     30
    3131  OsiClpSolverInterface solver1;
    3232
     
    4242  }
    4343#endif
    44   if (argc>=2) mpsFileName = argv[1];
    45   int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
    46   if( numMpsReadErrors != 0 )
    47   {
    48      printf("%d errors reading MPS file\n", numMpsReadErrors);
    49      return numMpsReadErrors;
     44  if (argc >= 2)
     45    mpsFileName = argv[1];
     46  int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(), "");
     47  if (numMpsReadErrors != 0) {
     48    printf("%d errors reading MPS file\n", numMpsReadErrors);
     49    return numMpsReadErrors;
    5050  }
    5151  double time1 = CoinCpuTime();
     
    5353  solver1.initialSolve();
    5454  // Reduce printout
    55   solver1.setHintParam(OsiDoReducePrint,true,OsiHintTry);
     55  solver1.setHintParam(OsiDoReducePrint, true, OsiHintTry);
    5656
    57   OsiSolverInterface * solver2=&solver1;
     57  OsiSolverInterface *solver2 = &solver1;
    5858  CbcModel model(*solver2);
    5959  // Point to solver
    60   OsiSolverInterface * solver3 = model.solver();
    61   assert (dynamic_cast< OsiClpSolverInterface*> (solver3));
     60  OsiSolverInterface *solver3 = model.solver();
     61  assert(dynamic_cast< OsiClpSolverInterface * >(solver3));
    6262
    6363  // Definition of node choice
    6464  CbcCompareUser compare;
    6565  model.setNodeComparison(compare);
    66 
    6766
    6867  int iColumn;
     
    7473  */
    7574  // Normal integer priorities
    76   int * priority = new int [numberColumns];
    77   int numberIntegers=0;
    78   for (iColumn=0;iColumn<numberColumns;iColumn++) {
     75  int *priority = new int[numberColumns];
     76  int numberIntegers = 0;
     77  for (iColumn = 0; iColumn < numberColumns; iColumn++) {
    7978    if (solver3->isInteger(iColumn)) {
    80       priority[numberIntegers++]= 100; // low priority
     79      priority[numberIntegers++] = 100; // low priority
    8180    }
    8281  }
    8382  /* Second parameter is true if we are adding objects,
    8483     false if integers.  So this does integers */
    85   model.passInPriorities(priority,false);
    86   delete [] priority;
     84  model.passInPriorities(priority, false);
     85  delete[] priority;
    8786  /* Add in objects before we can give priority.
    8887     In this case just one - but this shows general method
    8988  */
    90   CbcObject ** objects = new CbcObject * [1];
    91   objects[0]=new CbcFollowOn(&model);
    92   model.addObjects(1,objects);
     89  CbcObject **objects = new CbcObject *[1];
     90  objects[0] = new CbcFollowOn(&model);
     91  model.addObjects(1, objects);
    9392  delete objects[0];
    94   delete [] objects;
     93  delete[] objects;
    9594  // High priority
    96   int followPriority=1;
    97   model.passInPriorities(&followPriority,true);
     95  int followPriority = 1;
     96  model.passInPriorities(&followPriority, true);
    9897
    9998  // Do initial solve to continuous
     
    104103  model.setNumberStrong(0);
    105104
    106   model.solver()->setIntParam(OsiMaxNumIterationHotStart,100);
     105  model.solver()->setIntParam(OsiMaxNumIterationHotStart, 100);
    107106
    108107  // Switch off most output
    109   if (model.getNumCols()<3000) {
     108  if (model.getNumCols() < 3000) {
    110109    model.messageHandler()->setLogLevel(1);
    111110    //model.solver()->messageHandler()->setLogLevel(0);
     
    119118  try {
    120119    model.branchAndBound();
    121   }
    122   catch (CoinError e) {
     120  } catch (CoinError e) {
    123121    e.print();
    124     if (e.lineNumber()>=0)
    125       std::cout<<"This was from a CoinAssert"<<std::endl;
     122    if (e.lineNumber() >= 0)
     123      std::cout << "This was from a CoinAssert" << std::endl;
    126124    exit(0);
    127125  }
    128126  //void printHowMany();
    129127  //printHowMany();
    130   std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
    131            <<model.getNodeCount()<<" nodes with objective "
    132            <<model.getObjValue()
    133            <<(!model.status() ? " Finished" : " Not finished")
    134            <<std::endl;
     128  std::cout << mpsFileName << " took " << CoinCpuTime() - time1 << " seconds, "
     129            << model.getNodeCount() << " nodes with objective "
     130            << model.getObjValue()
     131            << (!model.status() ? " Finished" : " Not finished")
     132            << std::endl;
    135133
    136134  // Print solution if finished - we can't get names from Osi!
    137135
    138   if (model.getMinimizationObjValue()<1.0e50) {
     136  if (model.getMinimizationObjValue() < 1.0e50) {
    139137    int numberColumns = model.solver()->getNumCols();
    140    
    141     const double * solution = model.solver()->getColSolution();
    142    
     138
     139    const double *solution = model.solver()->getColSolution();
     140
    143141    int iColumn;
    144     std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
    145    
    146     std::cout<<"--------------------------------------"<<std::endl;
    147     for (iColumn=0;iColumn<numberColumns;iColumn++) {
    148       double value=solution[iColumn];
    149       if (fabs(value)>1.0e-7&&model.solver()->isInteger(iColumn))
    150         std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
     142    std::cout << std::setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14);
     143
     144    std::cout << "--------------------------------------" << std::endl;
     145    for (iColumn = 0; iColumn < numberColumns; iColumn++) {
     146      double value = solution[iColumn];
     147      if (fabs(value) > 1.0e-7 && model.solver()->isInteger(iColumn))
     148        std::cout << std::setw(6) << iColumn << " " << value << std::endl;
    151149    }
    152     std::cout<<"--------------------------------------"<<std::endl;
    153  
    154     std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
     150    std::cout << "--------------------------------------" << std::endl;
     151
     152    std::cout << std::resetiosflags(std::ios::fixed | std::ios::showpoint | std::ios::scientific);
    155153  }
    156154  return 0;
    157 }   
     155}
Note: See TracChangeset for help on using the changeset viewer.