Results NLP problem

Hello. Could you clarify a question for me. I am having certain problems with my mathematical model, this model is non-linear and the ipopt is the solver chosen for the resolution of the problem. My model has its minimum and maximum limits, pmin and pmax, when using the solver it partially respects them since it reaches an optimal solution but certain values ​​minimally exceed the maximum limits, such as pmax = 180 but some values ​​reach 180.0000018 . How can I do to limit these variables to values ​​without decimals, how can I do so that if the limits are reached, these are integer values?

using JuMP,Ipopt,XLSX

us = ["Jacui","Ita","Xingo","Salto Santiago","Lajeado","Itaparica","GP Souza","Canoas II","Capivara","Chavante","Funil","Camargos","Estreito","Manso"
,"Volta Grande","Porto Primavera","Marimbondo","Agua Vermelha","Samuel","Nova Ponte"]

d=[11924 9823 9539 9396 9254 9681 10735 11931 12813 13713 14308 13127 14892 16686 16458 16088 13411 11674 11105 11674 12244 11390 10535 9823]
metas=[108 870 1581 760 543 889 157 33 319 228 108 27 662 124 228 924 701 838 132 307]

pmin = [
    1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1
    140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140 140
    250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250
    170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170
    89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89  89
    113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113  113
    22  22   22   22  22   22   22   22   22   22   22   22   22   22   22   22   22   22   22   22   22   22   22   22
    3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3   3
    39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39  39
    30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30  30
    19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19
    9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9  9
    79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79  79
    19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19  19
    29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29
    29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29  29
    62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62  62
    4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4   4
    24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24  24
    33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33  33
    ]
pmax = [
    180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180  180
    1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450 1450
    2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635 2635
    1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268 1268
    905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905 905
    1482  1482  1482  1482  1482  1482  1482  1482  1482 1482  1482  1482  1482  1482  1482  1482  1482  1482  1482  1482  1482  1482  1482  1482
    262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262  262
    56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56  56
    532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532 532
    380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380 380
    180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180 180
    46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46  46
    1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104  1104
    208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208  208
    380  380  380  380  380  380  380  380  380  380  380  380  380  380  380  380  380  380  380  380 380  380  380  380
    1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540 1540
    1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169  1169
    1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398 1398
    220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220  220
    513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513  513 513
    ]

valor_agua = [0.0036*304,0.0036*517,0.0036*351,0.0036*887,0.0036*434,0.0036*914,0.0036*2436,0.0036*804,0.0036*695,0.0036*1070,0.0036*715,0.0036*2242,0.0036*1496,0.0036*194,0.0036*1235,0.0036*472,0.0036*1073,0.0036*878,0.0036*106.5,0.0036*2129]

μ = 0.02
c_00=[7.654052483048688,40.62910891274373,31.96800105675084,9.530406772017962,115.0049118998941,48.386870152983235,2.34354793711202,2.627036394848996,18.63093278809548,4.07890572514291,5.099703248503789,10.549371263936779,10.904689524486393,7.459857028022684,10.694499834932483,40.11398550553216,63.36789930537633,25.18352774321871,14.144017305549545,10.84673263581038]
c_10=[0.892362529923684,0.9432654477458005,0.8218848297576222,1.053776436577942,2.7366057154026873,1.9400889416028784,0.15268218429693264,6.67235493471428,2.5023123226385535,1.448444294223902,1.6969986757777689,3.8816000432889375,1.5940558126085134,1.6798486102276515,3.4983288807513486,4.677474604738309,1.6809127962695842,1.7959703284343882,3.1968915809440226,0.9556199774266778]
c_20=[0.0015737422140654617,0.00013596507465868818,5.607056623632372e-05,0.00017923047649544608,0.0007023209416358729,0.00027822366537762276,0.0001455034168815677,0.020963716840235052,0.0010175800823603272,0.00083654906236899,0.0020053516881876014,0.014807233540011597,0.0003250711763358595,0.0017329078541697622,0.0019636755066780617,0.0010966877092086073,0.00042246653492786397,0.0002968271707442997,0.004750879880736467,0.0003930043398122151]

model = Model(Ipopt.Optimizer)

nus = length(us)
nd = length(d)

@variables(model, begin
    p[i=1:nus, t=1:nd]
    z[t=1:nd] >= 0
end)

@NLobjective(
    model,
    Min,
    sum(
        sum(
            valor_agua[i] * (
                c_00[i] +
                c_10[i] * p[i, t] +
                c_20[i] * p[i, t]^2)
            for i = 1:nus
        ) + μ * z[t]^2
        for t = 1:nd
    )
)
@constraints(model, begin
[i=1:nus, t=1:nd], pmin[i, t]  <= p[i, t]
[i=1:nus, t=1:nd], p[i, t] <= pmax[i, t]
    [t=1:nd], sum(p[:, t]) + z[t] == d[t]
    [i=1:nus], sum(p[i, :]) == 24 * metas[i]
end)

print(model)
optimize!(model)
@show value.(p)
@show value.(p)
@show value.(n)
@show value.(z)

From Ipopt’s perspective these two numbers 180 and 180.0000018 are identical. You can check:
isapprox(180,180.0000018;atol=1e-5)
gives true, but
isapprox(180,180.0000018;atol=1e-6)
gives false.
You can probably play around with tolerances in Ipopt using set_optimizer_attribute (Models · JuMP) - most of the options (all of them) available for ipopt should be accessible from JuMP (Ipopt: Ipopt Options), but Ipopt doesn’t support integer variables, so you may always end up with x.00000000xx

3 Likes