Skip to content

Commit

Permalink
working on conversion from parametric-mcp ctor format
Browse files Browse the repository at this point in the history
  • Loading branch information
dfridovi committed Nov 17, 2024
1 parent 5cdc816 commit 27debd1
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/mcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function to_symbolic_mcp(
G,
H,
unconstrained_dimension,
constrained_dimension,
constrained_dimension;
backend = SymbolicUtils.SymbolicsBackend(),
backend_options = (;)
)
Expand All @@ -45,7 +45,7 @@ function PrimalDualMCP(
G_symbolic::Vector{T},
H_symbolic::Vector{T},
x_symbolic::Vector{T},
y_symbolic::Vector{T},
y_symbolic::Vector{T};
backend = SymbolicUtils.SymbolicsBackend(),
backend_options = (;)
) where {T<:Union{FD.Node,Symbolics.Num}}
Expand Down Expand Up @@ -85,3 +85,30 @@ function PrimalDualMCP(

PrimalDualMCP(F, ∇F, length(x_symbolic), length(y_symbolic))
end

"""Construct a PrimalDualMCP from K(z) ⟂ z̲ ≤ z ≤ z̅.
NOTE: Assumes that all upper bounds are Inf, and lower bounds are either
-Inf or 0.
"""
function PrimalDualMCP(
K_symbolic::Vector{T},
z_symbolic::Vector{T},
lower_bounds::Vector,
upper_bounds::Vector;
backend_options = (;)
)
assert(
all(isinf.(lower_bounds)) &&
all(isinf.(upper_bounds) .|| upper_bounds .== 0)
)

unconstrained_indices = findall(isinf, upper_bounds)
constrained_indices = findall(!isinf, upper_bounds)

G_symbolic = K_symbolic[unconstrained_indices]
H_symbolic = K_symbolic[constrained_indices]
x_symbolic = z_symbolic[unconstrained_indices]
y_symbolic = z_symbolic[constrained_indices]

PrimalDualMCP(G_symbolic, H_symbolic, x_symbolic, y_symbolic; backend_options)
end

0 comments on commit 27debd1

Please sign in to comment.