Consider the NLP formulation below
Formulation:
$$ \left.\begin{array}{rrcl} \min & 100(x_2-(\frac{1}{2}+x_1)^2)^2 + (1-x_1)^2 \\ \text {s.t.:} & & & \\ \text{(1)} & x_1 \geq 0\\ \text{(2)} & x_2 \geq 0 \end{array}\right\} $$What is the (rounded) optimal solution?
In [24]:
using JuMP
m = Model()
# Adding variable
@variable(m, x[1:2] >= 0)
# Adding objective
@NLobjective(m, Min, 100 * (x[2] - (1/2 + x[1])^2)^2 + (1 - x[1])^2)
solve(m)
@printf "Optimal Value: %0.2f\n" getobjectivevalue(m)
@printf "Optimal Solution: (%0.2f, %0.2f)\n" getvalue(x)[1] getvalue(x)[2]
Consider the NLP formulation below
Formulation: $$ \left.\begin{array}{rrcl} \min & (2x_1 + 3x_2 + 4x_3)^2 \\ \text {s.t.:} & & & \\ \text{(1)} & 10x_1 + 11x_2 + 12x_3 \leq 60\\ \text{(2)} & 21x_1 + 22x_2 + 23x_3 \leq 150\\ \text{(3)} & 21x_1 + 22x_2 -23x_3 \geq 110\\ \text{(4)} & 19x_1 + 34x_2 -32x_3 = 180 \\ \text{(5)} & x_1,x_2,x_3 \geq 0 \end{array}\right\} $$
What is the (rounded) optimal solution?
In [37]:
using JuMP
nm = Model()
@variable(nm, x[1:3] >= 0)
@constraints nm begin
10x[1] + 11x[2] + 12x[3] <= 60
21x[1] + 22x[2] + 23x[3] <= 150
21x[1] + 22x[2] - 23x[3] >= 110
19x[1] + 34x[2] - 32x[3] == 180
end
@NLobjective(nm, Min, (2x[1] + 3x[2] + 4x[3])^2)
solve(nm)
@printf "Optimal Value: %0.3f\n" getobjectivevalue(nm)
@printf "Optimal Solution: (%0.2f, %0.2f, %0.2f)\n" getvalue(x)[1] getvalue(x)[2] getvalue(x)[3]
Consider the maximization of the same NLP formulation
Formulation:
$$ \left.\begin{array}{rrcl} \max & (2x_1 + 3x_2 + 4x_3)^2 \\ \text {s.t.:} & & & \\ \text{(1)} & 10x_1 + 11x_2 + 12x_3 \leq 60\\ \text{(2)} & 21x_1 + 22x_2 + 23x_3 \leq 150\\ \text{(3)} & 21x_1 + 22x_2 -23x_3 \geq 110\\ \text{(4)} & 19x_1 + 34x_2 -32x_3 = 180 \\ \text{(5)} & x_1,x_2,x_3 \geq 0 \end{array}\right\} $$What is the rounded optimal solution?
In [38]:
using JuMP
nm = Model()
@variable(nm, x[1:3] >= 0)
@constraints nm begin
10x[1] + 11x[2] + 12x[3] <= 60
21x[1] + 22x[2] + 23x[3] <= 150
21x[1] + 22x[2] - 23x[3] >= 110
19x[1] + 34x[2] - 32x[3] == 180
end
@NLobjective(nm, Max, (2x[1] + 3x[2] + 4x[3])^2)
solve(nm)
@printf "Optimal Value: %0.3f\n" getobjectivevalue(nm)
@printf "Optimal Solution: (%0.2f, %0.2f, %0.2f)\n" getvalue(x)[1] getvalue(x)[2] getvalue(x)[3]
In [ ]: