API Reference
This page documents the public API of LinearDecisionRules.jl.
Model
LinearDecisionRules.LDRModel — Type
LDRModelMain model type for Linear Decision Rules optimization problems.
Examples
using LinearDecisionRules
import Distributions
using JuMP
import HiGHS
model = LDRModel(HiGHS.Optimizer)
@variable(
model,
x >= 0,
Uncertainty(distribution = Distributions.Normal(10.0, 2.0)),
)
@variable(model, y >= 0, FirstStage())
@objective(model, Min, x + y)
@constraint(model, x + 2y >= 20)
optimize!(model)
println("Objective value: ", objective_value(model))Variable Attributes
LinearDecisionRules.FirstStage — Type
FirstStageAttribute to declare first-stage decision variables. These variables are decided before the uncertainty is revealed.
Example
@variable(model, y >= 0, FirstStage)LinearDecisionRules.Uncertainty — Function
Uncertainty(; distribution)Declare an uncertain parameter with a specified probability distribution. The distribution must have finite bounds.
Arguments
distribution: aDistributions.jlunivariate or multivariate distribution
Example
import Distributions
# Scalar uncertainty
@variable(ldr, demand in LinearDecisionRules.Uncertainty(
distribution = Distributions.Uniform(80, 120),
))
# Vector uncertainty (independent components)
@variable(ldr, inflow[1:2] in LinearDecisionRules.Uncertainty(
distribution = Distributions.product_distribution([
Distributions.Uniform(0, 10),
Distributions.Uniform(0, 20),
]),
))Note
Uncertain parameters declared as different @variables are assumed to be independent. So, the last example is equivalent to declaring two separate scalar uncertainties with uniform distributions.
import Distributions
@variable(ldr, inflow1 in LinearDecisionRules.Uncertainty(
distribution = Distributions.Uniform(0, 10),
))
@variable(ldr, inflow2 in LinearDecisionRules.Uncertainty(
distribution = Distributions.Uniform(0, 20),
))LinearDecisionRules.BreakPoints — Type
BreakPointsAttribute to get/set the breakpoints for piecewise linear approximation of the recourse function associated with a variable.
If set to nothing, the piecewise linear approximation is removed.
If set to a Vector{Float64}, the breakpoints are set to the given values.
If set to an Integer, the breakpoints are set to that number of equally spaced points between the minimum and maximum of the uncertainty distribution associated with the variable.
Example
set_attribute(
x,
LinearDecisionRules.BreakPoints(),
3
)
# If the support of `x` is [6.0, 14.0], this is equivalent to
set_attribute(
x,
LinearDecisionRules.BreakPoints(),
[8.0, 10.0, 12.0],
)Model Attributes
LinearDecisionRules.SolvePrimal — Type
SolvePrimalAttribute to get/set whether to solve the primal LDR model.
Example
set_attribute(
model,
LinearDecisionRules.SolvePrimal(),
false,
)LinearDecisionRules.SolveDual — Type
SolveDualAttribute to get/set whether to solve the dual LDR model.
Example
set_attribute(
model,
LinearDecisionRules.SolveDual(),
false,
)Solution Queries
LinearDecisionRules.get_decision — Function
get_decision(m::LDRModel, x, η; dual = false, sampled = false, piece = nothing)Return the coefficient of uncertainty η in the linear decision rule for x.
Arguments
m: theLDRModelx: the decision variableη: the uncertainty variabledual = false: iftrue, return the coefficient from the dual solutionsampled = false: iftrue, return the coefficient from the sampled (SAA) solutionpiece = nothing: for piecewise linear rules, the piece index (1-indexed); required when breakpoints have been set onη
Example
x1 = LinearDecisionRules.get_decision(ldr, sell, demand)
# Decision rule: sell(demand) = x0 + x1 * demand
# For a piecewise linear rule with 2 breakpoints (3 pieces):
c2 = LinearDecisionRules.get_decision(ldr, sell, demand; piece = 2)get_decision(m::LDRModel, x; dual = false, sampled = false)Return the constant term in the linear decision rule for x.
Arguments
m: theLDRModelx: the decision variabledual = false: iftrue, return the constant from the dual solutionsampled = false: iftrue, return the constant from the sampled (SAA) solution
Example
x0 = LinearDecisionRules.get_decision(ldr, sell)
# Decision rule: sell(demand) = x0 + x1 * demandDistributions
Distributions are used to model uncertainty in the Uncertainty variable attribute. Many distributions from the Distributions.jl package are supported, as well as some custom ones:
LinearDecisionRules.MvDiscreteNonParametric — Type
MvDiscreteNonParametric(support, probs)A multivariate discrete distribution with explicit support points and probabilities. Use this for scenario-based uncertainty with joint realizations across multiple uncertain parameters.
Arguments
support: vector of scenario vectors (each scenario is aVector{<:Real})probs: vector of probabilities (must sum to 1)
Example
scenarios = [
[80.0, 60.0], # Low demand for both products
[100.0, 80.0], # Medium demand
[120.0, 100.0], # High demand for both
]
probs = [0.3, 0.4, 0.3]
@variable(ldr, demand[1:2] in LinearDecisionRules.Uncertainty(
distribution = LinearDecisionRules.MvDiscreteNonParametric(scenarios, probs),
))JuMP Extensions
LinearDecisionRules extends standard JuMP functions:
| Function | Description |
|---|---|
optimize!(model) | Solve the LDR model |
termination_status(model) | Get solver termination status |
primal_status(model) | Get primal solution status |
solution_summary(model) | Print solution summary |
set_silent(model) | Silence solver output |
unset_silent(model) | Enable solver output |
set_optimizer(model, optimizer) | Set/change the optimizer |
All these functions accept an optional dual=false keyword to query the dual problem.