Ignore:
Timestamp:
Aug 31, 2010 7:14:51 AM (9 years ago)
Author:
forrest
Message:

a few more rens heuristics

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcHeuristicRENS.cpp

    r1432 r1499  
    1313#include "CbcMessage.hpp"
    1414#include "CbcHeuristicRENS.hpp"
     15#include "CoinWarmStartBasis.hpp"
    1516#include "CbcBranchActual.hpp"
    1617#include "CbcStrategy.hpp"
     
    2223{
    2324    numberTries_ = 0;
     25    rensType_ = 0;
    2426    whereFrom_ = 256 + 1;
    2527}
     
    3133{
    3234    numberTries_ = 0;
     35    rensType_ = 0;
    3336    whereFrom_ = 256 + 1;
    3437}
     
    5356        CbcHeuristic::operator=(rhs);
    5457        numberTries_ = rhs.numberTries_;
     58        rensType_ = rhs.rensType_;
    5559    }
    5660    return *this;
     
    6165        :
    6266        CbcHeuristic(rhs),
    63         numberTries_(rhs.numberTries_)
     67        numberTries_(rhs.numberTries_),
     68        rensType_(rhs.rensType_)
    6469{
    6570}
     
    7580    int returnCode = 0;
    7681    const double * bestSolution = model_->bestSolution();
    77     if (numberTries_ || (when() < 2 && bestSolution))
     82    if ((numberTries_&&(rensType_&16)==0) || numberTries_>1 || (when() < 2 && bestSolution))
    7883        return 0;
    7984    numberTries_++;
     
    8489
    8590    const double * currentSolution = solver->getColSolution();
     91    const double * dj = solver->getReducedCost();
    8692    OsiSolverInterface * newSolver = cloneBut(3); // was model_->continuousSolver()->clone();
     93    int numberColumns = newSolver->getNumCols();
     94    double direction = newSolver->getObjSense();
     95    int type = rensType_&15;
     96    double djTolerance = (type!=1) ? -1.0e30 : 1.0e-4;
    8797    const double * colLower = newSolver->getColLower();
    8898    const double * colUpper = newSolver->getColUpper();
     99    if ((type&3)==3) {
     100        double total=0.0;
     101        int n=0;
     102        CoinWarmStartBasis * basis =
     103          dynamic_cast<CoinWarmStartBasis *>(solver->getWarmStart()) ;
     104        if (basis) {
     105            for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
     106              if (colUpper[iColumn]>colLower[iColumn]&&
     107                  basis->getStructStatus(iColumn) !=
     108                  CoinWarmStartBasis::basic) {
     109                  n++;
     110                  total += fabs(dj[iColumn]);
     111              }
     112            }
     113            if (n)
     114                djTolerance = (0.01*total)/static_cast<double>(n);
     115            delete basis;
     116        }
     117    }
    89118
    90119    double primalTolerance;
     
    95124    int numberTightened = 0;
    96125    int numberAtBound = 0;
    97     int numberColumns = newSolver->getNumCols();
    98126    int numberContinuous = numberColumns - numberIntegers;
    99127
     
    105133        value = CoinMax(value, lower);
    106134        value = CoinMin(value, upper);
     135        double djValue=dj[iColumn]*direction;
    107136#define RENS_FIX_ONLY_LOWER
    108137#ifndef RENS_FIX_ONLY_LOWER
     
    121150#else
    122151        if (fabs(value - floor(value + 0.5)) < 1.0e-8 &&
    123                 floor(value + 0.5) == lower) {
    124             value = floor(value + 0.5);
    125             numberAtBound++;
    126             newSolver->setColLower(iColumn, value);
    127             newSolver->setColUpper(iColumn, value);
    128             numberFixed++;
    129         } else if (colUpper[iColumn] - colLower[iColumn] >= 2.0) {
     152                floor(value + 0.5) == lower &&
     153            djValue > djTolerance ) {
     154          value = floor(value + 0.5);
     155          numberAtBound++;
     156          newSolver->setColLower(iColumn, value);
     157          newSolver->setColUpper(iColumn, value);
     158          numberFixed++;
     159        } else if (fabs(value - floor(value + 0.5)) < 1.0e-8 &&
     160                floor(value + 0.5) == upper &&
     161                   -djValue > djTolerance && (djTolerance > 0.0||type==2)) {
     162          value = floor(value + 0.5);
     163          numberAtBound++;
     164          newSolver->setColLower(iColumn, value);
     165          newSolver->setColUpper(iColumn, value);
     166          numberFixed++;
     167        } else if (colUpper[iColumn] - colLower[iColumn] >= 2.0 &&
     168                   djTolerance <0.0) {
    130169            numberTightened++;
    131170            if (fabs(value - floor(value + 0.5)) < 1.0e-8) {
     
    145184    }
    146185    if (numberFixed > numberIntegers / 5) {
    147         if (numberContinuous > numberIntegers && numberFixed < numberColumns / 5) {
     186        if ( numberFixed < numberColumns / 5) {
    148187#define RENS_FIX_CONTINUOUS
    149188#ifdef RENS_FIX_CONTINUOUS
     
    153192            double sumDj = 0.0;
    154193            const double * dj = newSolver->getReducedCost();
    155             double direction = newSolver->getObjSense();
    156194            for (int iColumn = 0; iColumn < numberColumns; iColumn++) {
    157195                if (!newSolver->isInteger(iColumn)) {
Note: See TracChangeset for help on using the changeset viewer.