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

    r1271 r1286  
    1111
    1212// Default Constructor
    13 CbcHeuristicDiveFractional::CbcHeuristicDiveFractional() 
    14   :CbcHeuristicDive()
     13CbcHeuristicDiveFractional::CbcHeuristicDiveFractional()
     14        : CbcHeuristicDive()
    1515{
    1616}
     
    1818// Constructor from model
    1919CbcHeuristicDiveFractional::CbcHeuristicDiveFractional(CbcModel & model)
    20   :CbcHeuristicDive(model)
     20        : CbcHeuristicDive(model)
    2121{
    2222}
    2323
    24 // Destructor 
     24// Destructor
    2525CbcHeuristicDiveFractional::~CbcHeuristicDiveFractional ()
    2626{
     
    3131CbcHeuristicDiveFractional::clone() const
    3232{
    33   return new CbcHeuristicDiveFractional(*this);
     33    return new CbcHeuristicDiveFractional(*this);
    3434}
    3535
    3636// Create C++ lines to get to current state
    37 void 
    38 CbcHeuristicDiveFractional::generateCpp( FILE * fp) 
     37void
     38CbcHeuristicDiveFractional::generateCpp( FILE * fp)
    3939{
    40   CbcHeuristicDiveFractional other;
    41   fprintf(fp,"0#include \"CbcHeuristicDiveFractional.hpp\"\n");
    42   fprintf(fp,"3  CbcHeuristicDiveFractional heuristicDiveFractional(*cbcModel);\n");
    43   CbcHeuristic::generateCpp(fp,"heuristicDiveFractional");
    44   fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveFractional);\n");
     40    CbcHeuristicDiveFractional other;
     41    fprintf(fp, "0#include \"CbcHeuristicDiveFractional.hpp\"\n");
     42    fprintf(fp, "3  CbcHeuristicDiveFractional heuristicDiveFractional(*cbcModel);\n");
     43    CbcHeuristic::generateCpp(fp, "heuristicDiveFractional");
     44    fprintf(fp, "3  cbcModel->addHeuristic(&heuristicDiveFractional);\n");
    4545}
    4646
    47 // Copy constructor 
     47// Copy constructor
    4848CbcHeuristicDiveFractional::CbcHeuristicDiveFractional(const CbcHeuristicDiveFractional & rhs)
    49 :
    50   CbcHeuristicDive(rhs)
     49        :
     50        CbcHeuristicDive(rhs)
    5151{
    5252}
    5353
    54 // Assignment operator 
    55 CbcHeuristicDiveFractional & 
    56 CbcHeuristicDiveFractional::operator=( const CbcHeuristicDiveFractional& rhs)
     54// Assignment operator
     55CbcHeuristicDiveFractional &
     56CbcHeuristicDiveFractional::operator=( const CbcHeuristicDiveFractional & 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
    6464bool
    6565CbcHeuristicDiveFractional::selectVariableToBranch(OsiSolverInterface* solver,
    66                                                    const double* newSolution,
    67                                                    int& bestColumn,
    68                                                    int& bestRound)
     66        const double* newSolution,
     67        int& bestColumn,
     68        int& bestRound)
    6969{
    70   int numberIntegers = model_->numberIntegers();
    71   const int * integerVariable = model_->integerVariable();
    72   double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     70    int numberIntegers = model_->numberIntegers();
     71    const int * integerVariable = model_->integerVariable();
     72    double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
    7373
    74   bestColumn = -1;
    75   bestRound = -1; // -1 rounds down, +1 rounds up
    76   double bestFraction = DBL_MAX;
    77   bool allTriviallyRoundableSoFar = true;
    78   for (int i=0; i<numberIntegers; i++) {
    79     int iColumn = integerVariable[i];
    80     double value=newSolution[iColumn];
    81     double fraction=value-floor(value);
    82     int round = 0;
    83     if (fabs(floor(value+0.5)-value)>integerTolerance) {
    84       if (allTriviallyRoundableSoFar||(downLocks_[i]>0&&upLocks_[i]>0)) {
     74    bestColumn = -1;
     75    bestRound = -1; // -1 rounds down, +1 rounds up
     76    double bestFraction = DBL_MAX;
     77    bool allTriviallyRoundableSoFar = true;
     78    for (int i = 0; i < numberIntegers; i++) {
     79        int iColumn = integerVariable[i];
     80        double value = newSolution[iColumn];
     81        double fraction = value - floor(value);
     82        int round = 0;
     83        if (fabs(floor(value + 0.5) - value) > integerTolerance) {
     84            if (allTriviallyRoundableSoFar || (downLocks_[i] > 0 && upLocks_[i] > 0)) {
    8585
    86         if (allTriviallyRoundableSoFar&&downLocks_[i]>0&&upLocks_[i]>0) {
    87           allTriviallyRoundableSoFar = false;
    88           bestFraction = DBL_MAX;
    89         }
     86                if (allTriviallyRoundableSoFar && downLocks_[i] > 0 && upLocks_[i] > 0) {
     87                    allTriviallyRoundableSoFar = false;
     88                    bestFraction = DBL_MAX;
     89                }
    9090
    91         // the variable cannot be rounded
    92         if(fraction < 0.5)
    93           round = -1;
    94         else {
    95           round = 1;
    96           fraction = 1.0 - fraction;
    97         }
    98        
    99         // if variable is not binary, penalize it
    100         if(!solver->isBinary(iColumn))
    101           fraction *= 1000.0;
    102        
    103         if(fraction < bestFraction) {
    104           bestColumn = iColumn;
    105           bestFraction = fraction;
    106           bestRound = round;
    107         }
    108       }
     91                // the variable cannot be rounded
     92                if (fraction < 0.5)
     93                    round = -1;
     94                else {
     95                    round = 1;
     96                    fraction = 1.0 - fraction;
     97                }
     98
     99                // if variable is not binary, penalize it
     100                if (!solver->isBinary(iColumn))
     101                    fraction *= 1000.0;
     102
     103                if (fraction < bestFraction) {
     104                    bestColumn = iColumn;
     105                    bestFraction = fraction;
     106                    bestRound = round;
     107                }
     108            }
     109        }
    109110    }
    110   }
    111   return allTriviallyRoundableSoFar;
     111    return allTriviallyRoundableSoFar;
    112112}
Note: See TracChangeset for help on using the changeset viewer.