Ignore:
Timestamp:
Nov 9, 2009 6:33:07 PM (10 years ago)
Author:
EdwinStraver
Message:

Changed formatting using AStyle -A4 -p

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/sandbox/Cbc/src/CbcHeuristicDiveGuided.cpp

    r1271 r1286  
    1111
    1212// Default Constructor
    13 CbcHeuristicDiveGuided::CbcHeuristicDiveGuided() 
    14   :CbcHeuristicDive()
     13CbcHeuristicDiveGuided::CbcHeuristicDiveGuided()
     14        : CbcHeuristicDive()
    1515{
    1616}
     
    1818// Constructor from model
    1919CbcHeuristicDiveGuided::CbcHeuristicDiveGuided(CbcModel & model)
    20   :CbcHeuristicDive(model)
     20        : CbcHeuristicDive(model)
    2121{
    2222}
    2323
    24 // Destructor 
     24// Destructor
    2525CbcHeuristicDiveGuided::~CbcHeuristicDiveGuided ()
    2626{
     
    3131CbcHeuristicDiveGuided::clone() const
    3232{
    33   return new CbcHeuristicDiveGuided(*this);
     33    return new CbcHeuristicDiveGuided(*this);
    3434}
    3535
    3636// Create C++ lines to get to current state
    37 void 
    38 CbcHeuristicDiveGuided::generateCpp( FILE * fp) 
     37void
     38CbcHeuristicDiveGuided::generateCpp( FILE * fp)
    3939{
    40   CbcHeuristicDiveGuided other;
    41   fprintf(fp,"0#include \"CbcHeuristicDiveGuided.hpp\"\n");
    42   fprintf(fp,"3  CbcHeuristicDiveGuided heuristicDiveGuided(*cbcModel);\n");
    43   CbcHeuristic::generateCpp(fp,"heuristicDiveGuided");
    44   fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveGuided);\n");
     40    CbcHeuristicDiveGuided other;
     41    fprintf(fp, "0#include \"CbcHeuristicDiveGuided.hpp\"\n");
     42    fprintf(fp, "3  CbcHeuristicDiveGuided heuristicDiveGuided(*cbcModel);\n");
     43    CbcHeuristic::generateCpp(fp, "heuristicDiveGuided");
     44    fprintf(fp, "3  cbcModel->addHeuristic(&heuristicDiveGuided);\n");
    4545}
    4646
    47 // Copy constructor 
     47// Copy constructor
    4848CbcHeuristicDiveGuided::CbcHeuristicDiveGuided(const CbcHeuristicDiveGuided & rhs)
    49 :
    50   CbcHeuristicDive(rhs)
     49        :
     50        CbcHeuristicDive(rhs)
    5151{
    5252}
    5353
    54 // Assignment operator 
    55 CbcHeuristicDiveGuided & 
    56 CbcHeuristicDiveGuided::operator=( const CbcHeuristicDiveGuided& rhs)
     54// Assignment operator
     55CbcHeuristicDiveGuided &
     56CbcHeuristicDiveGuided::operator=( const CbcHeuristicDiveGuided & rhs)
    5757{
    58   if (this!=&rhs) {
    59     CbcHeuristicDive::operator=(rhs);
    60   }
    61   return *this;
     58    if (this != &rhs) {
     59        CbcHeuristicDive::operator=(rhs);
     60    }
     61    return *this;
    6262}
    6363
     
    6565CbcHeuristicDiveGuided::canHeuristicRun()
    6666{
    67   double* bestIntegerSolution = model_->bestSolution();
    68   if(bestIntegerSolution == NULL)
    69     return false; // no integer solution available. Switch off heuristic
     67    double* bestIntegerSolution = model_->bestSolution();
     68    if (bestIntegerSolution == NULL)
     69        return false; // no integer solution available. Switch off heuristic
    7070
    71   return CbcHeuristicDive::canHeuristicRun();
     71    return CbcHeuristicDive::canHeuristicRun();
    7272}
    7373
    7474bool
    7575CbcHeuristicDiveGuided::selectVariableToBranch(OsiSolverInterface* solver,
    76                                                const double* newSolution,
    77                                                int& bestColumn,
    78                                                int& bestRound)
     76        const double* newSolution,
     77        int& bestColumn,
     78        int& bestRound)
    7979{
    80   double* bestIntegerSolution = model_->bestSolution();
     80    double* bestIntegerSolution = model_->bestSolution();
    8181
    82   int numberIntegers = model_->numberIntegers();
    83   const int * integerVariable = model_->integerVariable();
    84   double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     82    int numberIntegers = model_->numberIntegers();
     83    const int * integerVariable = model_->integerVariable();
     84    double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
    8585
    86   bestColumn = -1;
    87   bestRound = -1; // -1 rounds down, +1 rounds up
    88   double bestFraction = DBL_MAX;
    89   bool allTriviallyRoundableSoFar = true;
    90   for (int i=0; i<numberIntegers; i++) {
    91     int iColumn = integerVariable[i];
    92     double value=newSolution[iColumn];
    93     double fraction=value-floor(value);
    94     int round = 0;
    95     if (fabs(floor(value+0.5)-value)>integerTolerance) {
    96       if(allTriviallyRoundableSoFar||(downLocks_[i]>0&&upLocks_[i]>0)) {
     86    bestColumn = -1;
     87    bestRound = -1; // -1 rounds down, +1 rounds up
     88    double bestFraction = DBL_MAX;
     89    bool allTriviallyRoundableSoFar = true;
     90    for (int i = 0; i < numberIntegers; i++) {
     91        int iColumn = integerVariable[i];
     92        double value = newSolution[iColumn];
     93        double fraction = value - floor(value);
     94        int round = 0;
     95        if (fabs(floor(value + 0.5) - value) > integerTolerance) {
     96            if (allTriviallyRoundableSoFar || (downLocks_[i] > 0 && upLocks_[i] > 0)) {
    9797
    98         if(allTriviallyRoundableSoFar&&downLocks_[i]>0&&upLocks_[i]>0) {
    99           allTriviallyRoundableSoFar = false;
    100           bestFraction = DBL_MAX;
    101         }
     98                if (allTriviallyRoundableSoFar && downLocks_[i] > 0 && upLocks_[i] > 0) {
     99                    allTriviallyRoundableSoFar = false;
     100                    bestFraction = DBL_MAX;
     101                }
    102102
    103         if(value >= bestIntegerSolution[iColumn])
    104           round = -1;
    105         else {
    106           round = 1;
    107           fraction = 1.0 - fraction;
    108         }
    109        
    110         // if variable is not binary, penalize it
    111         if(!solver->isBinary(iColumn))
    112           fraction *= 1000.0;
     103                if (value >= bestIntegerSolution[iColumn])
     104                    round = -1;
     105                else {
     106                    round = 1;
     107                    fraction = 1.0 - fraction;
     108                }
    113109
    114         if(fraction < bestFraction) {
    115           bestColumn = iColumn;
    116           bestFraction = fraction;
    117           bestRound = round;
    118         }
    119       }
     110                // if variable is not binary, penalize it
     111                if (!solver->isBinary(iColumn))
     112                    fraction *= 1000.0;
     113
     114                if (fraction < bestFraction) {
     115                    bestColumn = iColumn;
     116                    bestFraction = fraction;
     117                    bestRound = round;
     118                }
     119            }
     120        }
    120121    }
    121   }
    122   return allTriviallyRoundableSoFar;
     122    return allTriviallyRoundableSoFar;
    123123}
Note: See TracChangeset for help on using the changeset viewer.