source: branches/devel/Bonmin/src/CbcBonmin/BonCbcNode.cpp @ 62

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

astyled the devel branch

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