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 updating NLPBlock after solve #236

Merged
merged 1 commit into from
Aug 25, 2022
Merged

Fix updating NLPBlock after solve #236

merged 1 commit into from
Aug 25, 2022

Conversation

odow
Copy link
Member

@odow odow commented Aug 25, 2022

Closes #204

@codecov
Copy link

codecov bot commented Aug 25, 2022

Codecov Report

Merging #236 (1ec7f83) into master (4a439e6) will decrease coverage by 0.02%.
The diff coverage is 66.66%.

@@            Coverage Diff             @@
##           master     #236      +/-   ##
==========================================
- Coverage   71.28%   71.26%   -0.03%     
==========================================
  Files          12       12              
  Lines        1919     1921       +2     
==========================================
+ Hits         1368     1369       +1     
- Misses        551      552       +1     
Impacted Files Coverage Δ
src/MOI_wrapper/nlp.jl 78.26% <66.66%> (-2.70%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@odow
Copy link
Member Author

odow commented Aug 25, 2022

With this PR I get:

julia> using JuMP

julia> using KNITRO

julia> # small test problem
       model = JuMP.Model(
           optimizer_with_attributes(
               KNITRO.Optimizer,
               "honorbnds" => 1,
               ),
       )
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Knitro

julia> @variable(model, 0 <= x[1:5] <= 10)
5-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]
 x[4]
 x[5]

julia> @constraint(model, sum(x) == 10)
x[1] + x[2] + x[3] + x[4] + x[5] = 10.0

julia> epsilon = @NLparameter(model, epsilon==1)
epsilon == 1.0

julia> @NLconstraint(model, x[1] + exp(x[2]*epsilon) <= 10)
(x[1] + exp(x[2] * epsilon)) - 10.0  0

julia> @NLconstraint(model, x[2] + exp(x[3]*epsilon) <= 5)
(x[2] + exp(x[3] * epsilon)) - 5.0  0

julia> @objective(model, Max, x[2])
x[2]

julia> # solve with first parameter
       set_value(epsilon, 1e-1) # okay
0.1

julia> optimize!(model)
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####

=======================================
            Student License
       (NOT FOR COMMERCIAL USE)
         Artelys Knitro 13.1.0
=======================================

No start point provided -- Knitro computing one.

Knitro presolve eliminated 0 variables and 0 constraints.

datacheck:               0
hessian_no_f:            1
honorbnds:               1
numthreads:              1

Problem Characteristics                                 (   Presolved)
-----------------------
Objective goal:  Maximize
Objective type:  linear
Number of variables:                                  5 (           5)
    bounded below only:                               0 (           0)
    bounded above only:                               0 (           0)
    bounded below and above:                          5 (           5)
    fixed:                                            0 (           0)
    free:                                             0 (           0)
Number of constraints:                                3 (           3)
    linear equalities:                                1 (           1)
    quadratic equalities:                             0 (           0)
    gen. nonlinear equalities:                        0 (           0)
    linear one-sided inequalities:                    0 (           0)
    quadratic one-sided inequalities:                 0 (           0)
    gen. nonlinear one-sided inequalities:            2 (           2)
    linear two-sided inequalities:                    0 (           0)
    quadratic two-sided inequalities:                 0 (           0)
    gen. nonlinear two-sided inequalities:            0 (           0)
Number of nonzeros in Jacobian:                       9 (           9)
Number of nonzeros in Hessian:                        2 (           2)

Knitro using the Interior-Point/Barrier Direct algorithm.

  Iter      Objective      FeasError   OptError    ||Step||    CGits 
--------  --------------  ----------  ----------  ----------  -------
       0    4.628316e+00   1.321e+01
       4    4.000000e+00   3.907e-08   3.907e-08   1.267e-03        0

EXIT: Locally optimal solution found.

Final Statistics
----------------
Final objective value               =   4.00000001980378e+00
Final feasibility error (abs / rel) =   3.91e-08 / 2.96e-09
Final optimality error  (abs / rel) =   3.91e-08 / 3.91e-08
# of iterations                     =          4 
# of CG iterations                  =          0 
# of function evaluations           =          6
# of gradient evaluations           =          6
# of Hessian evaluations            =          4
Total program time (secs)           =       1.57684 (     1.574 CPU time)
Time spent in evaluations (secs)    =       0.82033

===============================================================================


julia> # solve with second parameter
       set_value(epsilon, 1e-2) # error :(
0.01

julia> optimize!(model)
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####

=======================================
            Student License
       (NOT FOR COMMERCIAL USE)
         Artelys Knitro 13.1.0
=======================================

No start point provided -- Knitro computing one.

Knitro presolve eliminated 0 variables and 0 constraints.

datacheck:               0
hessian_no_f:            1
honorbnds:               1
numthreads:              1

Problem Characteristics                                 (   Presolved)
-----------------------
Objective goal:  Maximize
Objective type:  linear
Number of variables:                                  5 (           5)
    bounded below only:                               0 (           0)
    bounded above only:                               0 (           0)
    bounded below and above:                          5 (           5)
    fixed:                                            0 (           0)
    free:                                             0 (           0)
Number of constraints:                                3 (           3)
    linear equalities:                                1 (           1)
    quadratic equalities:                             0 (           0)
    gen. nonlinear equalities:                        0 (           0)
    linear one-sided inequalities:                    0 (           0)
    quadratic one-sided inequalities:                 0 (           0)
    gen. nonlinear one-sided inequalities:            2 (           2)
    linear two-sided inequalities:                    0 (           0)
    quadratic two-sided inequalities:                 0 (           0)
    gen. nonlinear two-sided inequalities:            0 (           0)
Number of nonzeros in Jacobian:                       9 (           9)
Number of nonzeros in Hessian:                        2 (           2)

Knitro using the Interior-Point/Barrier Direct algorithm.

  Iter      Objective      FeasError   OptError    ||Step||    CGits 
--------  --------------  ----------  ----------  ----------  -------
       0    4.628316e+00   1.321e+01
       4    4.000000e+00   2.217e-09   2.217e-09   4.859e-03        0

EXIT: Locally optimal solution found.

Final Statistics
----------------
Final objective value               =   4.00000000054325e+00
Final feasibility error (abs / rel) =   2.22e-09 / 1.68e-10
Final optimality error  (abs / rel) =   2.22e-09 / 2.22e-09
# of iterations                     =          4 
# of CG iterations                  =          0 
# of function evaluations           =          6
# of gradient evaluations           =          6
# of Hessian evaluations            =          4
Total program time (secs)           =       0.00249 (     0.002 CPU time)
Time spent in evaluations (secs)    =       0.00009

===============================================================================

@odow odow merged commit c6a475e into master Aug 25, 2022
@odow odow deleted the odow-patch-1 branch August 25, 2022 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Error updating NLparameter
1 participant