@@ -837,7 +837,7 @@ SnoopPrecompile.@precompile_all_calls begin
837
837
),
838
838
)
839
839
@variables (model, begin
840
- x1
840
+ x1 >= 0
841
841
0 <= x2 <= 1
842
842
x3 == 2
843
843
x4, Bin
@@ -847,12 +847,12 @@ SnoopPrecompile.@precompile_all_calls begin
847
847
x8[i = 1 : 3 ; isodd (i)], (start = i)
848
848
end )
849
849
@expressions (model, begin
850
- a, x1 + x2
851
- b, x1^ 2 + x2
850
+ a, - 1 + x1 + x2
851
+ b, 1 + x1^ 2 + x2
852
852
end )
853
853
@constraints (model, begin
854
854
c1, a >= 0
855
- c2, a <= 0
855
+ c2[i = 2 : 3 , j = [ " a " ]], a <= i
856
856
c3, a == 0
857
857
c4, 0 <= a <= 1
858
858
c5, b >= 0
@@ -866,24 +866,33 @@ SnoopPrecompile.@precompile_all_calls begin
866
866
@objective (model, Min, x1)
867
867
@objective (model, Max, a)
868
868
@objective (model, Min, b)
869
- @NLconstraint (model, sin (x1) + sin (a) + sin (b) <= 1 )
869
+ @NLconstraint (model, c9, 1 * sin (x1) + 2.0 * sin (a) + sin (b) <= 1 )
870
870
@NLparameter (model, p == 2 )
871
871
@NLexpression (model, expr, x1^ p)
872
- @NLobjective (model, Min, expr)
872
+ @NLobjective (model, Min, 1 + expr)
873
873
optimize! (model)
874
874
# This block could sit in MOI, but it's a public API at the JuMP
875
875
# level, so it can go here.
876
+ #
877
+ # We evaluate with a `view` because it's a common type for solvers
878
+ # like Ipopt to use.
876
879
d = NLPEvaluator (model)
880
+ MOI. features_available (d)
877
881
MOI. initialize (d, [:Grad , :Jac , :Hess ])
878
882
g = zeros (num_nonlinear_constraints (model))
883
+ v_g = view (g, 1 : length (g))
879
884
x = zeros (num_variables (model))
880
885
MOI. eval_objective (d, x)
881
886
MOI. eval_constraint (d, g, x)
887
+ MOI. eval_constraint (d, v_g, x)
882
888
MOI. eval_objective_gradient (d, g, x)
883
889
J = zeros (length (MOI. jacobian_structure (d)))
884
890
MOI. eval_constraint_jacobian (d, J, x)
891
+ v_J = view (J, 1 : length (J))
892
+ MOI. eval_constraint_jacobian (d, v_J, x)
885
893
H = zeros (length (MOI. hessian_lagrangian_structure (d)))
886
- MOI. eval_hessian_lagrangian (d, H, x, 1.0 , g)
894
+ v_H = view (H, 1 : length (H))
895
+ MOI. eval_hessian_lagrangian (d, v_H, x, 1.0 , v_g)
887
896
end
888
897
end
889
898
end
0 commit comments