In [1]:
using JuMP
using PyPlot
using ImplicitEquations
/usr/lib/python2.7/dist-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
WARNING: Method definition max(ValidatedNumerics.Interval, ValidatedNumerics.Interval) in module ValidatedNumerics at /home/magno/.julia/v0.4/ValidatedNumerics/src/intervals/arithmetic.jl:230 overwritten in module ImplicitEquations at /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:6.
WARNING: Method definition min(ValidatedNumerics.Interval, ValidatedNumerics.Interval) in module ValidatedNumerics at /home/magno/.julia/v0.4/ValidatedNumerics/src/intervals/arithmetic.jl:225 overwritten in module ImplicitEquations at /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:7.
WARNING: Base.MathConst is deprecated, use Base.Irrational instead.
likely near /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:221
WARNING: New definition
^(ImplicitEquations.OInterval, Real) at /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:249
is ambiguous with:
^(Real, ForwardDiff.GradientNumber) at /home/magno/.julia/v0.4/ForwardDiff/src/GradientNumber.jl:139.
To fix, define
^(ImplicitEquations.OInterval, ForwardDiff.GradientNumber)
before the new definition.
WARNING: New definition
^(ImplicitEquations.OInterval, Real) at /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:249
is ambiguous with:
^(Real, ForwardDiff.HessianNumber) at /home/magno/.julia/v0.4/ForwardDiff/src/HessianNumber.jl:209.
To fix, define
^(ImplicitEquations.OInterval, ForwardDiff.HessianNumber)
before the new definition.
WARNING: New definition
^(ImplicitEquations.OInterval, Real) at /home/magno/.julia/v0.4/ImplicitEquations/src/intervals.jl:249
is ambiguous with:
^(Real, ForwardDiff.TensorNumber) at /home/magno/.julia/v0.4/ForwardDiff/src/TensorNumber.jl:264.
To fix, define
^(ImplicitEquations.OInterval, ForwardDiff.TensorNumber)
before the new definition.
WARNING: deprecated syntax "[a=>b, ...]" at /home/magno/.julia/v0.4/ImplicitEquations/src/pyplotgraph.jl:39.
Use "Dict(a=>b, ...)" instead.
In [2]:
m = Model()
@variable m x
@variable m y
@NLobjective(m, Min, (x+1)^2 + (y-1)^2)
c1(x, y) = 2*y - 1
c2(x, y) = (1-x)*(4-x^2-y^2)
c3(x, y) = 100 - 2*x^2 - y^2
@constraint(m, 2*y - 1 == 0)
@NLconstraint(m, (1-x)*(4-x^2-y^2) <= 0)
@NLconstraint(m, 100 - 2*x^2 - y^2 >= 0)
setvalue(x, -2)
setvalue(y, 0)
m
Out[2]:
$$ \begin{alignat*}{1}\min\quad & (nonlinear expression)\\
\text{Subject to} \quad & 2 y = 1\\
& 2 nonlinear constraints\\
& x free\\
& y free\\
\end{alignat*}
$$
In [7]:
solve(m)
This is Ipopt version 3.12.1, running with linear solver mumps.
NOTE: Other linear solvers might be more efficient (see Ipopt documentation).
Number of nonzeros in equality constraint Jacobian...: 1
Number of nonzeros in inequality constraint Jacobian.: 4
Number of nonzeros in Lagrangian Hessian.............: 7
Total number of variables............................: 2
variables with only lower bounds: 0
variables with lower and upper bounds: 0
variables with only upper bounds: 0
Total number of equality constraints.................: 1
Total number of inequality constraints...............: 2
inequality constraints with only lower bounds: 1
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 1
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 2.0000000e+00 1.00e+00 1.15e-01 -1.0 0.00e+00 - 0.00e+00 0.00e+00 0
1 1.2681427e+00 0.00e+00 1.09e+00 -1.0 5.00e-01 - 9.92e-01 1.00e+00f 1
2 1.2246371e+00 0.00e+00 1.21e-04 -1.0 4.83e-01 - 1.00e+00 1.00e+00h 1
3 1.1322171e+00 0.00e+00 6.45e-04 -2.5 5.76e-01 - 1.00e+00 1.00e+00f 1
4 1.1271754e+00 0.00e+00 3.87e-06 -3.8 1.62e-02 - 1.00e+00 1.00e+00h 1
5 1.1270185e+00 0.00e+00 2.52e-09 -5.7 9.04e-04 - 1.00e+00 1.00e+00h 1
6 1.1270167e+00 0.00e+00 3.06e-13 -8.6 1.12e-05 - 1.00e+00 1.00e+00h 1
Number of Iterations....: 6
(scaled) (unscaled)
Objective...............: 1.1270166546526288e+00 1.1270166546526288e+00
Dual infeasibility......: 3.0553337637684308e-13 3.0553337637684308e-13
Constraint violation....: 0.0000000000000000e+00 0.0000000000000000e+00
Complementarity.........: 2.5058222494813427e-09 2.5058222494813427e-09
Overall NLP error.......: 2.5058222494813427e-09 2.5058222494813427e-09
Number of objective function evaluations = 7
Number of objective gradient evaluations = 7
Number of equality constraint evaluations = 7
Number of inequality constraint evaluations = 7
Number of equality constraint Jacobian evaluations = 7
Number of inequality constraint Jacobian evaluations = 7
Number of Lagrangian Hessian evaluations = 6
Total CPU secs in IPOPT (w/o function evaluations) = 0.000
Total CPU secs in NLP function evaluations = 0.000
EXIT: Optimal Solution Found.
Out[7]:
:Optimal
In [8]:
println("got ", getobjectivevalue(m), " at ", [getvalue(x),getvalue(y)])
got 1.1270166546526288 at [-1.9364916735628934,0.5]
In [ ]:
plot(c2 <= 0)
In [ ]:
Content source: lmagno/MAC0427
Similar notebooks: