Commit 565666af authored by Max Lyon's avatar Max Lyon

merge from ReForm

parents 396d2622 a0e47ef4
Pipeline #5865 passed with stages
in 6 minutes and 56 seconds
......@@ -323,7 +323,10 @@ void IPOPTSolverLean::solve(
//----------------------------------------------------------------------------
// 3. solve problem
//----------------------------------------------------------------------------
status = impl_->app_->OptimizeTNLP(np);
{
DEB_time_session_def("IPOPT App OptimizeTNLP(np)");
status = impl_->app_->OptimizeTNLP(np);
}
check_ipopt_status(status);
......
......@@ -127,6 +127,21 @@ public:
IpoptCalculatedQuantities* ip_cq);
//@}
/** Intermediate Callback method for the user. Providing dummy
* default implementation. For details see IntermediateCallBack
* in IpNLP.hpp. */
virtual bool 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
) override;
// special properties of problem
bool hessian_constant() const;
bool jac_c_constant() const;
......@@ -270,6 +285,22 @@ public:
IpoptCalculatedQuantities* ip_cq);
//@}
/** Intermediate Callback method for the user. Providing dummy
* default implementation. For details see IntermediateCallBack
* in IpNLP.hpp. */
virtual bool 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
) override;
private:
/**@name Methods to block default compiler methods.
* The compiler automatically generates the following three methods.
......
......@@ -40,6 +40,7 @@ void
NProblemIPOPT::
split_constraints(const std::vector<NConstraintInterface*>& _constraints)
{
DEB_enter_func;
// split user-provided constraints into general-constraints and bound-constraints
constraints_ .clear(); constraints_.reserve(_constraints.size());
bound_constraints_.clear(); bound_constraints_.reserve(_constraints.size());
......@@ -100,6 +101,7 @@ analyze_special_properties(const NProblemInterface* _problem, const std::vector<
bool NProblemIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
Index& nnz_h_lag, IndexStyleEnum& index_style)
{
DEB_enter_func;
// number of variables
n = static_cast<Index>(problem_->n_unknowns());
......@@ -233,6 +235,7 @@ bool NProblemIPOPT::get_starting_point(Index n, bool init_x, Number* x,
Index m, bool init_lambda,
Number* lambda)
{
DEB_enter_func;
// get initial value of problem instance
problem_->initial_x(x);
......@@ -245,6 +248,7 @@ bool NProblemIPOPT::get_starting_point(Index n, bool init_x, Number* x,
bool NProblemIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
{
DEB_enter_func;
// return the value of the objective function
obj_value = problem_->eval_f(x);
return true;
......@@ -256,6 +260,7 @@ bool NProblemIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_val
bool NProblemIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
{
DEB_enter_func;
problem_->eval_gradient(x, grad_f);
return true;
......@@ -267,6 +272,7 @@ bool NProblemIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number* gr
bool NProblemIPOPT::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
{
DEB_enter_func;
// evaluate all constraint functions
for( int i=0; i<m; ++i)
g[i] = constraints_[i]->eval_constraint(x);
......@@ -512,6 +518,26 @@ void NProblemIPOPT::finalize_solution(SolverReturn status,
//-----------------------------------------------------------------------------
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*/
)
{
PROGRESS_TICK;
return true;
}
//-----------------------------------------------------------------------------
bool NProblemIPOPT::hessian_constant() const
{
return hessian_constant_;
......@@ -542,6 +568,7 @@ bool NProblemIPOPT::jac_d_constant() const
bool NProblemGmmIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
Index& nnz_h_lag, IndexStyleEnum& index_style)
{
DEB_enter_func;
// number of variables
n = problem_->n_unknowns();
......@@ -633,6 +660,7 @@ bool NProblemGmmIPOPT::get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
bool NProblemGmmIPOPT::get_bounds_info(Index n, Number* x_l, Number* x_u,
Index m, Number* g_l, Number* g_u)
{
DEB_enter_func;
// first clear all variable bounds
for( int i=0; i<n; ++i)
{
......@@ -668,6 +696,7 @@ bool NProblemGmmIPOPT::get_starting_point(Index n, bool init_x, Number* x,
Index m, bool init_lambda,
Number* lambda)
{
DEB_enter_func;
// get initial value of problem instance
problem_->initial_x(x);
......@@ -680,6 +709,7 @@ bool NProblemGmmIPOPT::get_starting_point(Index n, bool init_x, Number* x,
bool NProblemGmmIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_value)
{
DEB_enter_func;
// return the value of the objective function
obj_value = problem_->eval_f(x);
return true;
......@@ -691,6 +721,7 @@ bool NProblemGmmIPOPT::eval_f(Index n, const Number* x, bool new_x, Number& obj_
bool NProblemGmmIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f)
{
DEB_enter_func;
problem_->eval_gradient(x, grad_f);
return true;
......@@ -702,6 +733,7 @@ bool NProblemGmmIPOPT::eval_grad_f(Index n, const Number* x, bool new_x, Number*
bool NProblemGmmIPOPT::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g)
{
DEB_enter_func;
// evaluate all constraint functions
for( int i=0; i<m; ++i)
g[i] = constraints_[i]->eval_constraint(x);
......@@ -840,10 +872,27 @@ void NProblemGmmIPOPT::finalize_solution(SolverReturn status,
const IpoptData* ip_data,
IpoptCalculatedQuantities* ip_cq)
{
DEB_enter_func;
// problem knows what to do
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*/
)
{
PROGRESS_TICK;
return true;
}
//=============================================================================
} // namespace COMISO
......
This diff is collapsed.
......@@ -35,11 +35,13 @@
//== INCLUDES =================================================================
#include "GMM_Tools.hh"
#define GMM_USES_LAPACK
#include <gmm/gmm_lapack_interface.h>
#include <queue>
#include <CoMISo/Utils/VSToolsT.hh>
#include <CoMISo/Utils/VSToolsT.hh>
#include <Base/Debug/DebOut.hh>
#include <queue>
//== NAMESPACES ===============================================================
......@@ -961,19 +963,19 @@ int gauss_seidel_local( MatrixT& _A, VectorT& _x, VectorT& _rhs, std::vector<uns
template<class MatrixT, class VectorT>
double residuum_norm( MatrixT& _A, VectorT& _x, VectorT& _rhs )
{
if ( gmm::mat_ncols( _A ) != _x.size() )
std::cerr << "DIM ERROR (residuum_norm): " << gmm::mat_ncols( _A ) << " vs " << _x.size() << std::endl;
if ( gmm::mat_nrows( _A) !=_rhs.size() )
std::cerr << "DIM ERROR 2 (residuum_norm): " << gmm::mat_nrows( _A) << " vs " << _rhs.size() << std::endl;
if (gmm::mat_ncols(_A) != _x.size())
std::cerr << "DIM ERROR (residuum_norm): " << gmm::mat_ncols(_A) << " vs " << _x.size() << std::endl;
if (gmm::mat_nrows(_A) != _rhs.size())
std::cerr << "DIM ERROR 2 (residuum_norm): " << gmm::mat_nrows(_A) << " vs " << _rhs.size() << std::endl;
// temp vectors
VectorT Ax( _rhs.size());
VectorT res( _rhs.size() );
// temp vectors
VectorT Ax(_rhs.size());
VectorT res(_rhs.size());
gmm::mult( _A,_x, Ax );
gmm::add( Ax, gmm::scaled( _rhs, -1.0 ), res );
gmm::mult(_A, _x, Ax);
gmm::add(Ax, gmm::scaled(_rhs, -1.0), res);
return gmm::vect_norm2( res );
return gmm::vect_norm2(res);
}
......@@ -983,29 +985,31 @@ double residuum_norm( MatrixT& _A, VectorT& _x, VectorT& _rhs )
template<class MatrixT, class MatrixT2, class VectorT>
void factored_to_quadratic( MatrixT& _F, MatrixT2& _Q, VectorT& _rhs)
{
DEB_enter_func;
gmm::size_type m = gmm::mat_nrows(_F);
gmm::size_type n = gmm::mat_ncols(_F);
// resize result matrix and vector
gmm::resize(_Q, n-1, n-1);
gmm::resize(_Q, n - 1, n - 1);
gmm::resize(_rhs, n);
// // set up transposed
// MatrixT Ft(n,m);
// gmm::copy(gmm::transposed(_F), Ft);
// // set up transposed
// MatrixT Ft(n,m);
// gmm::copy(gmm::transposed(_F), Ft);
// compute quadratic matrix
MatrixT Q(n,n);
// gmm::mult(Ft,_F,Q);
gmm::mult(gmm::transposed(_F),_F,Q);
MatrixT Q(n, n);
// gmm::mult(Ft,_F,Q);
gmm::mult(gmm::transposed(_F), _F, Q);
PROGRESS_TICK;
// extract rhs
gmm::copy( gmm::scaled(gmm::mat_const_row( Q, n - 1),-1.0), _rhs);
gmm::copy(gmm::scaled(gmm::mat_const_row(Q, n - 1), -1.0), _rhs);
// resize and copy output
gmm::resize( Q, n-1, n-1);
_rhs.resize( n - 1);
gmm::copy ( Q, _Q);
gmm::resize(Q, n - 1, n - 1);
_rhs.resize(n - 1);
PROGRESS_TICK;
gmm::copy(Q, _Q);
}
......
......@@ -97,22 +97,22 @@ MISolver::solve(
DEB_out(2, "# integer variables: " << _to_round.size()
<< "\n# continuous variables: " << _x.size()-_to_round.size() << "\n")
// nothing to solve?
if( gmm::mat_ncols(_A) == 0 || gmm::mat_nrows(_A) == 0)
return;
if( gurobi_rounding_)
solve_gurobi(_A, _x, _rhs, _to_round);
else if( cplex_rounding_)
solve_cplex(_A, _x, _rhs, _to_round);
else if( no_rounding_ || _to_round.size() == 0)
solve_no_rounding( _A, _x, _rhs);
else if( direct_rounding_)
solve_direct_rounding( _A, _x, _rhs, _to_round);
else if( multiple_rounding_)
solve_multiple_rounding( _A, _x, _rhs, _to_round);
else
solve_iterative( _A, _x, _rhs, _to_round, _fixed_order);
// nothing to solve?
if( gmm::mat_ncols(_A) == 0 || gmm::mat_nrows(_A) == 0)
return;
if( gurobi_rounding_)
solve_gurobi(_A, _x, _rhs, _to_round);
else if( cplex_rounding_)
solve_cplex(_A, _x, _rhs, _to_round);
else if( no_rounding_ || _to_round.size() == 0)
solve_no_rounding( _A, _x, _rhs);
else if( direct_rounding_)
solve_direct_rounding( _A, _x, _rhs, _to_round);
else if( multiple_rounding_)
solve_multiple_rounding( _A, _x, _rhs, _to_round);
else
solve_iterative( _A, _x, _rhs, _to_round, _fixed_order);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment