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

Add support for VectorNonlinearFunction #3450

Merged
merged 5 commits into from
Aug 16, 2023
Merged

Add support for VectorNonlinearFunction #3450

merged 5 commits into from
Aug 16, 2023

Conversation

odow
Copy link
Member

@odow odow commented Aug 14, 2023

Tests won't pass because requires new tag of MOI.

But this is working with PATHSolver#od/nlp-expr

julia> using JuMP, PATHSolver

julia> model = Model(PATHSolver.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Path 5.0.03

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

julia> @constraints(model, begin
                              -x[3]^2 -  x[4]   + 2  x[1]
                               x[3]^3 - 2x[4]^2 + 2  x[2]
           x[1]^5 -  x[2]   + 2x[3]   - 2x[4]   - 2  x[3]
           x[1]   + 2x[2]^3 - 2x[3]   + 4x[4]   - 6  x[4]
       end)
([-x[3- x[4] + 2, x[1]]  MathOptInterface.Complements(2), [((x[3] ^ 3) - (2 x[4]²)) + 2.0, +(x[2])]  MathOptInterface.Complements(2), [((((x[1] ^ 5) - x[2]) + (2 x[3])) - (2 x[4])) - 2.0, +(x[3])]  MathOptInterface.Complements(2), [(((x[1] + (2.0 * (x[2] ^ 3))) - (2 x[3])) + (4 x[4])) - 6.0, +(x[4])]  MathOptInterface.Complements(2))

julia> optimize!(model)
Path 5.0.03 (Fri Jun 26 09:58:07 2020)
Written by Todd Munson, Steven Dirkse, Youngdae Kim, and Michael Ferris


Crash Log
major  func  diff  size  residual    step       prox   (label)
    0     0             9.3949e+00             0.0e+00 (f[    4])
    1     4     3     2 7.7898e+00  4.1e-01    0.0e+00 (f[    1])
    2     5     1     3 1.4635e+00  1.0e+00    0.0e+00 (f[    3])
    3     6     0     3 1.1831e+00  1.0e+00    0.0e+00 (f[    3])
pn_search terminated: no basis change.

Major Iteration Log
major minor  func  grad  residual    step  type prox    inorm  (label)
    0     0     7     4 1.1831e+00           I 0.0e+00 1.2e+00 (f[    3])
    1     1     8     5 1.0633e+00  1.0e+00 SO 0.0e+00 1.1e+00 (f[    3])
    2     1     9     6 9.7034e-01  1.0e+00 SO 0.0e+00 9.7e-01 (f[    3])
    3     3    10     7 1.5017e+00  1.0e+00 SO 0.0e+00 1.2e+00 (f[    4])
    4     2    11     8 1.4820e+00  1.0e+00 SO 0.0e+00 1.2e+00 (f[    4])
    5     1    12     9 1.4756e+00  1.0e+00 SO 0.0e+00 1.2e+00 (f[    4])
    6     1    13    10 1.4483e+00  1.0e+00 SO 0.0e+00 1.2e+00 (f[    4])
    7     1    14    11 1.3317e+00  1.0e+00 SO 0.0e+00 1.1e+00 (f[    4])
    8     1    15    12 1.0594e+00  1.0e+00 SO 0.0e+00 1.0e+00 (f[    4])
    9     1    16    13 5.7505e-01  1.0e+00 SO 0.0e+00 5.7e-01 (f[    4])
   10     1    17    14 7.6079e-02  1.0e+00 SO 0.0e+00 7.6e-02 (f[    4])
   11     1    18    15 1.0305e-03  1.0e+00 SO 0.0e+00 1.0e-03 (f[    4])
   12     1    19    16 1.8656e-07  1.0e+00 SO 0.0e+00 1.9e-07 (f[    4])

Major Iterations. . . . 12
Minor Iterations. . . . 15
Restarts. . . . . . . . 0
Crash Iterations. . . . 3
Gradient Steps. . . . . 0
Function Evaluations. . 19
Gradient Evaluations. . 16
Basis Time. . . . . . . 0.000089
Total Time. . . . . . . 0.043275
Residual. . . . . . . . 1.865551e-07

julia> value.(x)
4-element Vector{Float64}:
 1.2847523472583888
 0.972916458993744
 0.909376156748673
 1.173035005537013

cc @mitchphillipson we're very close

@odow odow added the Category: Nonlinear Related to nonlinear programming label Aug 14, 2023
@odow
Copy link
Member Author

odow commented Aug 14, 2023

Here's a more complicated example, taken from https://github.com/mitchphillipson/GAMS_to_JuMP/blob/70017814dca5b6eb70f5b346ed19e64c5845c106/Models/12%20-%20Expected%20Utility/insurance.jl#L65-L99

julia> pi = 0.01
0.01

julia> L = 0.5
0.5

julia> γ = 0.02
0.02

julia> σ = 0.5
0.5

julia> ρ = 1 - 1 / 0.5
-1.0

julia> using JuMP, PATHSolver

julia> model = Model(PATHSolver.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Path 5.0.03

julia> @variable(model, EU, start = 1)
EU

julia> @variable(model, EV, start = 1)
EV

julia> @variable(model, C_G, start = 1)
C_G

julia> @variable(model, C_B, start = 1)
C_B

julia> @variable(model, K, start = 1)
K

julia> @constraints(model, begin
           EU - ((1 - pi) * C_G^ρ / ρ + pi * C_B^ρ / ρ)                        EU
           EV - 100 * (((1 - pi) * C_G^ρ + pi * C_B^ρ)^(1 / ρ) - 1)            EV
           C_G - (1 - γ * K)                                                   C_G
           C_B - (1 - L + (1 - γ) * K)                                         C_B
           γ * ((1 - pi) * C_G^- 1) + pi * C_B^- 1)) - pi * C_B^- 1)  K
       end)
([EU - (((0.99 * (C_G ^ -1.0)) / -1.0) + ((0.01 * (C_B ^ -1.0)) / -1.0)), +(EU)]  MathOptInterface.Complements(2), [EV - (100.0 * ((((0.99 * (C_G ^ -1.0)) + (0.01 * (C_B ^ -1.0))) ^ -1.0) - 1.0)), +(EV)]  MathOptInterface.Complements(2), [C_G + 0.02 K - 1, C_G]  MathOptInterface.Complements(2), [C_B - 0.98 K - 0.5, C_B]  MathOptInterface.Complements(2), [(0.02 * ((0.99 * (C_G ^ -2.0)) + (0.01 * (C_B ^ -2.0)))) - (0.01 * (C_B ^ -2.0)), +(K)]  MathOptInterface.Complements(2))

julia> optimize!(model)
Path 5.0.03 (Fri Jun 26 09:58:07 2020)
Written by Todd Munson, Steven Dirkse, Youngdae Kim, and Michael Ferris


Crash Log
major  func  diff  size  residual    step       prox   (label)
    0     0             2.2871e+00             0.0e+00 (f[    1])
    1     1     0     5 5.2034e-01  1.0e+00    0.0e+00 (f[    2])
pn_search terminated: no basis change.

Major Iteration Log
major minor  func  grad  residual    step  type prox    inorm  (label)
    0     0     2     2 5.2034e-01           I 0.0e+00 5.2e-01 (f[    2])
    1     1     3     3 1.0494e-01  1.0e+00 SO 0.0e+00 1.0e-01 (f[    2])
    2     1     4     4 1.8864e-02  1.0e+00 SO 0.0e+00 1.9e-02 (f[    2])
    3     1     5     5 6.1192e-04  1.0e+00 SO 0.0e+00 6.1e-04 (f[    2])
    4     1     6     6 5.9024e-07  1.0e+00 SO 0.0e+00 5.9e-07 (f[    2])

Major Iterations. . . . 4
Minor Iterations. . . . 4
Restarts. . . . . . . . 0
Crash Iterations. . . . 1
Gradient Steps. . . . . 0
Function Evaluations. . 6
Gradient Evaluations. . 6
Basis Time. . . . . . . 0.000038
Total Time. . . . . . . 0.000949
Residual. . . . . . . . 5.902418e-07

julia> value(EU), value(EV), value(C_G), value(C_B), value(K)
(-1.0083430730335787, -0.8274042096088718, 0.9959051992930924, 0.7006452346384702, 0.20474003534537774)

docs/Project.toml Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -1.44% ⚠️

Comparison is base (86a15ca) 97.94% compared to head (3a1029c) 96.51%.

Additional details and impacted files
@@               Coverage Diff               @@
##           od/nlp-expr    #3450      +/-   ##
===============================================
- Coverage        97.94%   96.51%   -1.44%     
===============================================
  Files               37       37              
  Lines             5412     4904     -508     
===============================================
- Hits              5301     4733     -568     
- Misses             111      171      +60     
Files Changed Coverage Δ
src/nlp_expr.jl 98.69% <100.00%> (+0.21%) ⬆️

... and 32 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@odow
Copy link
Member Author

odow commented Aug 15, 2023

docs/Project.toml Outdated Show resolved Hide resolved
@odow odow merged commit 00c464c into od/nlp-expr Aug 16, 2023
10 of 11 checks passed
@odow odow deleted the od/vnf branch August 16, 2023 09:27
odow added a commit that referenced this pull request Aug 25, 2023
odow added a commit that referenced this pull request Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Nonlinear Related to nonlinear programming
Development

Successfully merging this pull request may close these issues.

3 participants