Ignore:
Timestamp:
Sep 29, 2006 4:48:36 PM (13 years ago)
Author:
pbonami
Message:

astyled the devel branch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Bonmin/src/CbcBonmin/BonCbcNlpStrategy.cpp

    r58 r62  
    2323
    2424#include "BonOsiTMINLPInterface.hpp"
    25 namespace Bonmin{
     25namespace Bonmin
     26{
    2627// Default Constructor
    27 CbcNlpStrategy::CbcNlpStrategy(int maxFailures,
    28     int maxInfeasibles,
    29     int pretendFailIsInfeasible)
    30     :
    31     hasFailed_(false),
    32     maxFailure_(maxFailures),
    33     maxInfeasible_(maxInfeasibles),
    34     pretendFailIsInfeasible_(pretendFailIsInfeasible)
    35 {
    36   setPreProcessState(0);
    37 }
     28  CbcNlpStrategy::CbcNlpStrategy(int maxFailures,
     29      int maxInfeasibles,
     30      int pretendFailIsInfeasible)
     31      :
     32      hasFailed_(false),
     33      maxFailure_(maxFailures),
     34      maxInfeasible_(maxInfeasibles),
     35      pretendFailIsInfeasible_(pretendFailIsInfeasible)
     36  {
     37    setPreProcessState(0);
     38  }
    3839
    3940
    4041// Destructor
    41 CbcNlpStrategy::~CbcNlpStrategy ()
    42 {}
     42  CbcNlpStrategy::~CbcNlpStrategy ()
     43  {}
    4344
    4445// Clone
    45 CbcStrategy *
    46 CbcNlpStrategy::clone() const
    47 {
    48   return new CbcNlpStrategy(*this);
    49 }
     46  CbcStrategy *
     47  CbcNlpStrategy::clone() const
     48  {
     49    return new CbcNlpStrategy(*this);
     50  }
    5051
    5152// Copy constructor
    52 CbcNlpStrategy::CbcNlpStrategy(const CbcNlpStrategy & rhs)
    53     :
    54     hasFailed_(false),
    55     maxFailure_(rhs.maxFailure_),
    56     maxInfeasible_(rhs.maxInfeasible_),
    57     pretendFailIsInfeasible_(rhs.pretendFailIsInfeasible_)
    58 {}
     53  CbcNlpStrategy::CbcNlpStrategy(const CbcNlpStrategy & rhs)
     54      :
     55      hasFailed_(false),
     56      maxFailure_(rhs.maxFailure_),
     57      maxInfeasible_(rhs.maxInfeasible_),
     58      pretendFailIsInfeasible_(rhs.pretendFailIsInfeasible_)
     59  {}
    5960// Return a new Full node information pointer (descendant of CbcFullNodeInfo)
    60 CbcNodeInfo *
    61 CbcNlpStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
    62 {
    63   return new CbcFullNodeInfo(model,numberRowsAtContinuous);
    64 }
     61  CbcNodeInfo *
     62  CbcNlpStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
     63  {
     64    return new CbcFullNodeInfo(model,numberRowsAtContinuous);
     65  }
    6566// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
    66 CbcNodeInfo *
    67 CbcNlpStrategy::partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
    68     int numberChangedBounds,const int * variables,
    69     const double * boundChanges,
    70     const CoinWarmStartDiff *basisDiff) const
    71 {
    72   return new BonCbcPartialNodeInfo(model,parent, owner, numberChangedBounds, variables,
    73       boundChanges,basisDiff);
    74 }
    75 /* After a CbcModel::resolve this can return a status
    76    -1 no effect
    77    0 treat as optimal
    78    1 as 0 but do not do any more resolves (i.e. no more cuts)
    79    2 treat as infeasible
    80 */
    81 int
    82 CbcNlpStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
    83 {
    84   OsiSolverInterface * solver = model->solver();//get solver
    85   int feasible = 1;
    86   bool solved = true;
    87   int returnStatus = -1;
    88   BonCbcPartialNodeInfo * bmNodeInfo = dynamic_cast<BonCbcPartialNodeInfo *>(parent);
    89   if(!bmNodeInfo) return -1;
     67  CbcNodeInfo *
     68  CbcNlpStrategy::partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
     69      int numberChangedBounds,const int * variables,
     70      const double * boundChanges,
     71      const CoinWarmStartDiff *basisDiff) const
     72  {
     73    return new BonCbcPartialNodeInfo(model,parent, owner, numberChangedBounds, variables,
     74        boundChanges,basisDiff);
     75  }
     76  /* After a CbcModel::resolve this can return a status
     77     -1 no effect
     78     0 treat as optimal
     79     1 as 0 but do not do any more resolves (i.e. no more cuts)
     80     2 treat as infeasible
     81  */
     82  int
     83  CbcNlpStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
     84  {
     85    OsiSolverInterface * solver = model->solver();//get solver
     86    int feasible = 1;
     87    bool solved = true;
     88    int returnStatus = -1;
     89    BonCbcPartialNodeInfo * bmNodeInfo = dynamic_cast<BonCbcPartialNodeInfo *>(parent);
     90    if (!bmNodeInfo) return -1;
    9091
    91   int seqOfInfeasiblesSize = bmNodeInfo->getSequenceOfInfeasiblesSize();
    92   int seqOfUnsolvedSize = bmNodeInfo->getSequenceOfUnsolvedSize();
     92    int seqOfInfeasiblesSize = bmNodeInfo->getSequenceOfInfeasiblesSize();
     93    int seqOfUnsolvedSize = bmNodeInfo->getSequenceOfUnsolvedSize();
    9394
    9495
    95   if(solver->isAbandoned()) {
    96     solved = false;
    97     seqOfUnsolvedSize++;
    98     ;
    99   }
    100   else if(solver->isProvenPrimalInfeasible()) {
    101     feasible = 0;
    102     seqOfInfeasiblesSize++;
    103   }
     96    if (solver->isAbandoned()) {
     97      solved = false;
     98      seqOfUnsolvedSize++;
     99      ;
     100    }
     101    else if (solver->isProvenPrimalInfeasible()) {
     102      feasible = 0;
     103      seqOfInfeasiblesSize++;
     104    }
    104105
    105   if((seqOfUnsolvedSize==0) || (maxFailure_ == 0) &&
    106       (maxInfeasible_== 0) || (seqOfInfeasiblesSize==0))
     106    if ((seqOfUnsolvedSize==0) || (maxFailure_ == 0) &&
     107        (maxInfeasible_== 0) || (seqOfInfeasiblesSize==0))
    107108
    108     if(feasible && seqOfInfeasiblesSize > 1) {
    109       std::cerr<<"Feasible node while father was infeasible."
     109      if (feasible && seqOfInfeasiblesSize > 1) {
     110        std::cerr<<"Feasible node while father was infeasible."
     111        <<std::endl;
     112      }
     113
     114    if (solved && seqOfUnsolvedSize > 1) {
     115      std::cerr<<"Solved node while father was unsolved."
    110116      <<std::endl;
    111117    }
    112118
    113   if(solved && seqOfUnsolvedSize > 1) {
    114     std::cerr<<"Solved node while father was unsolved."
    115     <<std::endl;
     119    if (seqOfInfeasiblesSize < maxInfeasible_ &&
     120        solved && !feasible) {
     121      std::cerr<<"Branching on infeasible node, sequence of infeasibles size "
     122      <<seqOfInfeasiblesSize<<std::endl;
     123      // Have to make sure that we will branch
     124      OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
     125      ipopt->forceBranchable();
     126      //change objective value
     127      returnStatus = 0;
     128
     129    }
     130
     131    if (!solved && parent != NULL &&
     132        seqOfUnsolvedSize <= maxFailure_) {
     133      std::cout<<"Branching on unsolved node, sequence of unsolved size "<<seqOfUnsolvedSize<<std::endl;
     134      // Have to make sure that we will branch
     135      OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
     136      ipopt->forceBranchable();     //      feasible=1;
     137      returnStatus = 0;
     138    }
     139
     140    if (solver->isAbandoned() && parent != NULL &&
     141        seqOfUnsolvedSize > maxFailure_) {
     142      hasFailed_ = true;
     143      OsiTMINLPInterface * ipopt =
     144        dynamic_cast<OsiTMINLPInterface *>(solver);
     145      if (pretendFailIsInfeasible_) {
     146        //force infeasible
     147        ipopt->forceInfeasible();
     148        returnStatus = 2;
     149      }
     150      else
     151        throw ipopt->newUnsolvedError(0);
     152    }
     153    return returnStatus;
    116154  }
    117155
    118   if(seqOfInfeasiblesSize < maxInfeasible_ &&
    119       solved && !feasible) {
    120     std::cerr<<"Branching on infeasible node, sequence of infeasibles size "
    121     <<seqOfInfeasiblesSize<<std::endl;
    122     // Have to make sure that we will branch
    123     OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
    124     ipopt->forceBranchable();
    125     //change objective value
    126     returnStatus = 0;
    127 
    128   }
    129 
    130   if(!solved && parent != NULL &&
    131       seqOfUnsolvedSize <= maxFailure_) {
    132     std::cout<<"Branching on unsolved node, sequence of unsolved size "<<seqOfUnsolvedSize<<std::endl;
    133     // Have to make sure that we will branch
    134     OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
    135     ipopt->forceBranchable();     //      feasible=1;
    136     returnStatus = 0;
    137   }
    138 
    139   if(solver->isAbandoned() && parent != NULL &&
    140       seqOfUnsolvedSize > maxFailure_) {
    141     hasFailed_ = true;
    142     OsiTMINLPInterface * ipopt =
    143       dynamic_cast<OsiTMINLPInterface *>(solver);
    144     if(pretendFailIsInfeasible_) {
    145       //force infeasible
    146       ipopt->forceInfeasible();
    147       returnStatus = 2;
    148     }
    149     else
    150       throw ipopt->newUnsolvedError(0);
    151   }
    152   return returnStatus;
    153 }
    154 
    155 void
    156 CbcNlpStrategy::setupCutGenerators(CbcModel &model)
     156  void
     157  CbcNlpStrategy::setupCutGenerators(CbcModel &model)
    157158{}
    158159
    159 void
    160 CbcNlpStrategy::setupHeuristics(CbcModel &model)
    161 {}
     160  void
     161  CbcNlpStrategy::setupHeuristics(CbcModel &model)
     162  {}
    162163
    163 void
    164 CbcNlpStrategy::setupPrinting(CbcModel &model, int toto)
    165 {}
     164  void
     165  CbcNlpStrategy::setupPrinting(CbcModel &model, int toto)
     166  {}
    166167
    167 void
    168 CbcNlpStrategy::setupOther(CbcModel &model)
    169 {}
     168  void
     169  CbcNlpStrategy::setupOther(CbcModel &model)
     170  {}
    170171}
Note: See TracChangeset for help on using the changeset viewer.