15 #include "IpAlgTypes.hpp"
16 #include "IpIpoptCalculatedQuantities.hpp"
22 #include "OsiBranchingObject.hpp"
24 using namespace Ipopt;
34 const OptionsList& options
54 index_style_(TNLP::FORTRAN_STYLE),
57 nlp_lower_bound_inf_(-DBL_MAX),
58 nlp_upper_bound_inf_(DBL_MAX),
59 warm_start_entire_iterate_(true),
60 need_new_warm_starter_(true)
70 ASSERT_EXCEPTION(retval, TMINLP_INVALID,
71 "get_nlp_info of TMINLP returns false.");
108 options.GetBoolValue(
"warm_start_entire_iterate",
128 tminlp_(other.tminlp_),
129 nnz_jac_g_(other.nnz_jac_g_),
130 nnz_h_lag_(other.nnz_h_lag_),
131 index_style_(other.index_style_),
132 return_status_(other.return_status_),
133 obj_value_(other.obj_value_),
134 curr_warm_starter_(other.curr_warm_starter_),
135 nlp_lower_bound_inf_(other.nlp_lower_bound_inf_),
136 nlp_upper_bound_inf_(other.nlp_upper_bound_inf_),
137 warm_start_entire_iterate_(other.warm_start_entire_iterate_),
138 need_new_warm_starter_(other.need_new_warm_starter_)
191 IpBlasDcopy(n, other.
x_l_(), 1,
x_l_(), 1);
192 IpBlasDcopy(n, other.
x_u_(), 1,
x_u_(), 1);
200 if(!other.
x_sol_.empty()) {
205 if(!other.
g_l_.empty()){
206 const size_t& size = other.
g_l_.size();
212 IpBlasDcopy(m, other.
g_l_(), 1,
g_l_(), 1);
213 IpBlasDcopy(m, other.
g_u_(), 1,
g_u_(), 1);
214 if(!other.
g_sol_.empty()) {
242 IpBlasDcopy(n, x_l, 1,
x_l_(), 1);
243 IpBlasDcopy(n, x_u, 1,
x_u_(), 1);
250 IpBlasDcopy(n, x_l, 1,
x_l_(), 1);
257 IpBlasDcopy(n, x_u, 1,
x_u_(), 1);
290 IpBlasDcopy(n, x_init, 1,
x_init_(), 1);
311 assert(n == (
int)
x_sol_.size());
312 IpBlasDcopy(n, x_sol, 1,
x_sol_(), 1);
334 Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style)
346 Index
m, Number* g_l, Number* g_u)
350 IpBlasDcopy(n,
x_l_(), 1, x_l, 1);
351 IpBlasDcopy(n,
x_u_(), 1, x_u, 1);
353 IpBlasDcopy(m,
g_l_(), 1, g_l, 1);
354 IpBlasDcopy(m,
g_u_(), 1, g_u, 1);
360 bool init_z, Number* z_L, Number* z_U,
361 Index
m,
bool init_lambda,
370 if (init_x ==
true) {
376 IpBlasDcopy(n,
x_init_(), 1, x, 1);
378 if (init_z ==
true) {
382 IpBlasDcopy(n, duals_init_, 1, z_L, 1);
383 IpBlasDcopy(n, duals_init_ + n, 1, z_U, 1);
386 if(init_lambda ==
true) {
391 IpBlasDcopy(m, duals_init_ + 2*n , 1, lambda, 1);
414 return tminlp_->eval_f(n, x, new_x, obj_value);
421 return tminlp_->eval_grad_f(n, x, new_x, grad_f);
427 int return_code =
tminlp_->eval_g(n, x, new_x, m, g);
432 Index
m, Index nele_jac, Index* iRow,
433 Index *jCol, Number*
values)
436 tminlp_->eval_jac_g(n, x, new_x, m, nele_jac,
440 for(Index
k = 0;
k < nele_jac ;
k++){
450 Number obj_factor, Index
m,
const Number* lambda,
451 bool new_lambda, Index nele_hess,
452 Index* iRow, Index* jCol, Number*
values)
454 return tminlp_->eval_h(n, x, new_x, obj_factor, m, lambda,
455 new_lambda, nele_hess,
463 return tminlp_->eval_gi(n, x, new_x, i, gi);
467 Index i, Index& nele_grad_gi, Index* jCol,
470 return tminlp_->eval_grad_gi(n, x, new_x, i, nele_grad_gi, jCol, values);
474 Index
n,
const Number*
x,
const Number* z_L,
const Number* z_U,
475 Index
m,
const Number*
g,
const Number* lambda,
477 const IpoptData* ip_data,
478 IpoptCalculatedQuantities* ip_cq)
484 IpBlasDcopy(n, x, 1,
x_sol_(), 1);
488 IpBlasDcopy(m, g, 1,
g_sol_(), 1);
493 IpBlasDcopy(m, lambda, 1,
duals_sol_() + 2*n, 1);
502 if(status == Ipopt::LOCAL_INFEASIBILITY && ip_cq != NULL){
503 obj_value_ = ip_cq->curr_nlp_constraint_violation(NORM_MAX);
512 Index iter, Number obj_value,
513 Number inf_pr, Number inf_du,
514 Number mu, Number d_norm,
515 Number regularization_size,
516 Number alpha_du, Number alpha_pr,
518 const IpoptData* ip_data,
519 IpoptCalculatedQuantities* ip_cq)
556 const double * currentLower =
x_l();
557 const double * currentUpper =
x_u();
559 const double * originalLower =
orig_x_l();
560 const double * originalUpper =
orig_x_u();
562 std::string fBoundsName = probName;
563 std::ostringstream os;
564 fBoundsName+=
".bounds";
565 std::string fModName = probName;
567 std::ofstream fBounds;
569 bool hasVarNames = 0;
574 fMod.open(fModName.c_str());
575 fBounds.open(fBoundsName.c_str());
577 for(
int i = 0 ; i < numcols ; i++) {
578 if(!eq(currentLower[i],originalLower[i])) {
580 fMod<<
"bounds"<<i<<
": "
581 <<varNames[i]<<
" >= "
582 <<currentLower[i]<<
";\n";
585 fBounds<<
"LO"<<
"\t"<<i<<
"\t"<<currentLower[i]<<std::endl;
587 if(!eq(currentUpper[i],originalUpper[i])) {
589 fMod<<
"bounds"<<i<<
": "
590 <<varNames[i]<<
" <= "
591 <<currentUpper[i]<<
";\n";
593 fBounds<<
"UP"<<
"\t"<<i<<
"\t"<<currentUpper[i]<<std::endl;
598 std::string fStartPointName=probName;
599 fStartPointName+=
".start";
601 std::ofstream fStartPoint(fStartPointName.c_str());
602 const double * primals =
x_init();
604 fStartPoint.precision(17);
605 fStartPoint<<numcols<<
"\t"<<2*numcols+numrows<<std::endl;
606 for(
int i = 0 ; i < numcols ; i++)
607 fStartPoint<<primals[i]<<std::endl;
608 int end = 2*numcols + numrows;
610 for(
int i = 0 ; i <
end; i++)
611 fStartPoint<<duals[i]<<std::endl;
632 bool& use_x_scaling, Index
n,
634 bool& use_g_scaling, Index
m,
637 return tminlp_->get_scaling_parameters(obj_scaling, use_x_scaling, n,
639 use_g_scaling, m, g_scaling);
672 for (
int i = 0 ; i < nObjects ; i++) {
673 OsiSimpleInteger * obj =
dynamic_cast<OsiSimpleInteger *
>(objects[i]);
675 int colNumber = obj->columnNumber();
681 for (
unsigned int i = 0; i <
x_sol_.size() ; i++) {
690 for(
unsigned int i = 0 ; i <
g_sol_.size() ; i++){
691 error = std::max(error, std::max(0.,
g_l_[i] -
g_sol_[i]));
692 error = std::max(error, std::max(0., -
g_u_[i] +
g_sol_[i]));
TNLP::IndexStyleEnum index_style_
index style (fortran or C)
void Set_dual_sol(Ipopt::Index n, const Ipopt::Number *dual_sol)
Set the contiuous dual solution.
void outputDiffs(const std::string &probName, const std::string *varNames)
Procedure to ouptut relevant informations to reproduce a sub-problem.
vector< Ipopt::Number > g_l_
Lower bounds on constraints values.
void SetVariableType(Ipopt::Index n, TMINLP::VariableType type)
Change the type of the variable.
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Return the hessian of the lagrangian.
vector< Ipopt::Number > x_init_
Initial primal point.
void resetStartingPoint()
reset the starting point to original one.
vector< Ipopt::Number > x_l_
Current lower bounds on variables.
const Ipopt::Number * x_init() const
get the starting primal point
void SetVariablesUpperBounds(Ipopt::Index n, const Ipopt::Number *x_u)
Change the upper bound on the variable.
void SetVariablesLowerBounds(Ipopt::Index n, const Ipopt::Number *x_l)
Change the lower bound on the variables.
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
This method is called when the algorithm is complete so the TNLP can store/write the solution...
virtual ~TMINLP2TNLP()
Default destructor.
virtual bool eval_grad_gi(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index i, Ipopt::Index &nele_grad_gi, Ipopt::Index *jCol, Ipopt::Number *values)
compute the structure or values of the gradient for one constraint
void Set_x_sol(Ipopt::Index n, const Ipopt::Number *x_sol)
Set the contiuous solution.
vector< Ipopt::Number > orig_x_u_
Original upper bounds on variables.
Ipopt::Number * duals_init_
Initial values for all dual multipliers (constraints then lower bounds then upper bounds) ...
virtual bool eval_gi(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index i, Ipopt::Number &gi)
compute the value of a single constraint
virtual bool get_scaling_parameters(Ipopt::Number &obj_scaling, bool &use_x_scaling, Ipopt::Index n, Ipopt::Number *x_scaling, bool &use_g_scaling, Ipopt::Index m, Ipopt::Number *g_scaling)
Method that returns scaling parameters.
bool IsValid(const OSSmartPtr< U > &smart_ptr)
vector< TMINLP::VariableType > var_types_
Types of the variable (TMINLP::CONTINUOUS, TMINLP::INTEGER, TMINLP::BINARY).
void SetVariableLowerBound(Ipopt::Index var_no, Ipopt::Number x_l)
Change the lower bound on the variable.
Ipopt::SmartPtr< IpoptInteriorWarmStarter > curr_warm_starter_
Pointer to object that holds warmstart information.
bool warm_start_entire_iterate_
Option from Ipopt - we currently use it to see if we want to use some clever warm start or just the l...
void force_fractionnal_sol()
force solution to be fractionnal.
vector< Ipopt::Number > x_sol_
Optimal solution.
TMINLP2TNLP & operator=(const TMINLP2TNLP &)
Overloaded Equals Operator.
vector< Ipopt::Number > g_sol_
Activities of constraint g( x_sol_)
void SetVariableUpperBound(Ipopt::Index var_no, Ipopt::Number x_u)
Change the upper bound on the variable.
Ipopt::SmartPtr< TMINLP > tminlp_
pointer to the tminlp that is being adapted
double evaluateUpperBoundingFunction(const double *x)
Evaluate the upper bounding function at given point and store the result.
Ipopt::Number obj_value() const
Get the objective value.
const Ipopt::Number * x_l()
Get the current values for the lower bounds.
void SetVariablesBounds(Ipopt::Index n, const Ipopt::Number *x_l, const Ipopt::Number *x_u)
Change the bounds on the variables.
vector< Ipopt::Number > g_u_
Upper bounds on constraints values.
bool IsNull(const OSSmartPtr< U > &smart_ptr)
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
The caller is allowed to modify the bounds, so this method returns the internal bounds information...
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Returns the vector of constraint values in x.
vector< Ipopt::Number > orig_x_l_
Original lower bounds on variables.
bool need_new_warm_starter_
Do we need a new warm starter object.
vector< Ipopt::Number > x_u_
Current upper bounds on variables.
const Ipopt::Number * x_u()
Get the current values for the upper bounds.
Ipopt::Number nlp_lower_bound_inf_
Value for a lower bound that denotes -infinity.
void SetWarmStarter(Ipopt::SmartPtr< IpoptInteriorWarmStarter > warm_starter)
vector< Ipopt::Number > x_init_user_
User-provideed initial prmal point.
Ipopt::Index nnz_jac_g_
Number of non-zeroes in the constraints jacobian.
Ipopt::Index num_constraints() const
Get the number of constraints.
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Returns the vector of the gradient of the objective w.r.t.
const Ipopt::Number * duals_init() const
get the starting dual point
const Ipopt::Number * orig_x_l() const
Get the original values for the lower bounds.
double check_solution(OsiObject **objects=0, int nObjects=-1)
Round and check the current solution, return norm inf of constraint violation.
const Ipopt::Number * orig_x_u() const
Get the original values for the upper bounds.
Ipopt::Number obj_value_
Value of the optimal solution found by Ipopt.
Ipopt::SolverReturn return_status_
Return status of the optimization process.
void setDualsInit(Ipopt::Index n, const Ipopt::Number *duals_init)
set the dual starting point to duals_init
Ipopt::Number nlp_upper_bound_inf_
Value for a upper bound that denotes infinity.
TMINLP2TNLP()
Default Constructor.
void gutsOfCopy(const TMINLP2TNLP &source)
Copies all the arrays.
Ipopt::Index nnz_h_lag_
Number of non-zeroes in the lagrangian hessian.
void fint fint fint real fint real real real real real real * g
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Returns the value of the objective function in x.
Ipopt::Index num_variables() const
Get the number of variables.
vector< Ipopt::Number > duals_sol_
Dual multipliers of constraints and bounds.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, TNLP::IndexStyleEnum &index_style)
This call is just passed onto the TMINLP object.
void setxInit(Ipopt::Index n, const Ipopt::Number *x_init)
set the starting point to x_init
Ipopt::SmartPtr< IpoptInteriorWarmStarter > GetWarmStarter()
virtual bool intermediate_callback(Ipopt::AlgorithmMode mode, Ipopt::Index iter, Ipopt::Number obj_value, Ipopt::Number inf_pr, Ipopt::Number inf_du, Ipopt::Number mu, Ipopt::Number d_norm, Ipopt::Number regularization_size, Ipopt::Number alpha_du, Ipopt::Number alpha_pr, Ipopt::Index ls_trials, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Intermediate Callback method for the user.
void SetVariableBounds(Ipopt::Index var_no, Ipopt::Number x_l, Ipopt::Number x_u)
Change the bounds on the variable.
virtual bool get_warm_start_iterate(Ipopt::IteratesVector &warm_start_iterate)
Methat that returns an Ipopt IteratesVector that has the starting point for all internal varibles...
VariableType
Type of the variables.
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Returns the jacobian of the constraints.
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Method called by Ipopt to get the starting point.
void fint fint fint real fint real * x