API Reference

This page documents the public API of LinearDecisionRules.jl.

Model

LinearDecisionRules.LDRModelType
LDRModel

Main 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))
source

Variable Attributes

LinearDecisionRules.FirstStageType
FirstStage

Attribute to declare first-stage decision variables. These variables are decided before the uncertainty is revealed.

Example

@variable(model, y >= 0, FirstStage)
source
LinearDecisionRules.UncertaintyFunction
Uncertainty(; distribution)

Declare an uncertain parameter with a specified probability distribution. The distribution must have finite bounds.

Arguments

  • distribution: a Distributions.jl univariate 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),
))
source
LinearDecisionRules.BreakPointsType
BreakPoints

Attribute 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],
)
source

Model Attributes

LinearDecisionRules.SolvePrimalType
SolvePrimal

Attribute to get/set whether to solve the primal LDR model.

Example

set_attribute(
    model,
    LinearDecisionRules.SolvePrimal(),
    false,
)
source
LinearDecisionRules.SolveDualType
SolveDual

Attribute to get/set whether to solve the dual LDR model.

Example

set_attribute(
    model,
    LinearDecisionRules.SolveDual(),
    false,
)
source

Solution Queries

LinearDecisionRules.get_decisionFunction
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: the LDRModel
  • x: the decision variable
  • η: the uncertainty variable
  • dual = false: if true, return the coefficient from the dual solution
  • sampled = false: if true, return the coefficient from the sampled (SAA) solution
  • piece = 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)
source
get_decision(m::LDRModel, x; dual = false, sampled = false)

Return the constant term in the linear decision rule for x.

Arguments

  • m: the LDRModel
  • x: the decision variable
  • dual = false: if true, return the constant from the dual solution
  • sampled = false: if true, return the constant from the sampled (SAA) solution

Example

x0 = LinearDecisionRules.get_decision(ldr, sell)
# Decision rule: sell(demand) = x0 + x1 * demand
source

Distributions

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.MvDiscreteNonParametricType
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 a Vector{<: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),
))
source

JuMP Extensions

LinearDecisionRules extends standard JuMP functions:

FunctionDescription
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.