Skip to content

Commit b365961

Browse files
committed
Add availability flags in NLPModelMeta and NLSMeta
1 parent 11b0bc6 commit b365961

File tree

4 files changed

+140
-71
lines changed

4 files changed

+140
-71
lines changed

README.md

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,38 +84,46 @@ The complete list of methods that an interface may implement can be found in the
8484

8585
`NLPModelMeta` objects have the following attributes (with `S <: AbstractVector`):
8686

87-
Attribute | Type | Notes
88-
------------|--------------------|------------------------------------
89-
`nvar` | `Int ` | number of variables
90-
`x0 ` | `S` | initial guess
91-
`lvar` | `S` | vector of lower bounds
92-
`uvar` | `S` | vector of upper bounds
93-
`ifix` | `Vector{Int}` | indices of fixed variables
94-
`ilow` | `Vector{Int}` | indices of variables with lower bound only
95-
`iupp` | `Vector{Int}` | indices of variables with upper bound only
96-
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
97-
`ifree` | `Vector{Int}` | indices of free variables
98-
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
99-
`ncon` | `Int ` | total number of general constraints
100-
`nlin ` | `Int ` | number of linear constraints
101-
`nnln` | `Int ` | number of nonlinear general constraints
102-
`y0 ` | `S` | initial Lagrange multipliers
103-
`lcon` | `S` | vector of constraint lower bounds
104-
`ucon` | `S` | vector of constraint upper bounds
105-
`lin ` | `Vector{Int}` | indices of linear constraints
106-
`nln` | `Vector{Int}` | indices of nonlinear constraints
107-
`jfix` | `Vector{Int}` | indices of equality constraints
108-
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
109-
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
110-
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
111-
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
112-
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
113-
`nnzo` | `Int ` | number of nonzeros in the gradient
114-
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
115-
`nnzh` | `Int ` | number of nonzeros in the sparse Hessian
116-
`minimize` | `Bool ` | true if `optimize == minimize`
117-
`islp` | `Bool ` | true if the problem is a linear program
118-
`name` | `String` | problem name
87+
Attribute | Type | Notes
88+
---------------------|---------------|------------------------------------
89+
`nvar` | `Int` | number of variables
90+
`x0 ` | `S` | initial guess
91+
`lvar` | `S` | vector of lower bounds
92+
`uvar` | `S` | vector of upper bounds
93+
`ifix` | `Vector{Int}` | indices of fixed variables
94+
`ilow` | `Vector{Int}` | indices of variables with lower bound only
95+
`iupp` | `Vector{Int}` | indices of variables with upper bound only
96+
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
97+
`ifree` | `Vector{Int}` | indices of free variables
98+
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
99+
`ncon` | `Int` | total number of general constraints
100+
`nlin ` | `Int` | number of linear constraints
101+
`nnln` | `Int` | number of nonlinear general constraints
102+
`y0 ` | `S` | initial Lagrange multipliers
103+
`lcon` | `S` | vector of constraint lower bounds
104+
`ucon` | `S` | vector of constraint upper bounds
105+
`lin ` | `Vector{Int}` | indices of linear constraints
106+
`nln` | `Vector{Int}` | indices of nonlinear constraints
107+
`jfix` | `Vector{Int}` | indices of equality constraints
108+
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
109+
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
110+
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
111+
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
112+
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
113+
`nnzo` | `Int` | number of nonzeros in the gradient
114+
`nnzj` | `Int` | number of nonzeros in the sparse Jacobian
115+
`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian
116+
`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian
117+
`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
118+
`minimize` | `Bool` | true if `optimize == minimize`
119+
`islp` | `Bool` | true if the problem is a linear program
120+
`name` | `String` | problem name
121+
`gradient_available` | `Bool` | true if the gradient of the objective is available
122+
`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available
123+
`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available
124+
`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available
125+
`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available
126+
`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available
119127

120128
# Bug reports and discussions
121129

docs/src/index.md

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -79,40 +79,46 @@ See the [Models](@ref), the [Tools](@ref tools-section), or the [API](@ref).
7979

8080
`NLPModelMeta` objects have the following attributes (with `S <: AbstractVector`):
8181

82-
Attribute | Type | Notes
83-
------------|--------------------|------------------------------------
84-
`nvar` | `Int ` | number of variables
85-
`x0 ` | `S` | initial guess
86-
`lvar` | `S` | vector of lower bounds
87-
`uvar` | `S` | vector of upper bounds
88-
`ifix` | `Vector{Int}` | indices of fixed variables
89-
`ilow` | `Vector{Int}` | indices of variables with lower bound only
90-
`iupp` | `Vector{Int}` | indices of variables with upper bound only
91-
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
92-
`ifree` | `Vector{Int}` | indices of free variables
93-
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
94-
`ncon` | `Int ` | total number of general constraints
95-
`nlin ` | `Int ` | number of linear constraints
96-
`nnln` | `Int ` | number of nonlinear general constraints
97-
`y0 ` | `S` | initial Lagrange multipliers
98-
`lcon` | `S` | vector of constraint lower bounds
99-
`ucon` | `S` | vector of constraint upper bounds
100-
`lin ` | `Vector{Int}` | indices of linear constraints
101-
`nln` | `Vector{Int}` | indices of nonlinear constraints
102-
`jfix` | `Vector{Int}` | indices of equality constraints
103-
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
104-
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
105-
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
106-
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
107-
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
108-
`nnzo` | `Int ` | number of nonzeros in the gradient
109-
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
110-
`lin_nnzj` | `Int ` | number of nonzeros in the sparse linear constraints Jacobian
111-
`nln_nnzj` | `Int ` | number of nonzeros in the sparse nonlinear constraints Jacobian
112-
`nnzh` | `Int ` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
113-
`minimize` | `Bool ` | true if `optimize == minimize`
114-
`islp` | `Bool ` | true if the problem is a linear program
115-
`name` | `String` | problem name
82+
Attribute | Type | Notes
83+
---------------------|---------------|------------------------------------
84+
`nvar` | `Int` | number of variables
85+
`x0 ` | `S` | initial guess
86+
`lvar` | `S` | vector of lower bounds
87+
`uvar` | `S` | vector of upper bounds
88+
`ifix` | `Vector{Int}` | indices of fixed variables
89+
`ilow` | `Vector{Int}` | indices of variables with lower bound only
90+
`iupp` | `Vector{Int}` | indices of variables with upper bound only
91+
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
92+
`ifree` | `Vector{Int}` | indices of free variables
93+
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
94+
`ncon` | `Int` | total number of general constraints
95+
`nlin ` | `Int` | number of linear constraints
96+
`nnln` | `Int` | number of nonlinear general constraints
97+
`y0 ` | `S` | initial Lagrange multipliers
98+
`lcon` | `S` | vector of constraint lower bounds
99+
`ucon` | `S` | vector of constraint upper bounds
100+
`lin ` | `Vector{Int}` | indices of linear constraints
101+
`nln` | `Vector{Int}` | indices of nonlinear constraints
102+
`jfix` | `Vector{Int}` | indices of equality constraints
103+
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
104+
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
105+
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
106+
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
107+
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
108+
`nnzo` | `Int` | number of nonzeros in the gradient
109+
`nnzj` | `Int` | number of nonzeros in the sparse Jacobian
110+
`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian
111+
`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian
112+
`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
113+
`minimize` | `Bool` | true if `optimize == minimize`
114+
`islp` | `Bool` | true if the problem is a linear program
115+
`name` | `String` | problem name
116+
`gradient_available` | `Bool` | true if the gradient of the objective is available
117+
`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available
118+
`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available
119+
`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available
120+
`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available
121+
`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available
116122

117123
## License
118124

src/nlp/meta.jl

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ The following keyword arguments are accepted:
5151
- `minimize`: true if optimize == minimize
5252
- `islp`: true if the problem is a linear program
5353
- `name`: problem name
54+
- `gradient_available`: indicates whether the gradient of the objective is available
55+
- `jacobian_available`: indicates whether the sparse Jacobian of the constraints is available
56+
- `hessian_available`: indicates whether the sparse Hessian of the Lagrangian is available
57+
- `Jv_available`: indicates whether the Jacobian-vector product `J * v` is available
58+
- `Jtv_available`: indicates whether the transpose Jacobian-vector product `J' * v` is available
59+
- `Hv_available`: indicates whether the Hessian-vector product of the Lagrangian `H * v` is available
5460
5561
`NLPModelMeta` also contains the following attributes, which are computed from the variables above:
5662
- `nvar`: number of variables
@@ -114,6 +120,13 @@ struct NLPModelMeta{T, S} <: AbstractNLPModelMeta{T, S}
114120
minimize::Bool
115121
islp::Bool
116122
name::String
123+
124+
gradient_available::Bool
125+
jacobian_available::Bool
126+
hessian_available::Bool
127+
Jv_available::Bool
128+
Jtv_available::Bool
129+
Hv_available::Bool
117130
end
118131

119132
function NLPModelMeta{T, S}(
@@ -134,9 +147,15 @@ function NLPModelMeta{T, S}(
134147
nln_nnzj = nnzj - lin_nnzj,
135148
nnzh = nvar * (nvar + 1) / 2,
136149
lin = Int[],
137-
minimize = true,
138-
islp = false,
150+
minimize::Bool = true,
151+
islp::Bool = false,
139152
name = "Generic",
153+
gradient_available::Bool = true,
154+
jacobian_available::Bool = true,
155+
hessian_available::Bool = true,
156+
Jv_available::Bool = true,
157+
Jtv_available::Bool = true,
158+
Hv_available::Bool = true,
140159
) where {T, S}
141160
if (nvar < 1) || (ncon < 0)
142161
error("Nonsensical dimensions")
@@ -213,6 +232,12 @@ function NLPModelMeta{T, S}(
213232
minimize,
214233
islp,
215234
name,
235+
gradient_available,
236+
jacobian_available,
237+
hessian_available,
238+
Jv_available,
239+
Jtv_available,
240+
Hv_available,
216241
)
217242
end
218243

@@ -238,9 +263,15 @@ function NLPModelMeta(
238263
nln_nnzj = meta.nln_nnzj,
239264
nnzh = meta.nnzh,
240265
lin = meta.lin,
241-
minimize = meta.minimize,
242-
islp = meta.islp,
266+
minimize::Bool = meta.minimize,
267+
islp::Bool = meta.islp,
243268
name = meta.name,
269+
gradient_available::Bool = meta.gradient_available,
270+
jacobian_available::Bool = meta.jacobian_available,
271+
hessian_available::Bool = meta.hessian_available,
272+
Jv_available::Bool = meta.Jv_available,
273+
Jtv_available::Bool = meta.Jtv_available,
274+
Hv_available::Bool = meta.Hv_available,
244275
) where {T, S}
245276
NLPModelMeta{T, S}(
246277
nvar,
@@ -263,6 +294,12 @@ function NLPModelMeta(
263294
minimize = minimize,
264295
islp = islp,
265296
name = name,
297+
gradient_available = gradient_available,
298+
jacobian_available = jacobian_available,
299+
hessian_available = hessian_available,
300+
Jv_available = Jv_available,
301+
Jtv_available = Jtv_available,
302+
Hv_available = Hv_available,
266303
)
267304
end
268305

src/nls/meta.jl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ The following keyword arguments are accepted:
1515
- `nnzj`: number of elements needed to store the nonzeros of the Jacobian of the residual
1616
- `nnzh`: number of elements needed to store the nonzeros of the sum of Hessians of the residuals
1717
- `lin`: indices of linear residuals
18+
- `jacobian_residual_available`: indicates whether the sparse Jacobian of the residuals is available
19+
- `hessian_residual_available`: indicates whether the sum of the sparse Hessians of the residuals is available
20+
- `Jv_residual_available`: indicates whether the Jacobian-vector product for the residuals is available
21+
- `Jtv_residual_available`: indicates whether the transpose Jacobian-vector product for the residuals is available
22+
- `Hv_residual_available`: indicates whether the sum of Hessian-vector product for the residuals is available
1823
1924
`NLSMeta` also contains the following attributes, which are computed from the variables above:
2025
- `nequ`: size of the residual
@@ -35,13 +40,24 @@ struct NLSMeta{T, S}
3540
lin::Vector{Int} # List of linear residuals
3641
nlin::Int # = length(lin)
3742

43+
jacobian_residual_available::Bool
44+
hessian_residual_available::Bool
45+
Jv_residual_available::Bool
46+
Jtv_residual_available::Bool
47+
Hv_residual_available::Bool
48+
3849
function NLSMeta{T, S}(
3950
nequ::Int,
4051
nvar::Int;
4152
x0::S = fill!(S(undef, nvar), zero(T)),
4253
nnzj = nequ * nvar,
4354
nnzh = div(nvar * (nvar + 1), 2),
4455
lin = Int[],
56+
jacobian_residual_available::Bool = true,
57+
hessian_residual_available::Bool = true,
58+
Jv_residual_available::Bool = true,
59+
Jtv_residual_available::Bool = true,
60+
Hv_residual_available::Bool = true,
4561
) where {T, S}
4662
nnzj = max(0, nnzj)
4763
nnzh = max(0, nnzh)
@@ -50,7 +66,9 @@ struct NLSMeta{T, S}
5066
nlin = length(lin)
5167
nnln = length(nln)
5268

53-
return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin)
69+
return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin,
70+
jacobian_residual_available, hessian_residual_available, Jv_residual_available,
71+
Jtv_residual_available, Hv_residual_available)
5472
end
5573
end
5674

0 commit comments

Comments
 (0)