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

    r1271 r1286  
    1111
    1212// Default Constructor
    13 CbcHeuristicDiveLineSearch::CbcHeuristicDiveLineSearch() 
    14   :CbcHeuristicDive()
     13CbcHeuristicDiveLineSearch::CbcHeuristicDiveLineSearch()
     14        : CbcHeuristicDive()
    1515{
    1616}
     
    1818// Constructor from model
    1919CbcHeuristicDiveLineSearch::CbcHeuristicDiveLineSearch(CbcModel & model)
    20   :CbcHeuristicDive(model)
     20        : CbcHeuristicDive(model)
    2121{
    2222}
    2323
    24 // Destructor 
     24// Destructor
    2525CbcHeuristicDiveLineSearch::~CbcHeuristicDiveLineSearch ()
    2626{
     
    3131CbcHeuristicDiveLineSearch::clone() const
    3232{
    33   return new CbcHeuristicDiveLineSearch(*this);
     33    return new CbcHeuristicDiveLineSearch(*this);
    3434}
    3535
    3636// Create C++ lines to get to current state
    37 void 
    38 CbcHeuristicDiveLineSearch::generateCpp( FILE * fp) 
     37void
     38CbcHeuristicDiveLineSearch::generateCpp( FILE * fp)
    3939{
    40   CbcHeuristicDiveLineSearch other;
    41   fprintf(fp,"0#include \"CbcHeuristicDiveLineSearch.hpp\"\n");
    42   fprintf(fp,"3  CbcHeuristicDiveLineSearch heuristicDiveLineSearch(*cbcModel);\n");
    43   CbcHeuristic::generateCpp(fp,"heuristicDiveLineSearch");
    44   fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveLineSearch);\n");
     40    CbcHeuristicDiveLineSearch other;
     41    fprintf(fp, "0#include \"CbcHeuristicDiveLineSearch.hpp\"\n");
     42    fprintf(fp, "3  CbcHeuristicDiveLineSearch heuristicDiveLineSearch(*cbcModel);\n");
     43    CbcHeuristic::generateCpp(fp, "heuristicDiveLineSearch");
     44    fprintf(fp, "3  cbcModel->addHeuristic(&heuristicDiveLineSearch);\n");
    4545}
    4646
    47 // Copy constructor 
     47// Copy constructor
    4848CbcHeuristicDiveLineSearch::CbcHeuristicDiveLineSearch(const CbcHeuristicDiveLineSearch & rhs)
    49 :
    50   CbcHeuristicDive(rhs)
     49        :
     50        CbcHeuristicDive(rhs)
    5151{
    5252}
    5353
    54 // Assignment operator 
    55 CbcHeuristicDiveLineSearch & 
    56 CbcHeuristicDiveLineSearch::operator=( const CbcHeuristicDiveLineSearch& rhs)
     54// Assignment operator
     55CbcHeuristicDiveLineSearch &
     56CbcHeuristicDiveLineSearch::operator=( const CbcHeuristicDiveLineSearch & 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
    6565CbcHeuristicDiveLineSearch::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   // get the LP relaxation solution at the root node
    75   double * rootNodeLPSol = model_->continuousSolution();
     74    // get the LP relaxation solution at the root node
     75    double * rootNodeLPSol = model_->continuousSolution();
    7676
    77   bestColumn = -1;
    78   bestRound = -1; // -1 rounds down, +1 rounds up
    79   double bestRelDistance = DBL_MAX;
    80   bool allTriviallyRoundableSoFar = true;
    81   for (int i=0; i<numberIntegers; i++) {
    82     int iColumn = integerVariable[i];
    83     double rootValue=rootNodeLPSol[iColumn];
    84     double value=newSolution[iColumn];
    85     double fraction=value-floor(value);
    86     int round = 0;
    87     if (fabs(floor(value+0.5)-value)>integerTolerance) {
    88       if (allTriviallyRoundableSoFar||(downLocks_[i]>0&&upLocks_[i]>0)) {
     77    bestColumn = -1;
     78    bestRound = -1; // -1 rounds down, +1 rounds up
     79    double bestRelDistance = DBL_MAX;
     80    bool allTriviallyRoundableSoFar = true;
     81    for (int i = 0; i < numberIntegers; i++) {
     82        int iColumn = integerVariable[i];
     83        double rootValue = rootNodeLPSol[iColumn];
     84        double value = newSolution[iColumn];
     85        double fraction = value - floor(value);
     86        int round = 0;
     87        if (fabs(floor(value + 0.5) - value) > integerTolerance) {
     88            if (allTriviallyRoundableSoFar || (downLocks_[i] > 0 && upLocks_[i] > 0)) {
    8989
    90         if (allTriviallyRoundableSoFar&&downLocks_[i]>0&&upLocks_[i]>0) {
    91           allTriviallyRoundableSoFar = false;
    92           bestRelDistance = DBL_MAX;
    93         }
     90                if (allTriviallyRoundableSoFar && downLocks_[i] > 0 && upLocks_[i] > 0) {
     91                    allTriviallyRoundableSoFar = false;
     92                    bestRelDistance = DBL_MAX;
     93                }
    9494
    95         double relDistance;
    96         if(value < rootValue) {
    97           round = -1;
    98           relDistance = fraction / (rootValue - value);
    99         }
    100         else if(value > rootValue) {
    101           round = 1;
    102           relDistance = (1.0 - fraction) / (value - rootValue);
    103         }
    104         else {
    105           round = -1;
    106           relDistance = DBL_MAX;
    107         }
    108          
    109         // if variable is not binary, penalize it
    110         if(!solver->isBinary(iColumn))
    111           relDistance *= 1000.0;
    112        
    113         if(relDistance < bestRelDistance) {
    114           bestColumn = iColumn;
    115           bestRelDistance = relDistance;
    116           bestRound = round;
    117         }
    118       }
     95                double relDistance;
     96                if (value < rootValue) {
     97                    round = -1;
     98                    relDistance = fraction / (rootValue - value);
     99                } else if (value > rootValue) {
     100                    round = 1;
     101                    relDistance = (1.0 - fraction) / (value - rootValue);
     102                } else {
     103                    round = -1;
     104                    relDistance = DBL_MAX;
     105                }
     106
     107                // if variable is not binary, penalize it
     108                if (!solver->isBinary(iColumn))
     109                    relDistance *= 1000.0;
     110
     111                if (relDistance < bestRelDistance) {
     112                    bestColumn = iColumn;
     113                    bestRelDistance = relDistance;
     114                    bestRound = round;
     115                }
     116            }
     117        }
    119118    }
    120   }
    121   return allTriviallyRoundableSoFar;
     119    return allTriviallyRoundableSoFar;
    122120}
Note: See TracChangeset for help on using the changeset viewer.