Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
CoMISo
CoMISo
Commits
624b6955
Commit
624b6955
authored
Nov 14, 2019
by
Max Lyon
Browse files
Merge branch 'cleanup-ipopt-solvers' into 'master'
Cleanup ipopt solvers See merge request
!48
parents
c5b51cc2
2c20415f
Pipeline
#12798
passed with stages
in 6 minutes and 2 seconds
Changes
8
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
Examples/small_cplex_soc/main.cc
View file @
624b6955
...
...
@@ -114,14 +114,13 @@ int main(void)
std
::
cout
<<
"---------- 5) Solve with IPOPT solver... "
<<
std
::
endl
;
COMISO
::
IPOPTSolver
ipopt
;
ipopt
.
app
().
Options
()
->
SetStringValue
(
"derivative_test"
,
"second-order"
);
ipopt
.
set_ipopt_option
(
"derivative_test"
,
"second-order"
);
ipopt
.
solve
(
&
lsqp
,
constraints
);
#endif
std
::
cout
<<
"---------- 6) Print solution..."
<<
std
::
endl
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
std
::
cerr
<<
"x_"
<<
i
<<
" = "
<<
lsqp
.
x
()[
i
]
<<
std
::
endl
;
return
0
;
}
NSolver/IPOPTCallbackParameters.hh
0 → 100644
View file @
624b6955
//=============================================================================
//
// STRUCT IPOPTCallbackParameters
//
//=============================================================================
#ifndef COMISO_IPOPTCALLBACKPARAMETERS_HH
#define COMISO_IPOPTCALLBACKPARAMETERS_HH
#include <IpTNLP.hpp>
//== TYPE DEFINITION CALLBACK PARAMETERS ======================================
namespace
COMISO
{
struct
IPOPTCallbackParameters
{
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
;
};
}
#endif
NSolver/
N
ProblemI
POPTc
.cc
→
NSolver/
IPOPT
ProblemI
nstance
.cc
View file @
624b6955
...
...
@@ -11,21 +11,18 @@
#if COMISO_IPOPT_AVAILABLE
//=============================================================================
#include "CoMISo/Utils/CoMISoError.hh"
#include <CoMISo/Utils/gmm.hh>
#include <Base/Debug/DebTime.hh>
#include "NProblemIPOPT.hh"
#include "NProblemGmmInterface.hh"
#include "NProblemInterface.hh"
#include "NConstraintInterface.hh"
#include "BoundConstraint.hh"
#include "CoMISo/Utils/CoMISoError.hh"
#include <Base/Debug/DebTime.hh>
#include <CoMISo/Utils/gmm.hh>
#include "IPOPTCallbackParameters.hh"
#include <IpTNLP.hpp>
#include <IpIpoptApplication.hpp>
#include <IpSolveStatistics.hpp>
#include "IPOPTProblemInstance.hh"
//== NAMESPACES ===============================================================
...
...
@@ -33,11 +30,10 @@ namespace COMISO {
//== IMPLEMENTATION PROBLEM INSTANCE==========================================================
//== IMPLEMENTATION PROBLEM INSTANCE===========================================
void
N
ProblemI
POPT
::
IPOPT
ProblemI
nstance
::
split_constraints
(
const
std
::
vector
<
NConstraintInterface
*>&
_constraints
)
{
DEB_enter_func
;
...
...
@@ -61,7 +57,7 @@ split_constraints(const std::vector<NConstraintInterface*>& _constraints)
void
N
ProblemI
POPT
::
IPOPT
ProblemI
nstance
::
analyze_special_properties
(
const
NProblemInterface
*
_problem
,
const
std
::
vector
<
NConstraintInterface
*>&
_constraints
)
{
hessian_constant_
=
true
;
...
...
@@ -98,7 +94,7 @@ analyze_special_properties(const NProblemInterface* _problem, const std::vector<
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
get_nlp_info
(
Index
&
n
,
Index
&
m
,
Index
&
nnz_jac_g
,
bool
IPOPT
ProblemI
nstance
::
get_nlp_info
(
Index
&
n
,
Index
&
m
,
Index
&
nnz_jac_g
,
Index
&
nnz_h_lag
,
IndexStyleEnum
&
index_style
)
{
DEB_enter_func
;
...
...
@@ -161,7 +157,7 @@ bool NProblemIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
get_bounds_info
(
Index
n
,
Number
*
x_l
,
Number
*
x_u
,
bool
IPOPT
ProblemI
nstance
::
get_bounds_info
(
Index
n
,
Number
*
x_l
,
Number
*
x_u
,
Index
m
,
Number
*
g_l
,
Number
*
g_u
)
{
DEB_enter_func
;
...
...
@@ -230,7 +226,7 @@ bool NProblemIPOPT::get_bounds_info(Index n, Number* x_l, Number* x_u,
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
get_starting_point
(
Index
n
,
bool
init_x
,
Number
*
x
,
bool
IPOPT
ProblemI
nstance
::
get_starting_point
(
Index
n
,
bool
init_x
,
Number
*
x
,
bool
init_z
,
Number
*
z_L
,
Number
*
z_U
,
Index
m
,
bool
init_lambda
,
Number
*
lambda
)
...
...
@@ -246,7 +242,7 @@ bool NProblemIPOPT::get_starting_point(Index n, bool init_x, Number* x,
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
eval_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
&
obj_value
)
bool
IPOPT
ProblemI
nstance
::
eval_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
&
obj_value
)
{
DEB_enter_func
;
// return the value of the objective function
...
...
@@ -258,7 +254,7 @@ bool NProblemIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_val
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
eval_grad_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
*
grad_f
)
bool
IPOPT
ProblemI
nstance
::
eval_grad_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
*
grad_f
)
{
DEB_enter_func
;
problem_
->
eval_gradient
(
x
,
grad_f
);
...
...
@@ -270,7 +266,7 @@ bool NProblemIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number* gr
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
eval_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Number
*
g
)
bool
IPOPT
ProblemI
nstance
::
eval_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Number
*
g
)
{
DEB_enter_func
;
// evaluate all constraint functions
...
...
@@ -284,7 +280,7 @@ bool NProblemIPOPT::eval_g(Index n, const Number* x, bool new_x, Index m, Number
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
eval_jac_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
bool
IPOPT
ProblemI
nstance
::
eval_jac_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Index
nele_jac
,
Index
*
iRow
,
Index
*
jCol
,
Number
*
values
)
{
...
...
@@ -342,7 +338,7 @@ bool NProblemIPOPT::eval_jac_g(Index n, const Number* x, bool new_x,
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
eval_h
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
bool
IPOPT
ProblemI
nstance
::
eval_h
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
obj_factor
,
Index
m
,
const
Number
*
lambda
,
bool
new_lambda
,
Index
nele_hess
,
Index
*
iRow
,
Index
*
jCol
,
Number
*
values
)
...
...
@@ -476,7 +472,7 @@ bool NProblemIPOPT::eval_h(Index n, const Number* x, bool new_x,
double
_QNT
(
const
double
x
)
{
return
x
;
}
void
N
ProblemI
POPT
::
finalize_solution
(
SolverReturn
status
,
void
IPOPT
ProblemI
nstance
::
finalize_solution
(
SolverReturn
status
,
Index
n
,
const
Number
*
x
,
const
Number
*
z_L
,
const
Number
*
z_U
,
Index
m
,
const
Number
*
g
,
const
Number
*
lambda
,
Number
obj_value
,
...
...
@@ -516,21 +512,44 @@ void NProblemIPOPT::finalize_solution(SolverReturn status,
//-----------------------------------------------------------------------------
void
IPOPTProblemInstance
::
set_callback_function
(
std
::
function
<
bool
(
const
IPOPTCallbackParameters
&
)
>
func
)
{
intermediate_callback_
=
func
;
}
bool
NProblemIPOPT
::
intermediate_callback
(
Ipopt
::
AlgorithmMode
/*mode*/
,
Index
/*iter*/
,
Number
/*obj_value*/
,
Number
/*inf_pr*/
,
Number
/*inf_du*/
,
Number
/*mu*/
,
Number
/*d_norm*/
,
Number
/*regularization_size*/
,
Number
/*alpha_du*/
,
Number
/*alpha_pr*/
,
Index
/*ls_trials*/
,
const
IpoptData
*
/*ip_data*/
,
IpoptCalculatedQuantities
*
/*ip_cq*/
)
bool
IPOPTProblemInstance
::
intermediate_callback
(
Ipopt
::
AlgorithmMode
mode
,
Index
iter
,
Number
obj_value
,
Number
inf_pr
,
Number
inf_du
,
Number
mu
,
Number
d_norm
,
Number
regularization_size
,
Number
alpha_du
,
Number
alpha_pr
,
Index
ls_trials
,
const
IpoptData
*
ip_data
,
IpoptCalculatedQuantities
*
ip_cq
)
{
PROGRESS_TICK
;
if
(
intermediate_callback_
)
{
IPOPTCallbackParameters
callbackParameters
{
mode
,
iter
,
obj_value
,
inf_pr
,
inf_du
,
mu
,
d_norm
,
regularization_size
,
alpha_du
,
alpha_pr
,
ls_trials
,
ip_data
,
ip_cq
};
return
intermediate_callback_
(
callbackParameters
);
}
return
true
;
}
...
...
@@ -538,7 +557,7 @@ bool NProblemIPOPT::intermediate_callback(
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
hessian_constant
()
const
bool
IPOPT
ProblemI
nstance
::
hessian_constant
()
const
{
return
hessian_constant_
;
}
...
...
@@ -547,7 +566,7 @@ bool NProblemIPOPT::hessian_constant() const
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
jac_c_constant
()
const
bool
IPOPT
ProblemI
nstance
::
jac_c_constant
()
const
{
return
jac_c_constant_
;
}
...
...
@@ -556,7 +575,7 @@ bool NProblemIPOPT::jac_c_constant() const
//-----------------------------------------------------------------------------
bool
N
ProblemI
POPT
::
jac_d_constant
()
const
bool
IPOPT
ProblemI
nstance
::
jac_d_constant
()
const
{
return
jac_d_constant_
;
}
...
...
@@ -565,7 +584,7 @@ bool NProblemIPOPT::jac_d_constant() const
//== IMPLEMENTATION PROBLEM INSTANCE==========================================================
bool
N
Problem
GmmIPOPT
::
get_nlp_info
(
Index
&
n
,
Index
&
m
,
Index
&
nnz_jac_g
,
bool
IPOPT
Problem
InstanceGmm
::
get_nlp_info
(
Index
&
n
,
Index
&
m
,
Index
&
nnz_jac_g
,
Index
&
nnz_h_lag
,
IndexStyleEnum
&
index_style
)
{
DEB_enter_func
;
...
...
@@ -657,7 +676,7 @@ bool NProblemGmmIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
get_bounds_info
(
Index
n
,
Number
*
x_l
,
Number
*
x_u
,
bool
IPOPT
Problem
InstanceGmm
::
get_bounds_info
(
Index
n
,
Number
*
x_l
,
Number
*
x_u
,
Index
m
,
Number
*
g_l
,
Number
*
g_u
)
{
DEB_enter_func
;
...
...
@@ -691,7 +710,7 @@ bool NProblemGmmIPOPT::get_bounds_info(Index n, Number* x_l, Number* x_u,
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
get_starting_point
(
Index
n
,
bool
init_x
,
Number
*
x
,
bool
IPOPT
Problem
InstanceGmm
::
get_starting_point
(
Index
n
,
bool
init_x
,
Number
*
x
,
bool
init_z
,
Number
*
z_L
,
Number
*
z_U
,
Index
m
,
bool
init_lambda
,
Number
*
lambda
)
...
...
@@ -707,7 +726,7 @@ bool NProblemGmmIPOPT::get_starting_point(Index n, bool init_x, Number* x,
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
eval_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
&
obj_value
)
bool
IPOPT
Problem
InstanceGmm
::
eval_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
&
obj_value
)
{
DEB_enter_func
;
// return the value of the objective function
...
...
@@ -719,7 +738,7 @@ bool NProblemGmmIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
eval_grad_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
*
grad_f
)
bool
IPOPT
Problem
InstanceGmm
::
eval_grad_f
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
*
grad_f
)
{
DEB_enter_func
;
problem_
->
eval_gradient
(
x
,
grad_f
);
...
...
@@ -731,7 +750,7 @@ bool NProblemGmmIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number*
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
eval_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Number
*
g
)
bool
IPOPT
Problem
InstanceGmm
::
eval_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Number
*
g
)
{
DEB_enter_func
;
// evaluate all constraint functions
...
...
@@ -745,7 +764,7 @@ bool NProblemGmmIPOPT::eval_g(Index n, const Number* x, bool new_x, Index m, Num
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
eval_jac_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
bool
IPOPT
Problem
InstanceGmm
::
eval_jac_g
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Index
m
,
Index
nele_jac
,
Index
*
iRow
,
Index
*
jCol
,
Number
*
values
)
{
...
...
@@ -791,7 +810,7 @@ bool NProblemGmmIPOPT::eval_jac_g(Index n, const Number* x, bool new_x,
//-----------------------------------------------------------------------------
bool
N
Problem
GmmIPOPT
::
eval_h
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
bool
IPOPT
Problem
InstanceGmm
::
eval_h
(
Index
n
,
const
Number
*
x
,
bool
new_x
,
Number
obj_factor
,
Index
m
,
const
Number
*
lambda
,
bool
new_lambda
,
Index
nele_hess
,
Index
*
iRow
,
Index
*
jCol
,
Number
*
values
)
...
...
@@ -865,7 +884,7 @@ bool NProblemGmmIPOPT::eval_h(Index n, const Number* x, bool new_x,
//-----------------------------------------------------------------------------
void
N
Problem
GmmIPOPT
::
finalize_solution
(
SolverReturn
status
,
void
IPOPT
Problem
InstanceGmm
::
finalize_solution
(
SolverReturn
status
,
Index
n
,
const
Number
*
x
,
const
Number
*
z_L
,
const
Number
*
z_U
,
Index
m
,
const
Number
*
g
,
const
Number
*
lambda
,
Number
obj_value
,
...
...
@@ -877,19 +896,43 @@ void NProblemGmmIPOPT::finalize_solution(SolverReturn status,
problem_
->
store_result
(
x
);
}
bool
NProblemGmmIPOPT
::
intermediate_callback
(
Ipopt
::
AlgorithmMode
/*mode*/
,
Index
/*iter*/
,
Number
/*obj_value*/
,
Number
/*inf_pr*/
,
Number
/*inf_du*/
,
Number
/*mu*/
,
Number
/*d_norm*/
,
Number
/*regularization_size*/
,
Number
/*alpha_du*/
,
Number
/*alpha_pr*/
,
Index
/*ls_trials*/
,
const
IpoptData
*
/*ip_data*/
,
IpoptCalculatedQuantities
*
/*ip_cq*/
)
void
IPOPTProblemInstanceGmm
::
set_callback_function
(
std
::
function
<
bool
(
const
IPOPTCallbackParameters
&
)
>
func
)
{
intermediate_callback_
=
func
;
}
bool
IPOPTProblemInstanceGmm
::
intermediate_callback
(
Ipopt
::
AlgorithmMode
mode
,
Index
iter
,
Number
obj_value
,
Number
inf_pr
,
Number
inf_du
,
Number
mu
,
Number
d_norm
,
Number
regularization_size
,
Number
alpha_du
,
Number
alpha_pr
,
Index
ls_trials
,
const
IpoptData
*
ip_data
,
IpoptCalculatedQuantities
*
ip_cq
)
{
PROGRESS_TICK
;
if
(
intermediate_callback_
)
{
IPOPTCallbackParameters
callbackParameters
{
mode
,
iter
,
obj_value
,
inf_pr
,
inf_du
,
mu
,
d_norm
,
regularization_size
,
alpha_du
,
alpha_pr
,
ls_trials
,
ip_data
,
ip_cq
};
return
intermediate_callback_
(
callbackParameters
);
}
return
true
;
}
...
...
NSolver/
N
ProblemI
POPT
.hh
→
NSolver/
IPOPT
ProblemI
nstance
.hh
View file @
624b6955
...
...
@@ -15,10 +15,13 @@
//== INCLUDES =================================================================
#include <vector>
#include <cstddef>
#include <functional>
#include <CoMISo/Config/CoMISoDefines.hh>
#include "NProblemGmmInterface.hh"
#include "NProblemInterface.hh"
#include "IPOPTSolverLean.hh"
#include "NProblemGmmInterface.hh"
#include "NProblemInterface.hh"
#include "NConstraintInterface.hh"
...
...
@@ -32,23 +35,19 @@
#include <IpTNLP.hpp>
#include <IpIpoptApplication.hpp>
#include <IpSolveStatistics.hpp>
#include <vector>
#include <cstddef>
//== NAMESPACES ===============================================================
namespace
COMISO
{
//== FORWARDDECLARATIONS ======================================================
class
NProblemGmmInterface
;
// deprecated
class
NProblemInterface
;
class
NConstraintInterface
;
struct
IPOPTCallbackParameters
;
//== CLASS DEFINITION PROBLEM INSTANCE=========================================================
class
NProblemIPOPT
:
public
Ipopt
::
TNLP
//== CLASS DEFINITION PROBLEM INSTANCE ========================================
class
IPOPTProblemInstance
:
public
Ipopt
::
TNLP
{
public:
...
...
@@ -65,8 +64,11 @@ public:
typedef
NProblemInterface
::
SMatrixNP
SMatrixNP
;
/** default constructor */
NProblemIPOPT
(
NProblemInterface
*
_problem
,
const
std
::
vector
<
NConstraintInterface
*>&
_constraints
,
const
bool
_hessian_approximation
=
false
)
:
problem_
(
_problem
),
store_solution_
(
false
),
hessian_approximation_
(
_hessian_approximation
)
IPOPTProblemInstance
(
NProblemInterface
*
_problem
,
const
std
::
vector
<
NConstraintInterface
*>&
_constraints
,
const
bool
_hessian_approximation
=
false
)
:
problem_
(
_problem
),
store_solution_
(
false
),
hessian_approximation_
(
_hessian_approximation
)
{
split_constraints
(
_constraints
);
analyze_special_properties
(
_problem
,
_constraints
);
...
...
@@ -127,6 +129,9 @@ public:
IpoptCalculatedQuantities
*
ip_cq
)
override
;
//@}
/** Set intermediate callback function object **/
void
set_callback_function
(
std
::
function
<
bool
(
const
IPOPTCallbackParameters
&
)
>
);
/** Intermediate Callback method for the user. Providing dummy
* default implementation. For details see IntermediateCallBack
* in IpNLP.hpp. */
...
...
@@ -163,8 +168,8 @@ private:
*/
//@{
// MyNLP();
N
ProblemI
POPT
(
const
N
ProblemI
POPT
&
);
N
ProblemI
POPT
&
operator
=
(
const
N
ProblemI
POPT
&
);
IPOPT
ProblemI
nstance
(
const
IPOPT
ProblemI
nstance
&
);
IPOPT
ProblemI
nstance
&
operator
=
(
const
IPOPT
ProblemI
nstance
&
);
//@}
// split user-provided constraints into general-constraints and bound-constraints
...
...
@@ -193,13 +198,15 @@ private:
std
::
vector
<
double
>
x_
;
bool
hessian_approximation_
;
std
::
function
<
bool
(
const
IPOPTCallbackParameters
&
)
>
intermediate_callback_
;
};
//== CLASS DEFINITION PROBLEM INSTANCE=========================================================
class
N
Problem
GmmIPOPT
:
public
Ipopt
::
TNLP
class
IPOPT
Problem
InstanceGmm
:
public
Ipopt
::
TNLP
{
public:
...
...
@@ -226,7 +233,7 @@ public: