Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ordering of slack variabels in cons #54

Merged
merged 1 commit into from
Apr 28, 2022
Merged

Fix ordering of slack variabels in cons #54

merged 1 commit into from
Apr 28, 2022

Conversation

tmigot
Copy link
Member

@tmigot tmigot commented Apr 26, 2022

I introduced a bug in #48 . The ordering of slack variables matters. Here is a minimum working example illustrating the issue.

using ADNLPModels, NLPModels, NLPModelsModifiers
nlp = ADNLPModel(x -> sum(x), ones(2), x -> [x[1]^2; x[2]*x[1]], [-Inf, 1.0], [1.0, Inf])
function NLPModels.cons_nln!(::ADNLPModel, x, c)
  c .= [x[1]^2; x[2]*x[1]]
end
function NLPModels.jac_nln_structure!(::ADNLPModel, rows, cols)
  rows .= [1, 1, 2, 2]
  cols .= [1, 2, 1, 2]
  return rows, cols
end
function NLPModels.jac_nln_coord!(::ADNLPModel, x, vals)
  vals .= [2*x[1], 0.0, x[2], x[1]]
  return vals
end
function NLPModels.jprod_nln!(::ADNLPModel, x, v, jv)
  jv .= [2*x[1] * v[1], x[2] * v[1] + x[1] * v[2]]
  return jv
end
x0 = [1., 2.]
snlp = SlackModel(nlp)
s0 = [1., 2., 0.5, 4.]
#=
The slack variables are implicitly ordered as `[s(low), s(upp), s(rng)]`, where
`low`, `upp` and `rng` represent the indices of the constraints of the form
``c_L ≤ c(x) < ∞``, ``-∞ < c(x) ≤ c_U`` and
``c_L ≤ c(x) ≤ c_U``, respectively.
=#
@show nlp.meta.jlow == [2]
@show nlp.meta.jupp == [1]
@show nlp.meta.jrng == []
# So the constraint becomes: x[1]^2 + x[4] ; x[2] * x[1] + x[3]
@show cons_nln(snlp, s0) == [s0[1]^2 - s0[4] ; s0[2] * s0[1] - s0[3]]

@codecov
Copy link

codecov bot commented Apr 26, 2022

Codecov Report

Merging #54 (0da1efc) into main (50bbc20) will not change coverage.
The diff coverage is 58.33%.

@@           Coverage Diff           @@
##             main      #54   +/-   ##
=======================================
  Coverage   95.28%   95.28%           
=======================================
  Files           6        6           
  Lines         742      742           
=======================================
  Hits          707      707           
  Misses         35       35           
Impacted Files Coverage Δ
src/slack-model.jl 91.68% <58.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 50bbc20...0da1efc. Read the comment docs.

@github-actions
Copy link
Contributor

Package name latest stable
ADNLPModels.jl
AmplNLReader.jl
CUTEst.jl
CaNNOLeS.jl
DCI.jl
JSOSolvers.jl
LLSModels.jl
NLPModelsIpopt.jl
NLPModelsJuMP.jl
NLPModelsTest.jl
Percival.jl
QuadraticModels.jl
SolverBenchmark.jl
SolverTools.jl

@tmigot tmigot requested a review from abelsiqueira April 27, 2022 14:53
Copy link
Member

@abelsiqueira abelsiqueira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@dpo dpo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that was a clear bug. Thank you.

@tmigot tmigot merged commit 545f7b5 into main Apr 28, 2022
@tmigot tmigot deleted the fix-slack-cons branch April 28, 2022 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants