You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function MOI.eval_objective_gradient(moiproblem::MOIOptimizationProblem, G, x)
55
+
moiproblem.f.grad(G, x)
56
+
return
57
+
end
18
58
19
-
function MOI.eval_hessian_lagrangian(moiproblem::MOIOptimizationProblem{T}, h, x, σ, μ) where {T}
59
+
# This structure assumes the calculation of moiproblem.J is dense.
60
+
function MOI.jacobian_structure(moiproblem::MOIOptimizationProblem)
61
+
rows, cols =size(moiproblem.J)
62
+
return Tuple{Int,Int}[(i, j) for j in1:cols for i in1:rows]
63
+
end
64
+
65
+
function MOI.eval_constraint_jacobian(moiproblem::MOIOptimizationProblem, j, x)
66
+
ifisempty(j)
67
+
return
68
+
elseif moiproblem.f.cons_j ===nothing
69
+
error(
70
+
"Use OptimizationFunction to pass the derivatives or "*
71
+
"automatically generate them with one of the autodiff backends",
72
+
)
73
+
end
74
+
moiproblem.f.cons_j(moiproblem.J, x)
75
+
for i ineachindex(j)
76
+
j[i] = moiproblem.J[i]
77
+
end
78
+
return
79
+
end
80
+
81
+
# Because the Hessian is symmetrical, we choose to store the upper-triangular
82
+
# component. We also assume that it is dense.
83
+
function MOI.hessian_lagrangian_structure(moiproblem::MOIOptimizationProblem)
84
+
num_vars =length(moiproblem.u0)
85
+
return Tuple{Int,Int}[(row, col) for col in1:num_vars for row in1:col]
86
+
end
87
+
88
+
function MOI.eval_hessian_lagrangian(
89
+
moiproblem::MOIOptimizationProblem{T},
90
+
h,
91
+
x,
92
+
σ,
93
+
μ,
94
+
) where {T}
20
95
n =length(moiproblem.u0)
21
-
a =zeros(n, n)
22
-
moiproblem.f.hess(a, x)
23
96
ifiszero(σ)
24
97
fill!(h, zero(T))
25
98
else
@@ -47,126 +120,99 @@ function MOI.eval_hessian_lagrangian(moiproblem::MOIOptimizationProblem{T}, h, x
47
120
return
48
121
end
49
122
50
-
function MOI.eval_constraint_jacobian(moiproblem::MOIOptimizationProblem, j, x)
51
-
isempty(j) &&return
52
-
moiproblem.f.cons_j ===nothing&&error("Use OptimizationFunction to pass the derivatives or automatically generate them with one of the autodiff backends")
53
-
n =length(moiproblem.u0)
54
-
moiproblem.f.cons_j(moiproblem.J, x)
55
-
for i ineachindex(j)
56
-
j[i] = moiproblem.J[i]
57
-
end
58
-
end
59
-
60
-
function MOI.jacobian_structure(moiproblem::MOIOptimizationProblem)
61
-
return Tuple{Int,Int}[(con, var) for con in1:size(moiproblem.J,1) for var in1:size(moiproblem.J,2)]
62
-
end
63
-
64
-
function MOI.hessian_lagrangian_structure(moiproblem::MOIOptimizationProblem)
65
-
return Tuple{Int,Int}[(row, col) for col in1:length(moiproblem.u0) for row in1:col]
66
-
end
67
-
68
-
function MOI.initialize(moiproblem::MOIOptimizationProblem, requested_features::Vector{Symbol})
0 commit comments