Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,46 @@ The complete list of methods that an interface may implement can be found in the

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

Attribute | Type | Notes
------------|--------------------|------------------------------------
`nvar` | `Int ` | number of variables
`x0 ` | `S` | initial guess
`lvar` | `S` | vector of lower bounds
`uvar` | `S` | vector of upper bounds
`ifix` | `Vector{Int}` | indices of fixed variables
`ilow` | `Vector{Int}` | indices of variables with lower bound only
`iupp` | `Vector{Int}` | indices of variables with upper bound only
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
`ifree` | `Vector{Int}` | indices of free variables
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
`ncon` | `Int ` | total number of general constraints
`nlin ` | `Int ` | number of linear constraints
`nnln` | `Int ` | number of nonlinear general constraints
`y0 ` | `S` | initial Lagrange multipliers
`lcon` | `S` | vector of constraint lower bounds
`ucon` | `S` | vector of constraint upper bounds
`lin ` | `Vector{Int}` | indices of linear constraints
`nln` | `Vector{Int}` | indices of nonlinear constraints
`jfix` | `Vector{Int}` | indices of equality constraints
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
`nnzo` | `Int ` | number of nonzeros in the gradient
`nnzh` | `Int ` | number of nonzeros in the sparse Hessian
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
`lin_nnzj` | `Int ` | number of nonzeros in the linear part of sparse Jacobian
`nln_nnzj` | `Int ` | number of nonzeros in the nonlinear part of sparse Jacobian
`minimize` | `Bool ` | true if `optimize == minimize`
`islp` | `Bool ` | true if the problem is a linear program
`name` | `String` | problem name
Attribute | Type | Notes
---------------------|---------------|------------------------------------
`nvar` | `Int` | number of variables
`x0 ` | `S` | initial guess
`lvar` | `S` | vector of lower bounds
`uvar` | `S` | vector of upper bounds
`ifix` | `Vector{Int}` | indices of fixed variables
`ilow` | `Vector{Int}` | indices of variables with lower bound only
`iupp` | `Vector{Int}` | indices of variables with upper bound only
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
`ifree` | `Vector{Int}` | indices of free variables
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
`ncon` | `Int` | total number of general constraints
`nlin ` | `Int` | number of linear constraints
`nnln` | `Int` | number of nonlinear general constraints
`y0 ` | `S` | initial Lagrange multipliers
`lcon` | `S` | vector of constraint lower bounds
`ucon` | `S` | vector of constraint upper bounds
`lin ` | `Vector{Int}` | indices of linear constraints
`nln` | `Vector{Int}` | indices of nonlinear constraints
`jfix` | `Vector{Int}` | indices of equality constraints
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
`nnzo` | `Int` | number of nonzeros in the gradient
`nnzj` | `Int` | number of nonzeros in the sparse Jacobian
`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian
`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian
`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
`minimize` | `Bool` | true if `optimize == minimize`
`islp` | `Bool` | true if the problem is a linear program
`name` | `String` | problem name
`gradient_available` | `Bool` | true if the gradient of the objective is available
`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available
`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available
`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available
`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available
`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available

# Bug reports and discussions

Expand Down
74 changes: 40 additions & 34 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,40 +79,46 @@ See the [Models](@ref), the [Tools](@ref tools-section), or the [API](@ref).

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

Attribute | Type | Notes
------------|--------------------|------------------------------------
`nvar` | `Int ` | number of variables
`x0 ` | `S` | initial guess
`lvar` | `S` | vector of lower bounds
`uvar` | `S` | vector of upper bounds
`ifix` | `Vector{Int}` | indices of fixed variables
`ilow` | `Vector{Int}` | indices of variables with lower bound only
`iupp` | `Vector{Int}` | indices of variables with upper bound only
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
`ifree` | `Vector{Int}` | indices of free variables
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
`ncon` | `Int ` | total number of general constraints
`nlin ` | `Int ` | number of linear constraints
`nnln` | `Int ` | number of nonlinear general constraints
`y0 ` | `S` | initial Lagrange multipliers
`lcon` | `S` | vector of constraint lower bounds
`ucon` | `S` | vector of constraint upper bounds
`lin ` | `Vector{Int}` | indices of linear constraints
`nln` | `Vector{Int}` | indices of nonlinear constraints
`jfix` | `Vector{Int}` | indices of equality constraints
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
`nnzo` | `Int ` | number of nonzeros in the gradient
`nnzj` | `Int ` | number of nonzeros in the sparse Jacobian
`lin_nnzj` | `Int ` | number of nonzeros in the sparse linear constraints Jacobian
`nln_nnzj` | `Int ` | number of nonzeros in the sparse nonlinear constraints Jacobian
`nnzh` | `Int ` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
`minimize` | `Bool ` | true if `optimize == minimize`
`islp` | `Bool ` | true if the problem is a linear program
`name` | `String` | problem name
Attribute | Type | Notes
---------------------|---------------|------------------------------------
`nvar` | `Int` | number of variables
`x0 ` | `S` | initial guess
`lvar` | `S` | vector of lower bounds
`uvar` | `S` | vector of upper bounds
`ifix` | `Vector{Int}` | indices of fixed variables
`ilow` | `Vector{Int}` | indices of variables with lower bound only
`iupp` | `Vector{Int}` | indices of variables with upper bound only
`irng` | `Vector{Int}` | indices of variables with lower and upper bound (range)
`ifree` | `Vector{Int}` | indices of free variables
`iinf` | `Vector{Int}` | indices of visibly infeasible bounds
`ncon` | `Int` | total number of general constraints
`nlin ` | `Int` | number of linear constraints
`nnln` | `Int` | number of nonlinear general constraints
`y0 ` | `S` | initial Lagrange multipliers
`lcon` | `S` | vector of constraint lower bounds
`ucon` | `S` | vector of constraint upper bounds
`lin ` | `Vector{Int}` | indices of linear constraints
`nln` | `Vector{Int}` | indices of nonlinear constraints
`jfix` | `Vector{Int}` | indices of equality constraints
`jlow` | `Vector{Int}` | indices of constraints of the form c(x) ≥ cl
`jupp` | `Vector{Int}` | indices of constraints of the form c(x) ≤ cu
`jrng` | `Vector{Int}` | indices of constraints of the form cl ≤ c(x) ≤ cu
`jfree` | `Vector{Int}` | indices of "free" constraints (there shouldn't be any)
`jinf` | `Vector{Int}` | indices of the visibly infeasible constraints
`nnzo` | `Int` | number of nonzeros in the gradient
`nnzj` | `Int` | number of nonzeros in the sparse Jacobian
`lin_nnzj` | `Int` | number of nonzeros in the sparse linear constraints Jacobian
`nln_nnzj` | `Int` | number of nonzeros in the sparse nonlinear constraints Jacobian
`nnzh` | `Int` | number of nonzeros in the lower triangular part of the sparse Hessian of the Lagrangian
`minimize` | `Bool` | true if `optimize == minimize`
`islp` | `Bool` | true if the problem is a linear program
`name` | `String` | problem name
`gradient_available` | `Bool` | true if the gradient of the objective is available
`jacobian_available` | `Bool` | true if the sparse Jacobian of the constraints is available
`hessian_available` | `Bool` | true if the sparse Hessian of the Lagrangian is available
`Jv_available` | `Bool` | true if the Jacobian-vector product `J * v` is available
`Jtv_available` | `Bool` | true if the transpose Jacobian-vector product `J' * v` is available
`Hv_available` | `Bool` | true if the Hessian-vector product of the Lagrangian `H * v` is available

## License

Expand Down
45 changes: 41 additions & 4 deletions src/nlp/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ The following keyword arguments are accepted:
- `minimize`: true if optimize == minimize
- `islp`: true if the problem is a linear program
- `name`: problem name
- `gradient_available`: indicates whether the gradient of the objective is available
- `jacobian_available`: indicates whether the sparse Jacobian of the constraints is available
- `hessian_available`: indicates whether the sparse Hessian of the Lagrangian is available
- `Jv_available`: indicates whether the Jacobian-vector product `J * v` is available
- `Jtv_available`: indicates whether the transpose Jacobian-vector product `J' * v` is available
- `Hv_available`: indicates whether the Hessian-vector product of the Lagrangian `H * v` is available

`NLPModelMeta` also contains the following attributes, which are computed from the variables above:
- `nvar`: number of variables
Expand Down Expand Up @@ -114,6 +120,13 @@ struct NLPModelMeta{T, S} <: AbstractNLPModelMeta{T, S}
minimize::Bool
islp::Bool
name::String

gradient_available::Bool
jacobian_available::Bool
hessian_available::Bool
Jv_available::Bool
Jtv_available::Bool
Hv_available::Bool
end

function NLPModelMeta{T, S}(
Expand All @@ -134,9 +147,15 @@ function NLPModelMeta{T, S}(
nln_nnzj = nnzj - lin_nnzj,
nnzh = nvar * (nvar + 1) / 2,
lin = Int[],
minimize = true,
islp = false,
minimize::Bool = true,
islp::Bool = false,
name = "Generic",
gradient_available::Bool = true,
jacobian_available::Bool = true,
hessian_available::Bool = true,
Jv_available::Bool = true,
Jtv_available::Bool = true,
Hv_available::Bool = true,
) where {T, S}
if (nvar < 1) || (ncon < 0)
error("Nonsensical dimensions")
Expand Down Expand Up @@ -213,6 +232,12 @@ function NLPModelMeta{T, S}(
minimize,
islp,
name,
gradient_available,
jacobian_available,
hessian_available,
Jv_available,
Jtv_available,
Hv_available,
)
end

Expand All @@ -238,9 +263,15 @@ function NLPModelMeta(
nln_nnzj = meta.nln_nnzj,
nnzh = meta.nnzh,
lin = meta.lin,
minimize = meta.minimize,
islp = meta.islp,
minimize::Bool = meta.minimize,
islp::Bool = meta.islp,
name = meta.name,
gradient_available::Bool = meta.gradient_available,
jacobian_available::Bool = meta.jacobian_available,
hessian_available::Bool = meta.hessian_available,
Jv_available::Bool = meta.Jv_available,
Jtv_available::Bool = meta.Jtv_available,
Hv_available::Bool = meta.Hv_available,
) where {T, S}
NLPModelMeta{T, S}(
nvar,
Expand All @@ -263,6 +294,12 @@ function NLPModelMeta(
minimize = minimize,
islp = islp,
name = name,
gradient_available = gradient_available,
jacobian_available = jacobian_available,
hessian_available = hessian_available,
Jv_available = Jv_available,
Jtv_available = Jtv_available,
Hv_available = Hv_available,
)
end

Expand Down
20 changes: 19 additions & 1 deletion src/nls/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ The following keyword arguments are accepted:
- `nnzj`: number of elements needed to store the nonzeros of the Jacobian of the residual
- `nnzh`: number of elements needed to store the nonzeros of the sum of Hessians of the residuals
- `lin`: indices of linear residuals
- `jacobian_residual_available`: indicates whether the sparse Jacobian of the residuals is available
- `hessian_residual_available`: indicates whether the sum of the sparse Hessians of the residuals is available
- `Jv_residual_available`: indicates whether the Jacobian-vector product for the residuals is available
- `Jtv_residual_available`: indicates whether the transpose Jacobian-vector product for the residuals is available
- `Hv_residual_available`: indicates whether the sum of Hessian-vector product for the residuals is available

`NLSMeta` also contains the following attributes, which are computed from the variables above:
- `nequ`: size of the residual
Expand All @@ -35,13 +40,24 @@ struct NLSMeta{T, S}
lin::Vector{Int} # List of linear residuals
nlin::Int # = length(lin)

jacobian_residual_available::Bool
hessian_residual_available::Bool
Jv_residual_available::Bool
Jtv_residual_available::Bool
Hv_residual_available::Bool

function NLSMeta{T, S}(
nequ::Int,
nvar::Int;
x0::S = fill!(S(undef, nvar), zero(T)),
nnzj = nequ * nvar,
nnzh = div(nvar * (nvar + 1), 2),
lin = Int[],
jacobian_residual_available::Bool = true,
hessian_residual_available::Bool = true,
Jv_residual_available::Bool = true,
Jtv_residual_available::Bool = true,
Hv_residual_available::Bool = true,
) where {T, S}
nnzj = max(0, nnzj)
nnzh = max(0, nnzh)
Expand All @@ -50,7 +66,9 @@ struct NLSMeta{T, S}
nlin = length(lin)
nnln = length(nln)

return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin)
return new{T, S}(nequ, nvar, x0, nnzj, nnzh, nln, nnln, lin, nlin,
jacobian_residual_available, hessian_residual_available, Jv_residual_available,
Jtv_residual_available, Hv_residual_available)
end
end

Expand Down
Loading