source: branches/devel/Bonmin/src/CbcBonmin/BonCbcNlpStrategy.cpp @ 58

Last change on this file since 58 was 58, checked in by pbonami, 13 years ago

Finish renaming

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 4.5 KB
Line 
1// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// John J. Forrest, International Business Machines Corporation
7// P. Bonami, Carnegie Mellon University,
8//
9// Date : 03/15/2006
10
11#if defined(_MSC_VER)
12// Turn off compiler warning about long names
13#  pragma warning(disable:4786)
14#endif
15#include <cassert>
16#include <cmath>
17#include <cfloat>
18
19#include "OsiSolverInterface.hpp"
20#include "CbcModel.hpp"
21#include "BonCbcNlpStrategy.hpp"
22#include "BonCbcNode.hpp"
23
24#include "BonOsiTMINLPInterface.hpp"
25namespace Bonmin{
26// Default Constructor
27CbcNlpStrategy::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}
38
39
40// Destructor
41CbcNlpStrategy::~CbcNlpStrategy ()
42{}
43
44// Clone
45CbcStrategy *
46CbcNlpStrategy::clone() const
47{
48  return new CbcNlpStrategy(*this);
49}
50
51// Copy constructor
52CbcNlpStrategy::CbcNlpStrategy(const CbcNlpStrategy & rhs)
53    :
54    hasFailed_(false),
55    maxFailure_(rhs.maxFailure_),
56    maxInfeasible_(rhs.maxInfeasible_),
57    pretendFailIsInfeasible_(rhs.pretendFailIsInfeasible_)
58{}
59// Return a new Full node information pointer (descendant of CbcFullNodeInfo)
60CbcNodeInfo *
61CbcNlpStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
62{
63  return new CbcFullNodeInfo(model,numberRowsAtContinuous);
64}
65// Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
66CbcNodeInfo *
67CbcNlpStrategy::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*/
81int
82CbcNlpStrategy::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;
90
91  int seqOfInfeasiblesSize = bmNodeInfo->getSequenceOfInfeasiblesSize();
92  int seqOfUnsolvedSize = bmNodeInfo->getSequenceOfUnsolvedSize();
93
94
95  if(solver->isAbandoned()) {
96    solved = false;
97    seqOfUnsolvedSize++;
98    ;
99  }
100  else if(solver->isProvenPrimalInfeasible()) {
101    feasible = 0;
102    seqOfInfeasiblesSize++;
103  }
104
105  if((seqOfUnsolvedSize==0) || (maxFailure_ == 0) &&
106      (maxInfeasible_== 0) || (seqOfInfeasiblesSize==0))
107
108    if(feasible && seqOfInfeasiblesSize > 1) {
109      std::cerr<<"Feasible node while father was infeasible."
110      <<std::endl;
111    }
112
113  if(solved && seqOfUnsolvedSize > 1) {
114    std::cerr<<"Solved node while father was unsolved."
115    <<std::endl;
116  }
117
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
155void
156CbcNlpStrategy::setupCutGenerators(CbcModel &model)
157{}
158
159void
160CbcNlpStrategy::setupHeuristics(CbcModel &model)
161{}
162
163void
164CbcNlpStrategy::setupPrinting(CbcModel &model, int toto)
165{}
166
167void
168CbcNlpStrategy::setupOther(CbcModel &model)
169{}
170}
Note: See TracBrowser for help on using the repository browser.