Skip to content

Commit

Permalink
initialize arrays passed to ResortBnds, unless disabled
Browse files Browse the repository at this point in the history
- fixes #352
  • Loading branch information
svigerske committed Dec 20, 2019
1 parent 3902d2a commit 2695051
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
5 changes: 4 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ commit history.
2020-xx-yy: 3.13.1
- Added asserts that check whether sparsity pattern of Jacobian
and Hessian as returned by TNLP are within range w.r.t. number
of variables and constraints.
of variables and constraints. [#350]
- TNLPAdapter::ResortBnds now initialized complete output arrays
with 0.0 before filling in values for non-fixed variables. Use
new argument clearorig to turn this off. [#352]

2019-10-19: 3.13.0
This major release comes with a larger renovation of the build
Expand Down
3 changes: 3 additions & 0 deletions src/Interfaces/IpTNLP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ class IPOPTLIB_EXPORT TNLP : public ReferencedObject
* tnlp_adapter->ResortBnds(*ip_data->curr()->z_L(), duallbs,
* *ip_data->curr()->z_U(), dualubs);
* \endcode
* \note ResortBnds does not provide dual multipliers for fixed variables, even if the
* fixed-variable treatment has been set to handle them as constraints.
*
* Additionally, information about scaled violation of constraint
* and violation of complementarity constraints can be obtained via
* \code
Expand Down
17 changes: 10 additions & 7 deletions src/Interfaces/IpTNLPAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include <cmath>
#include <cstdio>
#include <cstring>

namespace Ipopt
{
Expand Down Expand Up @@ -2132,11 +2133,6 @@ void TNLPAdapter::FinalizeSolution(

Number* full_z_L = new Number[n_full_x_];
Number* full_z_U = new Number[n_full_x_];
for( int i = 0; i < n_full_x_; i++ )
{
full_z_L[i] = 0.; //nlp_lower_bound_inf_;
full_z_U[i] = 0.; //nlp_upper_bound_inf_;
}
ResortBnds(z_L, full_z_L, z_U, full_z_U);

SmartPtr<const DenseVectorSpace> z_L_space = dynamic_cast<const DenseVectorSpace*>(GetRawPtr(z_L.OwnerSpace()));
Expand All @@ -2161,7 +2157,7 @@ void TNLPAdapter::FinalizeSolution(
}
std::vector<Number> new_z_L_meta_data(n_full_x_, 0.0);
std::vector<Number> new_z_U_meta_data(n_full_x_, 0.0);
ResortBnds(*z_L_meta_vector, &new_z_L_meta_data[0], *z_U_meta_vector, &new_z_U_meta_data[0]);
ResortBnds(*z_L_meta_vector, &new_z_L_meta_data[0], *z_U_meta_vector, &new_z_U_meta_data[0], false);
std::string z_L_meta_data_tag = z_L_meta_iter->first;
std::string z_U_meta_data_tag = z_L_meta_iter->first;
z_L_meta_data_tag += "_z_L";
Expand Down Expand Up @@ -2475,11 +2471,15 @@ void TNLPAdapter::ResortBnds(
const Vector& x_L,
Number* x_L_orig,
const Vector& x_U,
Number* x_U_orig
Number* x_U_orig,
bool clearorig
)
{
if( x_L_orig )
{
if( clearorig )
memset(x_L_orig, 0, n_full_x_*sizeof(Number));

const DenseVector* dx_L = static_cast<const DenseVector*>(&x_L);
DBG_ASSERT(dynamic_cast<const DenseVector*>(&x_L));

Expand Down Expand Up @@ -2535,6 +2535,9 @@ void TNLPAdapter::ResortBnds(

if( x_U_orig )
{
if( clearorig )
memset(x_U_orig, 0, n_full_x_*sizeof(Number));

const DenseVector* dx_U = static_cast<const DenseVector*>(&x_U);
DBG_ASSERT(dynamic_cast<const DenseVector*>(&x_U));

Expand Down
13 changes: 9 additions & 4 deletions src/Interfaces/IpTNLPAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ class IPOPTLIB_EXPORT TNLPAdapter : public NLP
Number* g_orig
);

/** Provides values for lower and upper bounds on variables for given Ipopt-internal vectors.
*
* Similar to ResortX, but does so for two arrays and does not set any values for fixed variables.
*/
void ResortBnds(
const Vector& x_L,
Number* x_L_orig,
const Vector& x_U,
Number* x_U_orig
const Vector& x_L, /**< internal values for lower bounds on x */
Number* x_L_orig, /**< vector to fill with values from x_L */
const Vector& x_U, /**< internal values for upper bounds on x */
Number* x_U_orig, /**< vector to fill with values from x_U */
bool clearorig = true /**< whether to initialize complete x_L_orig and x_U_orig to 0.0 before setting values for non-fixed variables */
);
//@}

Expand Down

0 comments on commit 2695051

Please sign in to comment.