diff --git a/bindings/AMPL/AMPLModel.cpp b/bindings/AMPL/AMPLModel.cpp index 8db01eab..37205fc3 100644 --- a/bindings/AMPL/AMPLModel.cpp +++ b/bindings/AMPL/AMPLModel.cpp @@ -12,6 +12,7 @@ #include "tools/Infinity.hpp" #include "options/Options.hpp" #include "symbolic/Concatenation.hpp" +#include "symbolic/UnaryNegation.hpp" #include "Uno.hpp" namespace uno { @@ -53,6 +54,7 @@ namespace uno { variable_status(this->number_variables), constraint_type(this->number_constraints), constraint_status(this->number_constraints), + multipliers_with_flipped_sign(this->number_constraints), equality_constraints_collection(this->equality_constraints), inequality_constraints_collection(this->inequality_constraints), lower_bounded_variables_collection(this->lower_bounded_variables), @@ -201,10 +203,6 @@ namespace uno { const int upper_triangular = 1; this->number_asl_hessian_nonzeros = static_cast((*(this->asl)->p.Sphset)(this->asl, nullptr, objective_number, 1, 1, upper_triangular)); this->asl_hessian.reserve(this->number_asl_hessian_nonzeros); - - // use Lagrangian scale: in AMPL, the Lagrangian is f + lambda.g, while Uno uses f - lambda.g - fint error_flag{}; - lagscale_ASL(this->asl, -1., &error_flag); } size_t AMPLModel::number_objective_gradient_nonzeros() const { @@ -282,15 +280,17 @@ namespace uno { // evaluate the Hessian: store the matrix in a preallocated array this->asl_hessian const int objective_number = -1; + // flip the signs of the multipliers: in AMPL, the Lagrangian is f + lambda.g, while Uno uses f - lambda.g + this->multipliers_with_flipped_sign = -multipliers; if (this->fixed_hessian_sparsity) { (*(this->asl)->p.Sphes)(this->asl, nullptr, const_cast(this->asl_hessian.data()), objective_number, &objective_multiplier, - const_cast(multipliers.data())); + const_cast(this->multipliers_with_flipped_sign.data())); } else { double* objective_multiplier_pointer = (objective_multiplier != 0.) ? &objective_multiplier : nullptr; const bool all_zeros_multipliers = are_all_zeros(multipliers); (*(this->asl)->p.Sphes)(this->asl, nullptr, const_cast(this->asl_hessian.data()), objective_number, objective_multiplier_pointer, - all_zeros_multipliers ? nullptr : const_cast(multipliers.data())); + all_zeros_multipliers ? nullptr : const_cast(this->multipliers_with_flipped_sign.data())); } // generate the sparsity pattern in the right sparse format diff --git a/bindings/AMPL/AMPLModel.hpp b/bindings/AMPL/AMPLModel.hpp index c9d05b07..da7220d5 100644 --- a/bindings/AMPL/AMPLModel.hpp +++ b/bindings/AMPL/AMPLModel.hpp @@ -7,6 +7,7 @@ #include #include "model/Model.hpp" #include "linear_algebra/SparseVector.hpp" +#include "linear_algebra/Vector.hpp" #include "symbolic/CollectionAdapter.hpp" // include AMPL Solver Library (ASL) @@ -82,6 +83,7 @@ namespace uno { std::vector constraint_status; /*!< Status of the constraints (EQUAL_BOUNDS, BOUNDED_LOWER, BOUNDED_UPPER, BOUNDED_BOTH_SIDES, * UNBOUNDED) */ std::vector linear_constraints; + mutable Vector multipliers_with_flipped_sign; // lists of variables and constraints + corresponding collection objects std::vector equality_constraints{};