source: trunk/Bonmin/src/CbcBonmin/BonminCbcNode.cpp @ 1

Last change on this file since 1 was 1, checked in by andreasw, 13 years ago

imported initial code

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 4.3 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
12#if defined(_MSC_VER)
13// Turn off compiler warning about long names
14#  pragma warning(disable:4786)
15#endif
16#include <string>
17#include <cassert>
18#include <cfloat>
19#include "OsiSolverInterface.hpp"
20#include "CoinWarmStartBasis.hpp"
21#include "CbcModel.hpp"
22#include "BonminCbcNode.hpp"
23#include "IpoptInterface.hpp"
24#include "IpoptWarmStart.hpp"
25
26using namespace std;
27
28//Default constructor
29BonminCbcFullNodeInfo::BonminCbcFullNodeInfo()
30    :
31    CbcFullNodeInfo(),
32    sequenceOfInfeasiblesSize_(0),
33    sequenceOfUnsolvedSize_(0)
34{}
35
36BonminCbcFullNodeInfo::BonminCbcFullNodeInfo(CbcModel * model,
37    int numberRowsAtContinuous) :
38    CbcFullNodeInfo(model, numberRowsAtContinuous),
39    sequenceOfInfeasiblesSize_(0),
40    sequenceOfUnsolvedSize_(0)
41{
42}
43
44// Copy constructor
45BonminCbcFullNodeInfo::BonminCbcFullNodeInfo ( const BonminCbcFullNodeInfo &other):
46    CbcFullNodeInfo(other),
47    sequenceOfInfeasiblesSize_(other.sequenceOfInfeasiblesSize_),
48    sequenceOfUnsolvedSize_(other.sequenceOfUnsolvedSize_)
49
50{}
51
52
53void
54BonminCbcFullNodeInfo::allBranchesGone()
55{
56  IpoptWarmStart * ipws = dynamic_cast<IpoptWarmStart *>(basis_);
57  if(ipws)
58    ipws->flushPoint();
59}
60
61BonminCbcFullNodeInfo::~BonminCbcFullNodeInfo()
62{}
63
64CbcNodeInfo *
65BonminCbcFullNodeInfo::clone() const
66{
67  return new BonminCbcFullNodeInfo(*this);
68}
69/****************************************************************************************************/
70
71// Default constructor
72BonminCbcPartialNodeInfo::BonminCbcPartialNodeInfo ()
73    : CbcPartialNodeInfo(),
74    sequenceOfInfeasiblesSize_(0),
75    sequenceOfUnsolvedSize_(0)
76{
77}
78// Constructor from current state
79BonminCbcPartialNodeInfo::BonminCbcPartialNodeInfo (CbcModel * model,CbcNodeInfo *parent, CbcNode *owner,
80    int numberChangedBounds,
81    const int *variables,
82    const double *boundChanges,
83    const CoinWarmStartDiff *basisDiff)
84    : CbcPartialNodeInfo(parent,owner,numberChangedBounds,variables,
85        boundChanges,basisDiff),
86    sequenceOfInfeasiblesSize_(0),
87    sequenceOfUnsolvedSize_(0)
88{
89  IpoptInterface * ipopt = dynamic_cast<IpoptInterface *>(model->solver());
90  assert (ipopt);
91  Ipopt::ApplicationReturnStatus optimization_status
92  = ipopt->getOptStatus();
93  BonminCbcPartialNodeInfo * nlpParent = dynamic_cast<BonminCbcPartialNodeInfo *> (parent);
94  int numberInfeasible = 0;
95  int numberUnsolved = 0;
96  if(nlpParent)//father is not root
97  {
98    numberInfeasible = nlpParent->getSequenceOfInfeasiblesSize();
99    numberUnsolved =  nlpParent->getSequenceOfUnsolvedSize();
100//       if(!nlpParent->numberBranchesLeft_){
101//      IpoptWarmStartDiff * ipws = dynamic_cast<IpoptWarmStartDiff *>(nlpParent->basisDiff_);
102//      ipws->flushPoint();
103//       }
104  }
105  else {
106    BonminCbcFullNodeInfo * nlpRoot = dynamic_cast<BonminCbcFullNodeInfo *> (parent);
107    if(nlpRoot) {
108      numberInfeasible = nlpRoot->getSequenceOfInfeasiblesSize();
109      numberUnsolved =  nlpRoot->getSequenceOfUnsolvedSize();
110    }
111  }
112  if((optimization_status==Ipopt::Unrecoverable_Exception)||
113      (optimization_status==Ipopt::NonIpopt_Exception_Thrown)||
114      (optimization_status==Ipopt::Insufficient_Memory)||
115      (optimization_status==Ipopt::Restoration_Failed)||
116      (optimization_status==Ipopt::Internal_Error)||
117      (optimization_status==Ipopt::Maximum_Iterations_Exceeded))
118    sequenceOfUnsolvedSize_ = numberUnsolved + 1;
119
120  if(optimization_status==Ipopt::Infeasible_Problem_Detected)
121    sequenceOfInfeasiblesSize_ = numberInfeasible + 1;
122}
123
124BonminCbcPartialNodeInfo::BonminCbcPartialNodeInfo (const BonminCbcPartialNodeInfo & rhs)
125
126    : CbcPartialNodeInfo(rhs),
127    sequenceOfInfeasiblesSize_(rhs.sequenceOfInfeasiblesSize_),
128    sequenceOfUnsolvedSize_(rhs.sequenceOfUnsolvedSize_)
129
130{}
131
132CbcNodeInfo *
133BonminCbcPartialNodeInfo::clone() const
134{
135  return (new BonminCbcPartialNodeInfo(*this));
136}
137
138void
139BonminCbcPartialNodeInfo::allBranchesGone()
140{
141  IpoptWarmStartDiff * ipws = dynamic_cast<IpoptWarmStartDiff *>(basisDiff_);
142  if(ipws)
143    ipws->flushPoint();
144}
145
146BonminCbcPartialNodeInfo::~BonminCbcPartialNodeInfo ()
147{}
Note: See TracBrowser for help on using the repository browser.