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

formatting

File:
1 edited

Legend:

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

    r1898 r2469  
    66#include <cassert>
    77#include <iomanip>
    8 
    98
    109// For Branch and bound
     
    2019//#############################################################################
    2120
    22 
    2321/************************************************************************
    2422
     
    2826************************************************************************/
    2927
    30 int main (int argc, const char *argv[])
     28int main(int argc, const char *argv[])
    3129{
    3230
     
    4442  }
    4543#endif
    46   if (argc>=2) mpsFileName = argv[1];
    47   int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
    48   if( numMpsReadErrors != 0 )
    49   {
    50      printf("%d errors reading MPS file\n", numMpsReadErrors);
    51      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;
    5250  }
    5351  double time1 = CoinCpuTime();
     
    5856     if 2 parameters and numeric taken as time
    5957  */
    60   bool preProcess=false;
    61   double minutes=-1.0;
    62   int nGoodParam=0;
    63   for (int iParam=2; iParam<argc;iParam++) {
    64     if (!strcmp(argv[iParam],"preprocess")) {
    65       preProcess=true;
     58  bool preProcess = false;
     59  double minutes = -1.0;
     60  int nGoodParam = 0;
     61  for (int iParam = 2; iParam < argc; iParam++) {
     62    if (!strcmp(argv[iParam], "preprocess")) {
     63      preProcess = true;
    6664      nGoodParam++;
    67     } else if (!strcmp(argv[iParam],"time")) {
    68       if (iParam+1<argc&&isdigit(argv[iParam+1][0])) {
    69         minutes=atof(argv[iParam+1]);
    70         if (minutes>=0.0) {
    71           nGoodParam+=2;
     65    } else if (!strcmp(argv[iParam], "time")) {
     66      if (iParam + 1 < argc && isdigit(argv[iParam + 1][0])) {
     67        minutes = atof(argv[iParam + 1]);
     68        if (minutes >= 0.0) {
     69          nGoodParam += 2;
    7270          iParam++; // skip time
    7371        }
     
    7573    }
    7674  }
    77   if (nGoodParam==0&&argc==3&&isdigit(argv[2][0])) {
     75  if (nGoodParam == 0 && argc == 3 && isdigit(argv[2][0])) {
    7876    // If time is given then stop after that number of minutes
    7977    minutes = atof(argv[2]);
    80     if (minutes>=0.0)
    81       nGoodParam=1;
     78    if (minutes >= 0.0)
     79      nGoodParam = 1;
    8280  }
    83   if (nGoodParam!=argc-2&&argc>=2) {
     81  if (nGoodParam != argc - 2 && argc >= 2) {
    8482    printf("Usage <file> [preprocess] [time <minutes>] or <file> <minutes>\n");
    8583    exit(1);
    8684  }
    8785  // See if we want preprocessing
    88   OsiSolverInterface * solver2=&solver1;
     86  OsiSolverInterface *solver2 = &solver1;
    8987  CglPreProcess process;
    9088  if (preProcess) {
    9189    /* Do not try and produce equality cliques and
    9290       do up to 5 passes */
    93     solver2 = process.preProcess(solver1,false,5);
     91    solver2 = process.preProcess(solver1, false, 5);
    9492    if (!solver2) {
    9593      printf("Pre-processing says infeasible\n");
     
    10098  CbcModel model(*solver2);
    10199  // If time is given then stop after that number of minutes
    102   if (minutes>=0.0) {
    103     std::cout<<"Stopping after "<<minutes<<" minutes"<<std::endl;
    104     model.setDblParam(CbcModel::CbcMaximumSeconds,60.0*minutes);
     100  if (minutes >= 0.0) {
     101    std::cout << "Stopping after " << minutes << " minutes" << std::endl;
     102    model.setDblParam(CbcModel::CbcMaximumSeconds, 60.0 * minutes);
    105103  }
    106104  // Set strategy - below is == CbcStrategyDefault()
    107   CbcStrategyDefault strategy(true,5,0);
     105  CbcStrategyDefault strategy(true, 5, 0);
    108106  model.setStrategy(strategy);
    109107  // Do complete search
    110  
     108
    111109  model.branchAndBound();
    112110
    113   std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
    114            <<model.getNodeCount()<<" nodes with objective "
    115            <<model.getObjValue()
    116            <<(!model.status() ? " Finished" : " Not finished")
    117            <<std::endl;
     111  std::cout << mpsFileName << " took " << CoinCpuTime() - time1 << " seconds, "
     112            << model.getNodeCount() << " nodes with objective "
     113            << model.getObjValue()
     114            << (!model.status() ? " Finished" : " Not finished")
     115            << std::endl;
    118116
    119117  // Print solution if finished - we can't get names from Osi!
    120118
    121   if (model.getMinimizationObjValue()<1.0e50) {
     119  if (model.getMinimizationObjValue() < 1.0e50) {
    122120    // post process
    123     OsiSolverInterface * solver;
     121    OsiSolverInterface *solver;
    124122    if (preProcess) {
    125123      process.postProcess(*model.solver());
    126124      // Solution now back in solver1
    127       solver = & solver1;
     125      solver = &solver1;
    128126    } else {
    129127      solver = model.solver();
    130128    }
    131129    int numberColumns = solver->getNumCols();
    132    
    133     const double * solution = solver->getColSolution();
    134    
     130
     131    const double *solution = solver->getColSolution();
     132
    135133    int iColumn;
    136     std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
    137    
    138     std::cout<<"--------------------------------------"<<std::endl;
    139     for (iColumn=0;iColumn<numberColumns;iColumn++) {
    140       double value=solution[iColumn];
    141       if (fabs(value)>1.0e-7&&solver->isInteger(iColumn))
    142         std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
     134    std::cout << std::setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14);
     135
     136    std::cout << "--------------------------------------" << std::endl;
     137    for (iColumn = 0; iColumn < numberColumns; iColumn++) {
     138      double value = solution[iColumn];
     139      if (fabs(value) > 1.0e-7 && solver->isInteger(iColumn))
     140        std::cout << std::setw(6) << iColumn << " " << value << std::endl;
    143141    }
    144     std::cout<<"--------------------------------------"<<std::endl;
    145  
    146     std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
     142    std::cout << "--------------------------------------" << std::endl;
     143
     144    std::cout << std::resetiosflags(std::ios::fixed | std::ios::showpoint | std::ios::scientific);
    147145  }
    148146  return 0;
    149 }   
     147}
Note: See TracChangeset for help on using the changeset viewer.