Hi,
I am solving an optimization problem of the following interface:
find max A such that
x^A + y < = 100 for all 0 <= x <= y <= 1
How can I write the following type of constraint in JuMP? And how it is better to define that for non-integer parameter A we set 0^A == 0?
1 Like
Isn’t the answer A = \infty ? 1^\infty + 1 = 2 \le 100 .
2 Likes
Thank you for your reply,
yes , it’s better to change the 1 in constraint condition by 2, for example :).
In which case the answer is the solution to 2^A + 2 = 100 \implies A = \log_2 98 .
I’ve wrote in the beginning that this problem is just similar to mine in interface. Of course, no need to use computers to solve directly the problem I’ve mentioned. I want to know the sintaxis of writing constraint in JuMP of the mentioned type.
1 Like
odow
August 24, 2022, 9:53pm
6
You generally can’t write “for all” constraints in JuMP (that’s just not the way that solvers work).
You could write the inverse of the problem though. Find the minimum A
such that the constraint is violated.
julia> using JuMP
julia> import Ipopt
julia> model = Model(Ipopt.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Ipopt
julia> @variable(model, A >= 0.0)
A
julia> @variable(model, 0 <= x <= 2, start = 2)
x
julia> @variable(model, 0 <= y <= 2, start = 2)
y
julia> @NLconstraint(model, x^A + y >= 100)
(x ^ A + y) - 100.0 ≥ 0
julia> @objective(model, Min, A)
A
julia> optimize!(model)
This is Ipopt version 3.14.4, running with linear solver MUMPS 5.4.1.
Number of nonzeros in equality constraint Jacobian...: 0
Number of nonzeros in inequality constraint Jacobian.: 3
Number of nonzeros in Lagrangian Hessian.............: 3
Total number of variables............................: 3
variables with only lower bounds: 1
variables with lower and upper bounds: 2
variables with only upper bounds: 0
Total number of equality constraints.................: 0
Total number of inequality constraints...............: 1
inequality constraints with only lower bounds: 1
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 9.9999900e-03 9.70e+01 5.96e-01 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.6878344e-02 9.70e+01 1.04e+00 -1.0 5.56e+01 - 5.11e-04 3.53e-04h 1
2 1.4884628e+00 9.52e+01 2.37e+00 -1.0 1.40e+02 - 1.28e-04 1.05e-02h 1
3 7.6262848e+00 0.00e+00 2.76e+03 -1.0 4.91e+01 - 5.89e-02 1.25e-01h 4
4 7.6104472e+00 0.00e+00 1.59e+03 -1.0 1.23e-01 4.0 8.93e-02 1.00e+00h 1
5 7.6082893e+00 0.00e+00 2.89e+02 -1.0 3.65e-02 3.5 1.00e+00 1.00e+00h 1
6 7.6072385e+00 0.00e+00 5.54e+00 -1.0 4.09e-03 3.0 1.00e+00 1.00e+00h 1
7 7.6048327e+00 0.00e+00 3.52e+00 -1.0 9.51e-03 2.6 1.00e+00 1.00e+00f 1
8 6.4266817e+00 1.25e+01 3.79e+00 -1.0 8.60e+00 - 9.94e-01 1.37e-01f 1
9 6.7946110e+00 0.00e+00 1.03e+00 -1.0 2.82e+00 - 1.00e+00 1.00e+00f 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
10 6.8204764e+00 0.00e+00 2.01e-02 -1.0 3.81e+00 - 1.00e+00 1.00e+00h 1
11 6.6382699e+00 0.00e+00 1.87e-02 -2.5 6.93e+00 - 9.64e-01 9.59e-01f 1
12 6.6153426e+00 0.00e+00 4.30e-03 -3.8 8.16e-01 - 8.22e-01 1.00e+00h 1
13 6.6151594e+00 0.00e+00 7.80e-08 -3.8 8.22e-03 - 1.00e+00 1.00e+00h 1
14 6.6147160e+00 0.00e+00 1.30e-07 -5.7 1.01e-02 - 1.00e+00 1.00e+00h 1
15 6.6147098e+00 0.00e+00 2.80e-11 -8.6 1.74e-04 - 1.00e+00 1.00e+00h 1
Number of Iterations....: 15
(scaled) (unscaled)
Objective...............: 6.6147097558501411e+00 6.6147097558501411e+00
Dual infeasibility......: 2.8009594643663149e-11 2.8009594643663149e-11
Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00
Variable bound violation: 1.9474300838595582e-08 1.9474300838595582e-08
Complementarity.........: 2.5931984733449229e-09 2.5931984733449229e-09
Overall NLP error.......: 2.5931984733449229e-09 2.5931984733449229e-09
Number of objective function evaluations = 18
Number of objective gradient evaluations = 16
Number of equality constraint evaluations = 0
Number of inequality constraint evaluations = 21
Number of equality constraint Jacobian evaluations = 0
Number of inequality constraint Jacobian evaluations = 16
Number of Lagrangian Hessian evaluations = 15
Total seconds in IPOPT = 0.009
EXIT: Optimal Solution Found.
julia> value(A)
6.614709755850141
julia> log2(98)
6.614709844115208
3 Likes