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/lotsize.cpp

    r1898 r2469  
    1616#include "CoinTime.hpp"
    1717
    18 
    1918/************************************************************************
    2019
     
    2524
    2625*************************************************************************/
    27 int main (int argc, const char *argv[])
     26int main(int argc, const char *argv[])
    2827{
    29  
     28
    3029  // Define your favorite OsiSolver
    31  
     30
    3231  OsiClpSolverInterface solver1;
    33  
     32
    3433  // Read in model using argv[1]
    3534  // and assert that it is a clean model
     
    4342  }
    4443#endif
    45   if (argc>=2) mpsFileName = argv[1];
    46   int numMpsReadErrors = solver1.readMps(mpsFileName.c_str(),"");
    47   if( numMpsReadErrors != 0 )
    48   {
    49      printf("%d errors reading MPS file\n", numMpsReadErrors);
    50      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;
    5150  }
    52  
     51
    5352  int iColumn;
    5453  int numberColumns = solver1.getNumCols();
    55   int numberLot=0;
    56   char * mark = new char[numberColumns];
     54  int numberLot = 0;
     55  char *mark = new char[numberColumns];
    5756  // take off integers but find where they are
    58   for (iColumn=0;iColumn<numberColumns;iColumn++) {
     57  for (iColumn = 0; iColumn < numberColumns; iColumn++) {
    5958    if (solver1.isBinary(iColumn)) {
    6059      solver1.setContinuous(iColumn);
    61       mark[iColumn]=1;
     60      mark[iColumn] = 1;
    6261      numberLot++;
    6362    } else {
    64       mark[iColumn]=0;
     63      mark[iColumn] = 0;
    6564    }
    6665  }
    6766  CbcModel model(solver1);
    6867  // Do lotsizing
    69   CbcObject ** objects = new CbcObject * [numberLot];
    70   numberLot=0;
     68  CbcObject **objects = new CbcObject *[numberLot];
     69  numberLot = 0;
    7170  /* For semi-continuous variables numberRanges is 2
    7271     and ranges[]={0.0,0.0,K,COIN_DBL_MAX};
    7372  */
    7473  // valid ranges are 0.0 to 0.0, 0.45 to 0.55, 1.0 to 1.0
    75   double ranges[]={0.0,0.0,0.45,0.55,1.0,1.0};
    76   for (iColumn=0;iColumn<numberColumns;iColumn++) {
     74  double ranges[] = { 0.0, 0.0, 0.45, 0.55, 1.0, 1.0 };
     75  for (iColumn = 0; iColumn < numberColumns; iColumn++) {
    7776    if (mark[iColumn])
    78     objects[numberLot++]= new CbcLotsize(&model,iColumn,3,ranges,true);
     77      objects[numberLot++] = new CbcLotsize(&model, iColumn, 3, ranges, true);
    7978  }
    80   delete [] mark;
    81   model.addObjects(numberLot,objects);
    82   for (iColumn=0;iColumn<numberLot;iColumn++)
     79  delete[] mark;
     80  model.addObjects(numberLot, objects);
     81  for (iColumn = 0; iColumn < numberLot; iColumn++)
    8382    delete objects[iColumn];
    84   delete [] objects;
     83  delete[] objects;
    8584
    8685  // If time is given then stop after that number of minutes
    87   if (argc>2) {
     86  if (argc > 2) {
    8887    int minutes = atoi(argv[2]);
    89     std::cout<<"Stopping after "<<minutes<<" minutes"<<std::endl;
    90     assert (minutes>=0);
    91     model.setDblParam(CbcModel::CbcMaximumSeconds,60.0*minutes);
     88    std::cout << "Stopping after " << minutes << " minutes" << std::endl;
     89    assert(minutes >= 0);
     90    model.setDblParam(CbcModel::CbcMaximumSeconds, 60.0 * minutes);
    9291  }
    9392  // Switch off most output
    94   model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
    95   if (model.getNumCols()<3000) {
     93  model.solver()->setHintParam(OsiDoReducePrint, true, OsiHintTry);
     94  if (model.getNumCols() < 3000) {
    9695    model.messageHandler()->setLogLevel(1);
    9796    //model.solver()->messageHandler()->setLogLevel(0);
     
    101100  }
    102101  model.messageHandler()->setLogLevel(1);
    103  
     102
    104103  double time1 = CoinCpuTime();
    105104
    106105  // Do complete search
    107  
     106
    108107  model.branchAndBound();
    109108
    110   std::cout<<mpsFileName<<" took "<<CoinCpuTime()-time1<<" seconds, "
    111            <<model.getNodeCount()<<" nodes with objective "
    112            <<model.getObjValue()
    113            <<(!model.status() ? " Finished" : " Not finished")
    114            <<std::endl;
     109  std::cout << mpsFileName << " took " << CoinCpuTime() - time1 << " seconds, "
     110            << model.getNodeCount() << " nodes with objective "
     111            << model.getObjValue()
     112            << (!model.status() ? " Finished" : " Not finished")
     113            << std::endl;
    115114
    116115  // Print solution - we can't get names from Osi!
    117116
    118   if (model.getMinimizationObjValue()<1.0e50) {
     117  if (model.getMinimizationObjValue() < 1.0e50) {
    119118    int numberColumns = model.solver()->getNumCols();
    120    
    121     const double * solution = model.solver()->getColSolution();
    122    
     119
     120    const double *solution = model.solver()->getColSolution();
     121
    123122    int iColumn;
    124     std::cout<<std::setiosflags(std::ios::fixed|std::ios::showpoint)<<std::setw(14);
    125    
    126     std::cout<<"--------------------------------------"<<std::endl;
    127     for (iColumn=0;iColumn<numberColumns;iColumn++) {
    128       double value=solution[iColumn];
    129       if (fabs(value)>1.0e-7)
    130         std::cout<<std::setw(6)<<iColumn<<" "<<value<<std::endl;
     123    std::cout << std::setiosflags(std::ios::fixed | std::ios::showpoint) << std::setw(14);
     124
     125    std::cout << "--------------------------------------" << std::endl;
     126    for (iColumn = 0; iColumn < numberColumns; iColumn++) {
     127      double value = solution[iColumn];
     128      if (fabs(value) > 1.0e-7)
     129        std::cout << std::setw(6) << iColumn << " " << value << std::endl;
    131130    }
    132     std::cout<<"--------------------------------------"<<std::endl;
    133  
    134     std::cout<<std::resetiosflags(std::ios::fixed|std::ios::showpoint|std::ios::scientific);
     131    std::cout << "--------------------------------------" << std::endl;
     132
     133    std::cout << std::resetiosflags(std::ios::fixed | std::ios::showpoint | std::ios::scientific);
    135134  }
    136135  return 0;
    137 }   
     136}
Note: See TracChangeset for help on using the changeset viewer.