BonCurvBranchingSolver.cpp
Go to the documentation of this file.
1 // Copyright (C) 2006, 2007 International Business Machines
2 // Corporation and others. All Rights Reserved.
3 
4 #include "CoinPragma.hpp"
6 
7 namespace Bonmin
8 {
9 
11  StrongBranchingSolver(solver),
12  orig_d_(NULL),
13  projected_d_(NULL),
14  x_l_orig_(NULL),
15  x_u_orig_(NULL),
16  g_l_orig_(NULL),
17  g_u_orig_(NULL),
18  solution_(NULL),
19  duals_(NULL)
20  {}
21 
24  orig_d_(NULL),
25  projected_d_(NULL),
26  x_l_orig_(NULL),
27  x_u_orig_(NULL),
28  g_l_orig_(NULL),
29  g_u_orig_(NULL),
30  solution_(NULL),
31  duals_(NULL)
32  {}
33 
36  {
37  assert(!x_l_orig_);
38  if (this != &rhs) {
40  }
41  return *this;
42  }
43 
45  {
46  delete [] orig_d_;
47  delete [] projected_d_;
48  delete [] x_l_orig_;
49  delete [] x_u_orig_;
50  delete [] g_l_orig_;
51  delete [] g_u_orig_;
52  delete [] solution_;
53  delete [] duals_;
54  }
55 
58  {
59  if (IsNull(cur_estimator_)) {
60  // Get a curvature estimator
62  tminlp_interface->problem());
63  }
64 
65  new_bounds_ = true;
66  new_x_ = true;
67  new_mults_ = true;
68 
69  delete [] solution_;
70  delete [] duals_;
71  solution_ = NULL;
72  duals_ = NULL;
73 
74  numCols_ = tminlp_interface->getNumCols();
75  numRows_ = tminlp_interface->getNumRows();
76  solution_ = CoinCopyOfArray(tminlp_interface->problem()->x_sol(), numCols_);
77  duals_ = CoinCopyOfArray(tminlp_interface->problem()->duals_sol(),
78  numRows_ + 2*numCols_);
79  obj_value_ = tminlp_interface->problem()->obj_value();
80 
81  delete [] orig_d_;
82  delete [] projected_d_;
83  orig_d_ = NULL;
84  projected_d_ = NULL;
85  orig_d_ = new double[numCols_];
86  projected_d_ = new double[numCols_];
87 
88  // Get a copy of the current bounds
89  delete [] x_l_orig_;
90  delete [] x_u_orig_;
91  delete [] g_l_orig_;
92  delete [] g_u_orig_;
93  x_l_orig_ = NULL;
94  x_u_orig_ = NULL;
95  g_l_orig_ = NULL;
96  g_u_orig_ = NULL;
97  x_l_orig_ = new Number[numCols_];
98  x_u_orig_ = new Number[numCols_];
99  g_l_orig_ = new Number[numRows_];
100  g_u_orig_ = new Number[numRows_];
101 
102 #ifndef NDEBUG
103  bool retval =
104 #endif
105  tminlp_interface->problem()->
106  get_bounds_info(numCols_, x_l_orig_, x_u_orig_,
108  assert(retval);
109  }
110 
113  {
114  // Free memory
115  delete [] solution_;
116  delete [] duals_;
117  solution_ = NULL;
118  duals_ = NULL;
119  delete [] orig_d_;
120  delete [] projected_d_;
121  orig_d_ = NULL;
122  projected_d_ = NULL;
123  delete [] x_l_orig_;
124  delete [] x_u_orig_;
125  delete [] g_l_orig_;
126  delete [] g_u_orig_;
127  x_l_orig_ = NULL;
128  x_u_orig_ = NULL;
129  g_l_orig_ = NULL;
130  g_u_orig_ = NULL;
131  }
132 
135  {
136  // return iteration limit reached as status, so that it is
137  // clear we don't have a feasible point
139 
140  const double* z_L = duals_;
141  const double* z_U = z_L + numCols_;
142  const double* lam = z_U + numCols_;
143 
144  // get the current points
145  const double* b_L = tminlp_interface->getColLower();
146  const double* b_U = tminlp_interface->getColUpper();
147 
148  // Compute the step from the current point to the solution
149  // ToDo: If we know what changes, we can be more efficient
150  for (int i=0; i<numCols_; i++) {
151  if (b_L[i]>solution_[i]) {
152  orig_d_[i] = solution_[i]-b_L[i];
153  }
154  else if (b_U[i]<solution_[i]) {
155  orig_d_[i] = solution_[i]-b_U[i];
156  }
157  else {
158  orig_d_[i] = 0.;
159  }
160  }
161 
162  double gradLagTd;
163  double dTHLagd;
164  bool retval =
165  cur_estimator_->ComputeNullSpaceCurvature(
166  numCols_, solution_, new_x_, x_l_orig_, x_u_orig_,
167  g_l_orig_, g_u_orig_, new_bounds_, z_L, z_U,
169  gradLagTd, dTHLagd);
170 
171  if (!retval) {
172  retstatus = TNLPSolver::computationError;
173  }
174  else {
175  new_bounds_ = false;
176  new_x_ = false;
177  new_mults_ = false;
178  const double alpha = 1.0; // Think about this
179  double new_obj_value = obj_value_ +
180  alpha*gradLagTd + 0.5*alpha*alpha*dTHLagd;
181  tminlp_interface->problem()->set_obj_value(new_obj_value);
182  }
183 
184  return retstatus;
185  }
186 
187 
188 }
This class is the base class for a solver that can be used in BonOsiSolverInterface to perform the st...
virtual void markHotStart(OsiTMINLPInterface *tminlp_interface)
Called to initialize solver before a bunch of strong branching solves.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
const TMINLP2TNLP * problem() const
get pointer to the TMINLP2TNLP adapter
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
CurvBranchingSolver()
Default Constructor.
void set_obj_value(Ipopt::Number value)
Manually set objective value.
virtual int getNumRows() const
Get number of rows.
const Ipopt::Number * duals_sol() const
get the dual values
Ipopt::SmartPtr< Ipopt::Journalist > & Jnlst()
virtual int getNumCols() const
Get number of columns.
real alpha
virtual TNLPSolver::ReturnStatus solveFromHotStart(OsiTMINLPInterface *tminlp_interface)
Called to solve the current TMINLP (with changed bound information)
Ipopt::Number obj_value() const
Get the objective value.
bool IsNull(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:471
ReturnStatus
Standard return statuses for a solver.
StrongBranchingSolver & operator=(const StrongBranchingSolver &rhs)
Assignment operator.
CurvBranchingSolver & operator=(const CurvBranchingSolver &rhs)
Assignment operator.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real * lam
const Ipopt::Number * x_sol() const
get the solution values
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
SmartPtr< CurvatureEstimator > cur_estimator_
virtual ~CurvBranchingSolver()
Destructor.
virtual void unmarkHotStart(OsiTMINLPInterface *tminlp_interface)
Called after all strong branching solves in a node.
Implementation of BonChooseVariable for curvature-based braching.
Ipopt::SmartPtr< Ipopt::OptionsList > & Options()