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

    r1271 r1286  
    1111
    1212// Default Constructor
    13 CbcHeuristicDiveVectorLength::CbcHeuristicDiveVectorLength() 
    14   :CbcHeuristicDive()
     13CbcHeuristicDiveVectorLength::CbcHeuristicDiveVectorLength()
     14        : CbcHeuristicDive()
    1515{
    1616}
     
    1818// Constructor from model
    1919CbcHeuristicDiveVectorLength::CbcHeuristicDiveVectorLength(CbcModel & model)
    20   :CbcHeuristicDive(model)
     20        : CbcHeuristicDive(model)
    2121{
    2222}
    2323
    24 // Destructor 
     24// Destructor
    2525CbcHeuristicDiveVectorLength::~CbcHeuristicDiveVectorLength ()
    2626{
     
    3131CbcHeuristicDiveVectorLength::clone() const
    3232{
    33   return new CbcHeuristicDiveVectorLength(*this);
     33    return new CbcHeuristicDiveVectorLength(*this);
    3434}
    3535
    3636// Create C++ lines to get to current state
    37 void 
    38 CbcHeuristicDiveVectorLength::generateCpp( FILE * fp) 
     37void
     38CbcHeuristicDiveVectorLength::generateCpp( FILE * fp)
    3939{
    40   CbcHeuristicDiveVectorLength other;
    41   fprintf(fp,"0#include \"CbcHeuristicDiveVectorLength.hpp\"\n");
    42   fprintf(fp,"3  CbcHeuristicDiveVectorLength heuristicDiveVectorLength(*cbcModel);\n");
    43   CbcHeuristic::generateCpp(fp,"heuristicDiveVectorLength");
    44   fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveVectorLength);\n");
     40    CbcHeuristicDiveVectorLength other;
     41    fprintf(fp, "0#include \"CbcHeuristicDiveVectorLength.hpp\"\n");
     42    fprintf(fp, "3  CbcHeuristicDiveVectorLength heuristicDiveVectorLength(*cbcModel);\n");
     43    CbcHeuristic::generateCpp(fp, "heuristicDiveVectorLength");
     44    fprintf(fp, "3  cbcModel->addHeuristic(&heuristicDiveVectorLength);\n");
    4545}
    4646
    47 // Copy constructor 
     47// Copy constructor
    4848CbcHeuristicDiveVectorLength::CbcHeuristicDiveVectorLength(const CbcHeuristicDiveVectorLength & rhs)
    49 :
    50   CbcHeuristicDive(rhs)
     49        :
     50        CbcHeuristicDive(rhs)
    5151{
    5252}
    5353
    54 // Assignment operator 
    55 CbcHeuristicDiveVectorLength & 
    56 CbcHeuristicDiveVectorLength::operator=( const CbcHeuristicDiveVectorLength& rhs)
     54// Assignment operator
     55CbcHeuristicDiveVectorLength &
     56CbcHeuristicDiveVectorLength::operator=( const CbcHeuristicDiveVectorLength & 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
    6565CbcHeuristicDiveVectorLength::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   const double * objective = solver->getObjCoefficients();
    71   double direction = solver->getObjSense(); // 1 for min, -1 for max
     70    const double * objective = solver->getObjCoefficients();
     71    double direction = solver->getObjSense(); // 1 for min, -1 for max
    7272
    73   const int * columnLength = matrix_.getVectorLengths();
    74   int numberIntegers = model_->numberIntegers();
    75   const int * integerVariable = model_->integerVariable();
    76   double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
     73    const int * columnLength = matrix_.getVectorLengths();
     74    int numberIntegers = model_->numberIntegers();
     75    const int * integerVariable = model_->integerVariable();
     76    double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
    7777
    78   bestColumn = -1;
    79   bestRound = -1; // -1 rounds down, +1 rounds up
    80   double bestScore = DBL_MAX;
    81   bool allTriviallyRoundableSoFar = true;
    82   for (int i=0; i<numberIntegers; i++) {
    83     int iColumn = integerVariable[i];
    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)) {
     78    bestColumn = -1;
     79    bestRound = -1; // -1 rounds down, +1 rounds up
     80    double bestScore = DBL_MAX;
     81    bool allTriviallyRoundableSoFar = true;
     82    for (int i = 0; i < numberIntegers; i++) {
     83        int iColumn = integerVariable[i];
     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           bestScore = DBL_MAX;
    93         }
     90                if (allTriviallyRoundableSoFar && downLocks_[i] > 0 && upLocks_[i] > 0) {
     91                    allTriviallyRoundableSoFar = false;
     92                    bestScore = DBL_MAX;
     93                }
    9494
    95         // the variable cannot be rounded
    96         double obj = direction * objective[iColumn];
    97         if(obj >= 0.0)
    98           round = 1; // round up
    99         else
    100           round = -1; // round down
    101         double objDelta;
    102         if(round == 1)
    103           objDelta = (1.0 - fraction) * obj;
    104         else
    105           objDelta = - fraction * obj;
    106        
    107         // we want the smaller score
    108         double score = objDelta / (static_cast<double> (columnLength[iColumn]) + 1.0);
     95                // the variable cannot be rounded
     96                double obj = direction * objective[iColumn];
     97                if (obj >= 0.0)
     98                    round = 1; // round up
     99                else
     100                    round = -1; // round down
     101                double objDelta;
     102                if (round == 1)
     103                    objDelta = (1.0 - fraction) * obj;
     104                else
     105                    objDelta = - fraction * obj;
    109106
    110         // if variable is not binary, penalize it
    111         if(!solver->isBinary(iColumn))
    112           score *= 1000.0;
     107                // we want the smaller score
     108                double score = objDelta / (static_cast<double> (columnLength[iColumn]) + 1.0);
    113109
    114         if(score < bestScore) {
    115           bestColumn = iColumn;
    116           bestScore = score;
    117           bestRound = round;
    118         }
    119       }
     110                // if variable is not binary, penalize it
     111                if (!solver->isBinary(iColumn))
     112                    score *= 1000.0;
     113
     114                if (score < bestScore) {
     115                    bestColumn = iColumn;
     116                    bestScore = score;
     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.