Public interface

Documentation for StochasticPrograms.jl's public interface.

Contents

Index

Constructors

StochasticPrograms.StochasticProgramType
StochasticProgram(first_stage_params::Any,
                  second_stage_params::Any,
                  scenarios::Vector{<:AbstractScenario},
                  instantiation::StochasticInstantiation,
                  optimizer_constructor = nothing)

Create a new two-stage stochastic program with a given collection of scenarios. Optionally, a capable optimizer_constructor can be supplied to later optimize the stochastic program. If multiple Julia processes are available, the resulting stochastic program will automatically be memory-distributed on these processes. This can be avoided by setting procs = [1].

StochasticPrograms.StochasticProgramType
StochasticProgram(first_stage_params::Any,
                  second_stage_params::Any,
                  instantiation::StochasticInstantiation,
                  optimizer_constructor=nothing) where T <: AbstractFloat

Create a new two-stage stochastic program with stage data given by first_stage_params and second_stage_params. After construction, scenarios of type Scenario can be added through add_scenario!. Optionally, a capable optimizer_constructor can be supplied to later optimize the stochastic program. If multiple Julia processes are available, the resulting stochastic program will automatically be memory-distributed on these processes. This can be avoided by setting procs = [1].

StochasticPrograms.StochasticProgramType
StochasticProgram(scenarios::Vector{<:AbstractScenario},
                  instantiation::StochasticInstantiation,
                  optimizer_constructor = nothing)

Create a new two-stage stochastic program with a given collection of scenarios and no stage data. Optionally, a capable optimizer_constructor can be supplied to later optimize the stochastic program. If multiple Julia processes are available, the resulting stochastic program will automatically be memory-distributed on these processes. This can be avoided by setting procs = [1].

StochasticPrograms.StochasticProgramMethod
StochasticProgram(first_stage_params::Any,
                  second_stage_params::Any,
                  ::Type{Scenario},
                  instantiation::StochasticInstantiation,
                  optimizer_constructor=nothing) where Scenario <: AbstractScenario

Create a new two-stage stochastic program with stage data given by first_stage_params and second_stage_params. After construction, scenarios of type S can be added through add_scenario!. Optionally, a capable optimizer_constructor can be supplied to later optimize the stochastic program. If multiple Julia processes are available, the resulting stochastic program will automatically be memory-distributed on these processes. This can be avoided by setting procs = [1].

StochasticPrograms.StochasticProgramMethod
StochasticProgram(::Type{Scenario},
                  instantiation::StochasticInstantiation,
                  optimizer_constructor=nothing) where Scenario <: AbstractScenario

Create a new two-stage stochastic program with scenarios of type Scenario and no stage data. Optionally, a capable optimizer_constructor can be supplied to later optimize the stochastic program.

IO

Base.readMethod
read(io::IO,
     ::Type{SMPSSampler})

Return an SMPSSampler capable of sampling SMPSScenario using the model definition read from io in SMPS format.

Base.readMethod
read(io::IO,
     ::Type{SMPSSampler})

Return an StochasticModel from the model definition read from io in SMPS format.

Base.readMethod
read(io::IO,
     ::Type{StochasticProgram};
     num_scenarios::Union{Nothing, Integer} = nothing,
     instantiation::StochasticInstantiation = UnspecifiedInstantiation(),
     optimizer = nothing;
     defer::Bool = false,
     kw...)

Instantiate a two-stage stochastic program using the model definition read from io in SMPS format, of size num_scenarios. If num_scenarios = nothing, instantiate using the full support. Optionally, supply an optimizer. If no explicit instantiation is provided, the structure is induced by the optimizer. The structure is Deterministic by default.

Structures

StochasticPrograms.UnloadableStructureType
UnloadasbleStructure{Opt <: StochasticProgramOptimizerType, S <: AbstractStochasticStructure}

Error thrown when an optimizer of type Opt cannot load a structure of type S.

StochasticPrograms.UnloadedStructureType
UnloadedStructure{Opt <: StochasticProgramOptimizerType}

Error thrown when an optimizer of type Opt has not yet loaded a stochastic structure and an operation which requires a structure to be loaded is called.

StochasticPrograms.UnsupportedStructureType
UnsupportedStructure{Opt <: StochasticProgramOptimizerType, S <: AbstractStochasticStructure}

Error indicating that an optimizer of type Opt does not support the stochastic structure S.

StochasticPrograms.StochasticStructureFunction
StochasticStructure(scenario_types::ScenarioTypes{M}, instantiation::StochasticInstantiation) where M

Constructs a stochastic structure over the M provided scenario types according to the specified instantiation. Should be overrided for every defined stochastic structure.

StochasticStructure(scenarios::NTuple{M, Vector{<:AbstractScenario}}, instantiation::StochasticInstantiation) where M

Constructs a stochastic structure over the M provided scenario sets according to the specified instantiation. Should be overrided for every defined stochastic structure.

StochasticPrograms.default_structureMethod
default_structure(instantiation::StochasticInstantiation, optimizer)

Returns a StochasticInstantiation based on the provided instantiation and optimizer. If an explicit instantiation is provided it is always prioritized. Otherwise, if instantiation is UnspecifiedInstantiation, returns whatever structure requested by the optimizer. Defaults to Deterministic if no optimizer is provided.

StochasticPrograms.DeterministicEquivalentType
DeterministicEquivalent

Deterministic equivalent memory structure. Stochastic program is stored as one large optimization problem. Supported by any standard AbstractOptimizer.

Decisions

StochasticPrograms.DecisionVariableType
DecisionVariable <: AbstractVariableRef

Identifier for a decision in a stochastic program. Holds a reference to the stochastic program, the stage the decision is taken in, and its corresponding MOI.VariableIndex.

JuMP.BinaryRefMethod
BinaryRef(dvar::DecisionVariable)

Return a constraint reference to the binary constraint of the decision variable dvar. Errors if one does not exist.

JuMP.FixRefMethod
FixRef(dvar::DecisionVariable)

Return a constraint reference to the constraint fixing the value of the decision dvar. Errors if one does not exist.

JuMP.IntegerRefMethod
IntegerRef(dvar::DecisionVariable)

Return a constraint reference to the integrality constraint of the decision variable dvar. Errors if one does not exist.

JuMP.LowerBoundRefMethod
LowerBoundRef(dvar::DecisionVariable)

Return a constraint reference to the lower bound constraint of the decision variable dvar. Errors if one does not exist.

JuMP.UpperBoundRefMethod
LowerBoundRef(dvar::DecisionVariable)

Return a constraint reference to the upper bound constraint of the decision variable dvar. Errors if one does not exist.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, dvar::DecisionVariable, scenario_index::Integer)

Delete the scenario-dependent decision variable associated with dvar from the stochasticprogram at scenario_index.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, dvar::DecisionVariable)

Delete the first-stage decision variable associated with dvar from the stochasticprogram.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, dvars::Vector{DecisionVariable}, scenario_index::Integer)

Delete the scenario-dependent decisions associated with dvars from the stochasticprogram at scenario_index.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, dvars::Vector{DecisionVariable})

Delete the decisions associated with dvars from the stochasticprogram.

JuMP.delete_lower_boundMethod
delete_lower_bound(dvar::DecisionVariable, scenario_index::Integer)

Delete the lower bound constraint of the scenario-dependent decision variable dvar at scenario_index.

JuMP.delete_lower_boundMethod
delete_lower_bound(dvar::DecisionVariable)

Delete the lower bound constraint of the first-stage decision variable dvar.

JuMP.delete_upper_boundMethod
delete_upper_bound(dvar::DecisionVariable, scenario_index::Integer)

Delete the upper bound constraint of the scenario-dependent decision variable dvar at scenario_index.

JuMP.delete_upper_boundMethod
delete_upper_bound(dvar::DecisionVariable)

Delete the upper bound constraint of the first-stage decision variable dvar.

JuMP.fixMethod
fix(dvar::DecisionVariable, scenario_index::Integer, val::Number)

Fix the scenario-dependent decision associated with dvar at scenario_index to val. In contexts where dvar is a variable, the variable is fixed to the value. In contexts where dvar is a known parameter value, the value is updated.

JuMP.fixMethod
fix(dvar::DecisionVariable, val::Number)

Fix the first-stage decision associated with dvar to val. In contexts where dvar is a variable, the variable is fixed to the value. In contexts where dvar is a known parameter value, the value is updated.

JuMP.has_lower_boundMethod
has_lower_bound(dvar::DecisionVariable, scenario_index::Integer)

Return true if the scenario-dependent decision variable dvar has a lower bound at scenario_index.

JuMP.has_lower_boundMethod
has_lower_bound(dvar::DecisionVariable)

Return true if the first-stage decision variable dvar has a lower bound.

JuMP.has_upper_boundMethod
has_upper_bound(dvar::DecisionVariable, scenario_index::Integer)

Return true if the scenario-dependent decision variable dvar has a upper bound at scenario_index.

JuMP.has_upper_boundMethod
has_upper_bound(dvar::DecisionVariable)

Return true if the first-stage decision variable dvar has a upper bound.

JuMP.has_valuesMethod
has_values(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return true if the solver has a primal solution in the node at stage stage and scenario scenario_index in result index result available to query, otherwise return false.

JuMP.has_valuesMethod
has_values(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return true if the solver has a primal solution in scenario scenario_index in result index result available to query, otherwise return false.

JuMP.has_valuesMethod
has_duals(stochasticprogram::StochasticProgram; result::Int = 1)

Return true if the solver has a primal solution in the first-stage of stochasticprogram in result index result available to query, otherwise return false.

JuMP.indexMethod
index(dvar::DecisionVariable)::MOI.VariableIndex

Return the index of the decision variable that corresponds to dvar in the MOI backend.

JuMP.is_binaryMethod
is_binary(dvar::DecisionVariable, scenario_index::Integer)

Return true if the scenario-dependent decision variable dvar is constrained to be binary at scenario_index.

JuMP.is_binaryMethod
is_binary(dvar::DecisionVariable)

Return true if the first-stage decision variable dvar is constrained to be binary.

JuMP.is_fixedMethod
is_fixed(dvar::DecisionVariable, scenario_index)

Return true if dvar is a fixed decision variable in scenario_index.

JuMP.is_fixedMethod
is_fixed(dvar::DecisionVariable)

Return true if dvar is a fixed first-stage decision variable.

JuMP.is_integerMethod
is_integer(dvar::DecisionVariable, scenario_index::Integer)

Return true if the scenario-dependent decision variable dvar is constrained to be integer at scenario_index.

JuMP.is_integerMethod
is_integer(dvar::DecisionVariable)

Return true if the first-stage decision variable dvar is constrained to be integer.

JuMP.is_validMethod
is_valid(stochasticprogram::StochasticProgram, dvar::DecisionVariable, scenario_index::Integer)

Return true if the scenario-dependent dvar refers to a valid decision variable in stochasticprogram at scenario_index.

JuMP.is_validMethod
is_valid(stochasticprogram::StochasticProgram, dvar::DecisionVariable)

Return true if dvar refers to a valid first-stage decision variable in stochasticprogram.

JuMP.lower_boundMethod
lower_bound(dvar::DecisionVariable, scenario_index::Integer)

Return the lower bound of the scenario-dependent decision variable dvar at scenario_index. Error if one does not exist.

JuMP.lower_boundMethod
lower_bound(dvar::DecisionVariable)

Return the lower bound of the first-stage decision variable dvar. Error if one does not exist.

JuMP.nameMethod
name(dvar::DecisionVariable, scenario_index::Integer)::String

Get the name of the scenario-dependent decision variable dvar in scenario scenario_index.

JuMP.nameMethod
name(dvar::DecisionVariable, scenario_index::Integer)::String

Get the name of the decision variable dvar.

JuMP.optimizer_indexMethod
optimizer_index(dvar::DecisionVariable, scenario_index)::MOI.VariableIndex

Return the index of the variable that corresponds to the scenario-dependent dvar in the optimizer model at scenario_index.

JuMP.optimizer_indexMethod
optimizer_index(dvar::DecisionVariable)::MOI.VariableIndex

Return the index of the variable that corresponds to dvar in the optimizer model.

JuMP.reduced_costMethod
reduced_cost(dvar::DecisionVariable)::Float64

Return the reduced cost associated with the scenario-dependent decision variable dvar at scenario_index.

JuMP.reduced_costMethod
reduced_cost(dvar::DecisionVariable)::Float64

Return the reduced cost associated with the decision variable dvar.

JuMP.relax_integralityMethod
relax_integrality(stochasticprogram::StochasticProgram)

Modifies stochasticprogram to "relax" all binary and integrality constraints on decisions and auxiliary variables.

Returns a function that can be called without any arguments to restore the original stochasticprogram. The behavior of this function is undefined if additional changes are made to the affected decisions and variables in the meantime.

JuMP.set_binaryMethod
set_binary(dvar::DecisionVariable, scenario_index::Integer)

Constrain the scenario-dependent decision variable dvar to the set $\{0,1\}$ at scenario_index.

JuMP.set_binaryMethod
set_binary(dvar::DecisionVariable)

Constrain the first-stage decision variable dvar to the set $\{0,1\}$.

JuMP.set_integerMethod
set_integer(dvar::DecisionVariable, scenario_index::Integer)

Add an integrality constraint on the scenario-dependent decision variable dvar at scenario_index.

JuMP.set_integerMethod
set_integer(dvar::DecisionVariable)

Add an integrality constraint on the first-stage decision variable dvar.

JuMP.set_lower_boundMethod
set_lower_bound(dvar::DecisionVariable, scenario_index::Integer, lower::Number)

Set the lower bound of the scenario-dependent decision variable dvar at scenario_index to lower. If one does not exist, create a new lower bound constraint.

JuMP.set_lower_boundMethod
set_lower_bound(dvar::DecisionVariable)

Set the lower bound of the first-stage decision variable dvar to lower. If one does not exist, create a new lower bound constraint.

JuMP.set_nameMethod
set_name(dvar::DecisionVariable, scenario_index::Integer, name::String)

Set the name of the scenario-dependent decision variable dvar in scenario scenario_index to name.

JuMP.set_nameMethod
set_name(dvar::DecisionVariable, scenario_index::Integer, name::String)

Set the name of the decision variable dvar to name.

JuMP.set_start_valueMethod
set_start_value(dvar::DecisionVariable, scenario_index::Integer, value::Number)

Set the start value of the scenario-dependent decision variable dvar at scenario_index to value.

JuMP.set_start_valueMethod
set_start_value(dvar::DecisionVariable)

Set the start value of the first-stage decision variable dvar to value.

JuMP.set_upper_boundMethod
set_upper_bound(dvar::DecisionVariable, scenario_index::Integer, upper::Number)

Set the upper bound of the scenario-dependent decision variable dvar at scenario_index to upper. If one does not exist, create a new upper bound constraint.

JuMP.set_upper_boundMethod
set_upper_bound(dvar::DecisionVariable, upper::Number)

Set the upper bound of the first-stage decision variable dvar to upper. If one does not exist, create a new upper bound constraint.

JuMP.start_valueMethod
start_value(dvar::DecisionVariable, scenario_index::Integer)

Return the start value of the scenario-dependent decision variable dvar at scenario_index.

JuMP.start_valueMethod
start_value(dvar::DecisionVariable)

Return the start value of the first-stage decision variable dvar.

JuMP.unfixMethod
unfix(dvar::DecisionVariable, scenario_index::Integer)

Unfix the scenario-dependent decision associated with dvar at scenario_index. If the decision is already in a NotTaken state, this does nothing.

JuMP.unfixMethod
unfix(dvar::DecisionVariable)

Unfix the first-stage decision associated with dvar. If the decision is already in a NotTaken state, this does nothing.

JuMP.unset_binaryMethod
unset_binary(dvar::DecisionVariable, scenario_index::Integer)

Delete the binary constraint of the scenario-dependent decision variable dvar at scenario_index.

JuMP.unset_binaryMethod
unset_binary(dvar::DecisionVariable)

Delete the binary constraint of the first-stage decision variable dvar.

JuMP.unset_integerMethod
unset_integer(dvar::DecisionVariable, scenario_index::Integer)

Delete the integrality constraint of the scenario-dependent decision variable dvar at scenario_index.

JuMP.unset_integerMethod
unset_integer(dvar::DecisionVariable)

Delete the integrality constraint of the first-stage decision variable dvar.

JuMP.upper_boundMethod
upper_bound(dvar::DecisionVariable, scenario_index::Integer)

Return the upper bound of the scenario-dependent decision variable dvar at scenario_index. Error if one does not exist.

JuMP.upper_boundMethod
upper_bound(dvar::DecisionVariable)

Return the upper bound of the first-stage decision variable dvar. Error if one does not exist.

JuMP.valueMethod
value(dvar::DecisionVariable, scenario_index::Integer; result = 1)

Return the scenario-dependent value of the decision variable dvar associated with result index result at scenario_index of the most-recent returned by the solver.

JuMP.valueMethod
value(dvar::DecisionVariable; result = 1)

Return the value of the first-stage decision variable dvar associated with result index result of the most-recent returned by the solver.

JuMP.valueMethod
value(dvar_expr::Union{GenericAffExpr{T,DecisionVariable}, GenericQuadExpr{T,DecisionVariable}}, stage_to_scenario::Dict{Int,Int}) where T

Evaluate dvar_expr where the value of a given dvar is found in the scenario returned by the provided stage_to_scenario map.

StochasticPrograms.decisionMethod
decision(dvar::DecisionVariable, scenario_index::Integer)

Return the scenario-dependent internal Decision associated with dvar at scenario_index.

StochasticPrograms.decisionMethod
decision(dvar::DecisionVariable)

Return the internal Decision associated with the first-stage dvar.

StochasticPrograms.decision_by_nameMethod
decision_by_name(stochasticprogram::Stochasticprogram,
                 stage::Integer,
                 name::String)::Union{AbstractVariableRef, Nothing}

Returns the reference of the variable with name attribute name at stage of stochasticprogram or Nothing if no variable has this name attribute. Throws an error if several variables have name as their name attribute at stage s.

StochasticPrograms.stateMethod
state(dvar::DecisionVariable, scenario_index::Integer)

Return the scenario-dependent DecisionState of dvar at scenario_index.

StochasticPrograms.SPConstraintRefType
SPConstraintRef

Holds a reference to the stochastic program, the stage the constraint resides in, and the corresponding MOI.ConstraintIndex.

JuMP.all_constraintsMethod
all_constraints(stochasticprogram::StochasticProgram, stage::Integer, function_type, set_type)::Vector{<:SPConstraintRef}

Return a list of all decision constraints currently in the stochasticprogram at stage where the function has type function_type and the set has type set_type. The constraints are ordered by creation time. This errors if regular constraints are queried. If so, either annotate the relevant variables with @decision or first query the relevant JuMP subproblem and use the regular all_constraints function.

JuMP.constraint_by_nameMethod
constraint_by_name(stochasticprogram::StochasticProgram,
                   stage::Integer,
                   name::String)::Union{SPConstraintRef, Nothing}

Returns the reference of the constraint with name attribute name at stage of stochasticprogram or Nothing if no constraint has this name attribute. Throws an error if several constraints have name as their name attribute.

constraint_by_name(stochasticprogram::StochasticProgram,
                   stage::Integer,
                   name::String,
                   F::Type{<:Union{AbstractJuMPScalar,
                                   Vector{<:AbstractJuMPScalar},
                                   MOI.AbstactFunction}},
                   S::Type{<:MOI.AbstractSet})::Union{SPConstraintRef, Nothing}

Similar to the method above, except that it throws an error if the constraint is not an F-in-S contraint where F is either the JuMP or MOI type of the function, and S is the MOI type of the set.

JuMP.constraint_objectMethod
constraint_object(sp_cref::SPConstraintRef)

Return the underlying constraint data for the first-stage decision constraint referenced by sp_cref.

JuMP.constraint_objectMethod
constraint_object(sp_cref::SPConstraintRef, scenario_index)

Return the underlying constraint data for the scenario-dependent decision constraint referenced by sp_cref in scenario scenario_index.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, sp_cref::SPConstraintRef, scenario_index::Integer)

Delete the scenario-dependent decision constraint associated with sp_cref from the stochasticprogram in scenario scenario_index.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, sp_cref::SPConstraintRef)

Delete the first-stage decision constraint associated with sp_cref from the stochasticprogram.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, sp_crefs::Vector{<:SPConstraintRef}, scenario_index::Integer)

Delete the scenario-dependent decision constraints associated with sp_crefs from the stochasticprogram at scenario_index.

JuMP.deleteMethod
delete(stochasticprogram::StochasticProgram, sp_crefs::Vector{<:SPConstraintRef})

Delete the first-stage decision constraints associated with sp_crefs from the stochasticprogram.

JuMP.dualMethod
dual(sp_cref::SPConstraintRef, scenario_index::Integer; result::Int = 1)

Return the dual value of the scenario-dependent decision constraint sp_cref in scenario scenario_index associated with result index result of the most-recent solution returned by the solver.

JuMP.dualMethod
dual(sp_cref::SPConstraintRef; result::Int = 1)

Return the dual value of the first-stage decision constraint sp_cref associated with result index result of the most-recent solution returned by the solver.

JuMP.has_dualsMethod
has_duals(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return true if the solver has a dual solution in the node at stage stage and scenario scenario_index in result index result available to query, otherwise return false.

JuMP.has_dualsMethod
has_duals(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return true if the solver has a dual solution in scenario scenario_index in result index result available to query, otherwise return false.

JuMP.has_dualsMethod
has_duals(stochasticprogram::StochasticProgram; result::Int = 1)

Return true if the solver has a dual solution in the first-stage of stochasticprogram in result index result available to query, otherwise return false.

JuMP.indexMethod
index(sp_cref::SPConstraintNotOwned)::MOI.ConstraintIndex

Return the index of the decision constraint that corresponds to sp_cref in the MOI backend.

JuMP.is_validMethod
is_valid(stochasticprogram::StochasticProgram, sp_cref::SPConstraintRef, scenario_index::Integer)

Return true if the scenario-dependent sp_cref refers to a valid decision constraint in stochasticprogram at scenario_index.

JuMP.is_validMethod
is_valid(stochasticprogram::StochasticProgram, sp_cref::SPConstraintRef)

Return true if sp_cref refers to a valid first-stage decision constraint in stochasticprogram.

JuMP.list_of_constraint_typesMethod
list_of_constraint_types(stochasticprogram::Stochasticprogram, stage::Integer)::Vector{Tuple{DataType, DataType}}

Return a list of tuples of the form (F, S) where F is a JuMP function type and S is an MOI set type such that all_constraints(stochasticprogram, stage, F, S) returns a nonempty list.

JuMP.nameMethod
name(sp_cref::SPConstraintRef, scenario_index::Integer)::String

Get the name of the scenario-dependent decision constraint sp_cref in scenario scenario_index.

JuMP.nameMethod
name(sp_cref::SPConstraintRef)::String

Get the name of the decision constraint sp_cref.

JuMP.normalized_coefficientMethod
normalized_coefficient(sp_cref::SPConstraintRef, dvar::DecisionVariable, scenario_index::Integer)

Return the coefficient associated with dvar in the decision constraint sp_cref in scenario scenario_index after JuMP has normalized the constraint into its standard form.

JuMP.normalized_coefficientMethod
normalized_coefficient(sp_cref::SPConstraintRef, dvar::DecisionVariable)

Return the coefficient associated with dvar in the first-stage decision constraint sp_cref after JuMP has normalized the constraint into its standard form.

JuMP.normalized_rhsMethod
normalized_rhs(sp_cref::SPConstraintRef)

Return the right-hand side term of the first-stage decision constraint sp_cref after JuMP has converted the constraint into its normalized form.

JuMP.normalized_rhsMethod
normalized_rhs(sp_cref::SPConstraintRef, scenario_index::Integer)

Return the right-hand side term of the scenario-dependent decision constraint sp_cref at scenario_index after JuMP has converted the constraint into its normalized form.

JuMP.num_constraintsMethod
num_constraints(stochasticprogram::StochasticProgram{N}, stage::Integer, function_type, set_type)::Int64

Return the number of decision constraints currently in the stochasticprogram at stage where the function has type function_type and the set has type set_type. This errors if regular constraints are queried. If so, either annotate the relevant variables with @decision or first query the relevant JuMP subproblem and use the regular all_constraints function.

JuMP.optimizer_indexMethod
optimizer_index(sp_cref::SPConstraintRef, scenario_index)::MOI.VariableIndex

Return the index of the constraint that corresponds to the scenario-dependent sp_cref in the optimizer model at scenario_index.

JuMP.optimizer_indexMethod
optimizer_index(sp_cref::SPConstraintRef)::MOI.VariableIndex

Return the index of the variable that corresponds to dvar in the optimizer model.

JuMP.set_nameMethod
set_name(sp_cref::SPConstraintRef, scenario_index::Integer, name::String)

Set the name of the scenario-dependent decision constraint sp_cref in scenario scenario_index to name.

JuMP.set_nameMethod
set_name(sp_cref::SPConstraintRef, name::String)

Set the name of the decision constraint sp_cref to name.

JuMP.set_normalized_coefficientMethod
set_normalized_coefficient(sp_cref::SPConstraintRef, dvar::DecisionVariable, value)

Set the coefficient of dvar in the first-stage decision constraint sp_cref to value.

JuMP.set_normalized_coefficientMethod
set_normalized_coefficient(sp_cref::SPConstraintRef, dvar::DecisionVariable, scenario_index::Integer, value)

Set the coefficient of dvar in the decision constraint sp_cref in scenario scenario_index to value.

JuMP.set_normalized_rhsMethod
set_normalized_rhs(sp_cref::SPConstraintRef, value)

Set the right-hand side term of the first-stage decision constraint sp_cref to value.

JuMP.set_normalized_rhsMethod
set_normalized_rhs(sp_cref::SPConstraintRef, scenario_index::Integer, value)

Set the right-hand side term of the decision constraint sp_cref at scenario_index to value.

JuMP.shadow_priceMethod
shadow_price(sp_cref::SPConstraintRef)

Return the shadow price of the first-stage decision constraint sp_cref associated with result index result of the most-recent solution returned by the solver.

JuMP.shadow_priceMethod
shadow_price(sp_cref::SPConstraintRef, scenario_index::Integer)

Return the shadow price of the scenario-dependent decision constraint sp_cref in scenario scenario_index associated with result index result of the most-recent solution returned by the solver.

JuMP.valueMethod
value(sp_cref::SPConstraintRef, dvar_value::Function)

Evaluate the primal value of the first-stage decision constraint sp_cref using dvar_value(dvar) as the value for each decision variable dvar.

JuMP.valueMethod
value(sp_cref::SPConstraintRef, dvar_value::Function)

Evaluate the primal value of the scenario-dependent decision constraint sp_cref in scenario scenario_index using dvar_value(dvar) as the value for each decision variable dvar.

JuMP.valueMethod
value(sp_cref::SPConstraintRef, scenario_index::Integer; result::Int = 1)

Return the primal value of the scenario-dependent decision constraint sp_cref at scenario_index associated with result index result of the most-recent solution returned by the solver.

JuMP.valueMethod
value(sp_cref::SPConstraintRef; result::Int = 1)

Return the primal value of the first-stage decision constraint sp_cref associated with result index result of the most-recent solution returned by the solver.

JuMP.dual_objective_valueMethod
dual_objective_value(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return the objective value of the dual problem of the node at stage stage and scenario scenario_index associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.dual_objective_valueMethod
dual_objective_value(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return the objective value of the dual problem of scenario scenario_index associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.dual_objective_valueMethod
dual_objective_value(stochasticprogram::StochasticProgram; result::Int = 1)

Return the objective value of the dual problem associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.objective_boundMethod
objective_bound(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the best known bound on the optimal objective value in the node at stage stage and scenario scenario_index after a call to optimize!(stochasticprogram).

JuMP.objective_boundMethod
objective_bound(stochasticprogram::StochasticProgram)

Return the best known bound on the optimal objective value after a call to optimize!(stochasticprogram).

JuMP.objective_functionFunction
objective_function(stochasticprogram::StochasticProgram,
                   stage::Integer,
                   scenario_index::Integer,
                   T::Type{<:AbstractJuMPScalar}=objective_function_type(model))

Return an object of type T representing the objective function in the node at stage stage and scenario scenario_index. Error if the objective is not convertible to type T.

JuMP.objective_functionFunction
objective_function(stochasticprogram::StochasticProgram,
                   T::Type{<:AbstractJuMPScalar}=objective_function_type(model))

Return an object of type T representing the full objective function of the stochasticprogram. Error if the objective is not convertible to type T.

JuMP.objective_functionMethod
objective_function(stochasticprogram::StochasticProgram,
                   stage::Integer,
                   T::Type{<:AbstractJuMPScalar}=objective_function_type(model))

Return an object of type T representing the objective function at stage stage of the stochasticprogram. Error if the objective is not convertible to type T.

JuMP.objective_function_typeMethod
objective_function_type(stochasticprogram::Stochasticprogram, stage::Integer, scenario_index::Integer)::AbstractJuMPScalar

Return the type of the objective function in the node at stage stage and scenario scenario_index.

JuMP.objective_function_typeMethod
objective_function_type(stochasticprogram::Stochasticprogram)::AbstractJuMPScalar

Return the type of the objective function of stochasticprogram.

JuMP.objective_function_typeMethod
objective_function_type(stochasticprogram::Stochasticprogram, stage::Integer)::AbstractJuMPScalar

Return the type of the objective function at stage stage of stochasticprogram.

JuMP.objective_senseMethod
objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)::MathOptInterface.OptimizationSense

Return the objective sense in the node at stage stage and scenario scenario_index.

JuMP.objective_senseMethod
objective_sense(stochasticprogram::StochasticProgram)::MathOptInterface.OptimizationSense

Return the objective sense of the stochasticprogram.

JuMP.objective_senseMethod
objective_sense(stochasticprogram::StochasticProgram, stage::Integer)::MathOptInterface.OptimizationSense

Return the objective sense of the stochasticprogram stage stage.

JuMP.objective_valueMethod
objective_value(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return the objective value of the node at stage stage and scenario scenario_index associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.objective_valueMethod
objective_value(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return the objective value of scenario scenario_index associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.objective_valueMethod
objective_value(stochasticprogram::StochasticProgram; result::Int = 1)

Return the objective value associated with result index result of the most-recent solution after a call to optimize!(stochasticprogram).

JuMP.relative_gapMethod
relative_gap(model::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the final relative optimality gap in the node at stage stage and scenario scenario_index after a call to optimize!(stochasticprogram).

JuMP.relative_gapMethod
relative_gap(model::StochasticProgram)

Return the final relative optimality gap after a call to optimize!(stochasticprogram).

JuMP.set_objective_coefficientMethod
set_objective_coefficient(stochasticprogram::StochasticProgram, dvar::DecisionVariable, stage::Integer, scenario_index::Integer, coefficient::Real)

Set the scenario-dependent linear objective coefficient at scenario_index associated with dvar to coefficient in stage stage.

JuMP.set_objective_coefficientMethod
set_objective_coefficient(stochasticprogram::StochasticProgram, dvar::DecisionVariable, stage::Integer, coefficient::Real)

Set the linear objective coefficient associated with dvar to coefficient in stage stage.

JuMP.set_objective_senseMethod
set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer, sense::MathOptInterface.OptimizationSense)

Sets the objective sense of the stochasticprogram node at stage stage and scenario scenario_index to the given sense.

JuMP.set_objective_senseMethod
set_objective_sense(stochasticprogram::StochasticProgram, sense::MathOptInterface.OptimizationSense)

Sets the objective sense of the stochasticprogram to sense.

JuMP.set_objective_senseMethod
set_objective_sense(stochasticprogram::StochasticProgram, stage::Integer, sense::MathOptInterface.OptimizationSense)

Sets the objective sense of the stochasticprogram at stage stage to sense.

StochasticPrograms.DecisionRefType
DecisionRef <: AbstractVariableRef

Holds a reference to the model, the stage the decision is taken in, and the corresponding MOI.VariableIndex.

JuMP.fixMethod
fix(dref::DecisionRef, val::Number)

Fix the decision associated with dref to val.

See also unfix.

StochasticPrograms.all_auxiliary_variablesMethod
all_auxiliary_variables(model::JuMP.Model)

Returns a list of all auxiliary variables currently in the decision model through @variable. The variables are ordered by creation time.

StochasticPrograms.all_decision_variablesMethod
all_decision_variables(model::JuMP.Model, stage::Integer)

Returns a list of all decisions currently in the model at stage stage. The decisions are ordered by creation time.

StochasticPrograms.all_known_decision_variablesMethod
all_known_decision_variables(model::JuMP.Model, stage::Integer)

Returns a stage-wise list of all known decisions currently in the model at stage stage. The decisions are ordered by creation time.

StochasticPrograms.num_decisionsFunction
num_decisions(model::JuMP.Model, stage::Integer = 1)

Return the number of decisions in model at stage stage. Defaults to the first stage.

StochasticPrograms.num_known_decisionsFunction
num_known_decisions(model::JuMP.Model, stage::Integer = 2)

Return the number of known decisions in model at stage stage. Defaults to the second stage.

Scenarios

StochasticPrograms.expectedMethod
expected(scenarios::Vector{<:AbstractScenario})

Return the expected scenario out of the collection scenarios in an ExpectedScenario wrapper.

This is defined through classical expectation: sum([probability(s)*s for s in scenarios]), and is always defined for scenarios created through @scenario, if the requested fields support it.

Otherwise, user-defined scenario types must implement this method for full functionality.

See also ExpectedScenario

StochasticPrograms.probabilityMethod
probability(scenario::AbstractScenario)

Return the probability of scenario occuring.

Is always defined for scenarios created through @scenario. Other user defined scenario types must implement this method to generate a proper probability. The default behaviour is to assume that scenario has a probability field of type Probability

See also: Probability

StochasticPrograms.probabilityMethod
probability(scenarios::Vector{<:AbstractScenario})

Return the probability of that any scenario in the collection scenarios occurs.

StochasticPrograms.set_probability!Method
set_probability!(scenario::AbstractScenario, probability::AbstractFloat)

Set the probability of scenario occuring.

Is always defined for scenarios created through @scenario. Other user defined scenario types must implement this method.

StochasticPrograms.@define_scenarioMacro
@define_scenario(def)

Define a scenario type compatible with StochasticPrograms using the syntax

@define_scenario name = begin
    ...structdef...

    [@zero begin
        ...
        return zero(scenario)
    end]

    [@expectation begin
        ...
        return expected(scenarios)
     end]
end

The generated type is referenced through name and a default constructor is always generated. This constructor accepts the keyword probability to set the probability of the scenario occuring. Otherwise, any internal variables and specialized constructors are defined in the @define_scenario block as they would be in any Julia struct.

If possible, a zero method and an expected method will be generated for the defined type. Otherwise, or if the default implementation is not desired, these can be user provided through @zero and @expectation.

The defined scenario type will be available on all Julia processes.

Examples

The following defines a simple scenario $ξ$ with a single value.

@define_scenario ExampleScenario = begin
    ξ::Float64
end

ExampleScenario(1.0, probability = 0.5)

# output

ExampleScenario with probability 0.5
  ξ: 1.0

See also: @zero, @expectation, @sampler

StochasticPrograms.@expectationMacro
@expectation(def)

Define how to form the expected scenario inside a @define_scenario block. The scenario collection is accessed through the reserved keyword scenarios.

@zero begin
    ...
    return zero_scenario
end

Examples

The following defines expectation for the example scenario defined in @scenario

@expectation begin
    return ExampleScenario(sum([probability(s)*s.ξ for s in scenarios]))
end

See also @define_scenario

StochasticPrograms.@scenarioMacro
@scenario(args..., probability = )

Create Scenario matching some @uncertain declaration with a supplied probability.

@scenario(var1 = val1, var2 = val2, ..., probability = 1.0)

Create Scenario matching @uncertain annotation of the form @uncertain var1, var2, ...

@scenario(ξ[i=..., j=..., ...] = values, probability = 1.0)

Create Scenario matching @uncertain annotation of the form @uncertain ξ[i=..., j=..., ...]. values must have the same dimension as the specified index sets.

@scenario(ξ[i=..., j=..., ...], expr, probability = 1.0, requested_container = :Auto)

Create Scenario matching @uncertain annotation of the form @uncertain ξ[i=..., j=..., ...]. Wraps JuMP's @container macro to create DenseAxisArray or SparseAxisArray as underlying data. See @container for further syntax information.

Examples

The following are equivalent ways of creating an instance of the random vector $[q₁(ξ) q₂(ξ) d₁(ξ) d₂(ξ)]$ of probability $0.4$ and values $[24.0 28.0 500.0 100.0]$.

@scenario q₁ = 24.0 q₂ = 28.0 d₁ = 500.0 d₂ = 100.0 probability = 0.4

@scenario ξ[i in 1:4] = [24.0, 28.0, 500.0, 100.0] probability = 0.4
StochasticPrograms.@uncertainMacro
@uncertain(def)

In a @stage block, annotate each uncertain variable using the syntax

@uncertain var1, var2, ...

or using JuMP's container syntax

@uncertain ξ[i=..., j=..., ...]

This assumes that the [Scenario] type is used. Matching scenario data is then conveniently created using @scenario.

Alternatively, user-defined scenarios can be specified by annotating the type. Also, inside a @stochasticmodel block, user-defined scenarios can be created during the @uncertain annotation, using [`@definescenario`](@ref) syntax.

Examples

The following are equivalent ways of declaring a random vector $[q₁(ξ) q₂(ξ) d₁(ξ) d₂(ξ)]$ in a @stage block, and creating a matching scenario instance of probability $0.4$ and values $[24.0 28.0 500.0 100.0]$

@uncertain q₁ q₂ d₁ d₂
ξ₁ = @scenario q₁ = 24.0 q₂ = 28.0 d₁ = 500.0 d₂ = 100.0 probability = 0.4

@uncertain ξ[i in 1:4]
ξ₁ = @scenario ξ[i in 1:4] = [24.0, 28.0, 500.0, 100.0] probability = 0.4

@define_scenario SimpleScenario = begin
    q₁::Float64
    q₂::Float64
    d₁::Float64
    d₂::Float64
end
@uncertain ξ::SimpleScenario
ξ₁ = SimpleScenario(24.0, 28.0, 500.0, 100.0, probability = 0.4)

@stochastic_model begin
    ...
    @uncertain ξ::SimpleScenario = begin
        q₁::Float64
        q₂::Float64
        d₁::Float64
        d₂::Float64
    end
    ...
end
ξ₁ = SimpleScenario(24.0, 28.0, 500.0, 100.0 probability = 0.4)

See also @scenario, @define_scenario, @parameters, @decision, @stage

StochasticPrograms.@zeroMacro
@zero(def)

Define the additive zero scenario inside a @scenario block using the syntax:

@zero begin
    ...
    return zero_scenario
end

Examples

The following defines a zero scenario for the example scenario defined in @define_scenario

@zero begin
    return ExampleScenario(0.0)
end

See also @define_scenario

StochasticPrograms.sampleFunction
sample(sampler::AbstractSampler{S})

Sample a scenario of type S using sampler.

sample(sampler::AbstractSampler{S}, π::AbstractSampler)

Sample a scenario of type S using sampler and set the probability of the sampled scenario to π.

StochasticPrograms.@scenarioMacro
@scenario(args..., probability = )

Create Scenario matching some @uncertain declaration with a supplied probability.

@scenario(var1 = val1, var2 = val2, ..., probability = 1.0)

Create Scenario matching @uncertain annotation of the form @uncertain var1, var2, ...

@scenario(ξ[i=..., j=..., ...] = values, probability = 1.0)

Create Scenario matching @uncertain annotation of the form @uncertain ξ[i=..., j=..., ...]. values must have the same dimension as the specified index sets.

@scenario(ξ[i=..., j=..., ...], expr, probability = 1.0, requested_container = :Auto)

Create Scenario matching @uncertain annotation of the form @uncertain ξ[i=..., j=..., ...]. Wraps JuMP's @container macro to create DenseAxisArray or SparseAxisArray as underlying data. See @container for further syntax information.

Examples

The following are equivalent ways of creating an instance of the random vector $[q₁(ξ) q₂(ξ) d₁(ξ) d₂(ξ)]$ of probability $0.4$ and values $[24.0 28.0 500.0 100.0]$.

@scenario q₁ = 24.0 q₂ = 28.0 d₁ = 500.0 d₂ = 100.0 probability = 0.4

@scenario ξ[i in 1:4] = [24.0, 28.0, 500.0, 100.0] probability = 0.4
StochasticPrograms.@define_scenarioMacro
@define_scenario(def)

Define a scenario type compatible with StochasticPrograms using the syntax

@define_scenario name = begin
    ...structdef...

    [@zero begin
        ...
        return zero(scenario)
    end]

    [@expectation begin
        ...
        return expected(scenarios)
     end]
end

The generated type is referenced through name and a default constructor is always generated. This constructor accepts the keyword probability to set the probability of the scenario occuring. Otherwise, any internal variables and specialized constructors are defined in the @define_scenario block as they would be in any Julia struct.

If possible, a zero method and an expected method will be generated for the defined type. Otherwise, or if the default implementation is not desired, these can be user provided through @zero and @expectation.

The defined scenario type will be available on all Julia processes.

Examples

The following defines a simple scenario $ξ$ with a single value.

@define_scenario ExampleScenario = begin
    ξ::Float64
end

ExampleScenario(1.0, probability = 0.5)

# output

ExampleScenario with probability 0.5
  ξ: 1.0

See also: @zero, @expectation, @sampler

StochasticPrograms.@zeroMacro
@zero(def)

Define the additive zero scenario inside a @scenario block using the syntax:

@zero begin
    ...
    return zero_scenario
end

Examples

The following defines a zero scenario for the example scenario defined in @define_scenario

@zero begin
    return ExampleScenario(0.0)
end

See also @define_scenario

StochasticPrograms.@expectationMacro
@expectation(def)

Define how to form the expected scenario inside a @define_scenario block. The scenario collection is accessed through the reserved keyword scenarios.

@zero begin
    ...
    return zero_scenario
end

Examples

The following defines expectation for the example scenario defined in @scenario

@expectation begin
    return ExampleScenario(sum([probability(s)*s.ξ for s in scenarios]))
end

See also @define_scenario

StochasticPrograms.@samplerMacro
@sampler(def)

Define a sampler type for some scenariotype compatible with StochasticPrograms using the syntax

@sampler samplername = begin
    ...internals...

    @sample scenariotype begin
        ...
        return scenario
    end
end

Any internal state required by the sampler, as well as any specialized constructor, are defined in the @sampler block as they would be in any Julia struct. Define the sample operation inside the @sample block and specify the scenariotype that the sampler returns. The defined sampler will be available on all Julia processes.

Examples

The following defines a simple dummy sampler, with some internal weight value, for the scenario defined in @scenario, and samples one scenario.

@sampler ExampleSampler = begin
    w::Float64

    ExampleSampler(w::AbstractFloat) = new(w)

    @sample ExampleScenario begin
        @parameters w
        return ExampleScenario(w*randn(), probability = rand())
    end
end
s = ExampleSampler(2.0)
s()

# output

ExampleScenario with probability 0.29
  ξ: 1.48

See also: @sample, @scenario

StochasticPrograms.@sampleMacro
@sample(def)

Define the sample operaton inside a @sampler block, using the syntax

@sample begin
    ...
    return sampled_scenario
end

The sampler object is referenced through the reserved keyword sampler, from which any internals can be accessed.

Model definition

StochasticPrograms.@stageMacro
@stage(def)

Add a stage model generation recipe to stochasticprogram using the syntax

@stage stage stochasticprogram::StochasticProgram = begin
    @parameters param1 param2 ...
    @decision(stochasticprogram, var) ...
    @uncertain ξ
    ... JuMPdef ...
    ...
end

where stage is the stage number and JuMP syntax is used inside the block to define the stage model. During definition, the stage model is referenced using the same variable name as stochasticprogram.

Examples

The following defines the first stage model given by:

\[ minimize 100x₁ + 150x₂ s.t x₁ + x₂ ≤ 120 x₁ ≥ 40 x₂ ≥ 20\]

and the second-stage model given by:

\[ maximize q₁(ξ)y₁ + q₂(ξ)y₂ s.t 6y₁ + 10y₂ ≤ 60x₁ 8y₁ + 5y₂ ≤ 60x₂ 0 ≤ y₁ ≤ d₁(ξ) 0 ≤ y₂ ≤ d₂(ξ)\]

where $q₁(ξ), q₂(ξ), d₁(ξ), d₂(ξ)$ depend on the scenario $ξ$ and $x₁, x₂$ are first stage variables. Two scenarios are added so that two second stage models are generated.

ξ₁ = @scenario q₁ = 24.0 q₂ = 28.0 d₁ = 500.0 d₂ = 100.0 probability = 0.4
ξ₂ = @scenario q₁ = 28.0 q₂ = 32.0 d₁ = 300.0 d₂ = 300.0 probability = 0.6

sp = StochasticProgram([ξ₁, ξ₂])

@stage 1 sp = begin
    @decision(sp, x₁ >= 40)
    @decision(sp, x₂ >= 20)
    @objective(sp, Min, 100*x₁ + 150*x₂)
    @constraint(sp, x₁ + x₂ <= 120)
end

@stage 2 sp = begin
    @uncertain q₁ q₂ d₁ d₂
    @variable(sp, 0 <= y₁ <= d₁)
    @variable(sp, 0 <= y₂ <= d₂)
    @objective(sp, Max, q₁*y₁ + q₂*y₂)
    @constraint(sp, 6*y₁ + 10*y₂ <= 60*x₁)
    @constraint(sp, 8*y₁ + 5*y₂ <= 80*x₂)
end

# output

Stochastic program with:
 * 2 decision variables
 * 2 scenarios of type Scenario
Solver is default solver

See also: @parameters, @decision, @uncertain

StochasticPrograms.@first_stageMacro
@first_stage(def)

Add a first stage model generation recipe to stochasticprogram using the syntax

@first_stage stochasticprogram::StochasticProgram = begin
    ...
end [defer]

where JuMP syntax is used inside the block to define the first stage model. During definition, the first stage model is referenced through the reserved keyword matching the name of stochasticprogram.

Examples

The following defines the first stage model given by:

\[ minimize 100x₁ + 150x₂ s.t x₁ + x₂ ≤ 120 x₁ ≥ 40 x₂ ≥ 20\]

@first_stage sp = begin
    @decision(sp, x₁ >= 40)
    @decision(sp, x₂ >= 20)
    @objective(sp, Min, 100*x₁ + 150*x₂)
    @constraint(sp, x₁ + x₂ <= 120)
end

See also: @second_stage

StochasticPrograms.@second_stageMacro
@second_stage(def)

Add a second stage model generation recipe to stochasticprogram using the syntax

@second_stage stochasticprogram::StochasticProgram = begin
    @known var1 var2 ...
    ...
end

where JuMP syntax is used inside the block to define the second stage model. During definition, the second stage model is referenced through the reserved keyword matching the name of stochasticprogram.

Examples

The following defines the second stage model given by:

\[ minimize q₁(ξ)y₁ + q₂(ξ)y₂ s.t 6y₁ + 10y₂ ≤ 60x₁ 8y₁ + 5y₂ ≤ 60x₂ 0 ≤ y₁ ≤ d₁(ξ) 0 ≤ y₂ ≤ d₂(ξ)\]

where $q₁(ξ), q₂(ξ), d₁(ξ), d₂(ξ)$ depend on the scenario $ξ$ and $x₁, x₂$ are first stage variables. Two scenarios are added so that two second stage models are generated.

@second_stage sp = begin
    @known(sp, x₁, x₂)
    @uncertain q₁ q₂ d₁ d₂
    @variable(sp, 0 <= y₁ <= d₁)
    @variable(sp, 0 <= y₂ <= d₂)
    @objective(sp, Min, q₁*y₁ + q₂*y₂)
    @constraint(sp, 6*y₁ + 10*y₂ <= 60*x₁)
    @constraint(sp, 8*y₁ + 5*y₂ <= 80*x₂)
end

See also: @first_stage

StochasticPrograms.@decisionMacro
@decision(model, expr, args..., kw_args...)

Add a decision variable to model described by the expression expr. If used inside a @stage block, the created variable can be used in subsequent stage blocks. @recourse should be used to mark decisions in the final stage. See @variable for syntax details.

Examples

@decision(model, x >= 40)

See also @recourse, @parameters, @uncertain, @stage

StochasticPrograms.@parametersMacro
@parameters(def)

Define the problem parameters in a @stage block

@parameters param1, param2, ...

possibly with default values. Any defined parameter without a default value must be supplied as a keyword argument to instantiate when creating models.

Examples

@parameters d

@parameters begin
    Crops = [:wheat, :corn, :beets]
    Cost = Dict(:wheat=>150, :corn=>230, :beets=>260)
    Budget = 500
end

See also @decision, @uncertain, @stage

StochasticPrograms.@uncertainMacro
@uncertain(def)

In a @stage block, annotate each uncertain variable using the syntax

@uncertain var1, var2, ...

or using JuMP's container syntax

@uncertain ξ[i=..., j=..., ...]

This assumes that the [Scenario] type is used. Matching scenario data is then conveniently created using @scenario.

Alternatively, user-defined scenarios can be specified by annotating the type. Also, inside a @stochasticmodel block, user-defined scenarios can be created during the @uncertain annotation, using [`@definescenario`](@ref) syntax.

Examples

The following are equivalent ways of declaring a random vector $[q₁(ξ) q₂(ξ) d₁(ξ) d₂(ξ)]$ in a @stage block, and creating a matching scenario instance of probability $0.4$ and values $[24.0 28.0 500.0 100.0]$

@uncertain q₁ q₂ d₁ d₂
ξ₁ = @scenario q₁ = 24.0 q₂ = 28.0 d₁ = 500.0 d₂ = 100.0 probability = 0.4

@uncertain ξ[i in 1:4]
ξ₁ = @scenario ξ[i in 1:4] = [24.0, 28.0, 500.0, 100.0] probability = 0.4

@define_scenario SimpleScenario = begin
    q₁::Float64
    q₂::Float64
    d₁::Float64
    d₂::Float64
end
@uncertain ξ::SimpleScenario
ξ₁ = SimpleScenario(24.0, 28.0, 500.0, 100.0, probability = 0.4)

@stochastic_model begin
    ...
    @uncertain ξ::SimpleScenario = begin
        q₁::Float64
        q₂::Float64
        d₁::Float64
        d₂::Float64
    end
    ...
end
ξ₁ = SimpleScenario(24.0, 28.0, 500.0, 100.0 probability = 0.4)

See also @scenario, @define_scenario, @parameters, @decision, @stage

StochasticPrograms.@stochastic_modelMacro
@stochastic_model(def)

Define a stochastic model capable of instantiating stochastic programs, using the syntax

@stochastic_model model_name begin
    ...
    @stage x begin
      ...
    end
    ...
end

where the inner blocks are @stage blocks. At least two stages must be specified in consecutive order. A stochastic model object can later be used to instantiate stochastic programs using a given set of scenarios or by using samplers. The model is referenced using model_name in the @stage blocks. If model_name is left out, the macro returns an anonymous model object, and the reserved keyword model must be used in the @stage blocks. Otherwise, the resulting stochastic model object is stored in a variable named model_name.

Examples

The following defines a stochastic model consisitng of the first stage model given by:

\[ minimize 100x₁ + 150x₂ s.t x₁ + x₂ ≤ 120 x₁ ≥ 40 x₂ ≥ 20\]

and the second-stage model given by:

\[ minimize q₁(ξ)y₁ + q₂(ξ)y₂ s.t 6y₁ + 10y₂ ≤ 60x₁ 8y₁ + 5y₂ ≤ 60x₂ 0 ≤ y₁ ≤ d₁(ξ) 0 ≤ y₂ ≤ d₂(ξ)\]

where $q₁(ξ), q₂(ξ), d₁(ξ), d₂(ξ)$ depend on the scenario $ξ$.

@stochastic_model sm begin
    @stage 1 begin
        @decision(sm, x₁ >= 40)
        @decision(sm, x₂ >= 20)
        @objective(sm, Min, 100*x₁ + 150*x₂)
        @constraint(sm, x₁ + x₂ <= 120)
    end
    @stage 2 begin
        @uncertain q₁ q₂ d₁ d₂
        @variable(sm, 0 <= y₁ <= d₁)
        @variable(sm, 0 <= y₂ <= d₂)
        @objective(sm, Min, q₁*y₁ + q₂*y₂)
        @constraint(sm, 6*y₁ + 10*y₂ <= 60*x₁)
        @constraint(sm, 8*y₁ + 5*y₂ <= 80*x₂)
    end
end

or alternatively using anonymous syntax:

sm = @stochastic_model begin
    @stage 1 begin
        @decision(model, x₁ >= 40)
        @decision(model, x₂ >= 20)
        @objective(model, Min, 100*x₁ + 150*x₂)
        @constraint(model, x₁ + x₂ <= 120)
    end
    @stage 2 begin
        @uncertain q₁ q₂ d₁ d₂
        @variable(model, 0 <= y₁ <= d₁)
        @variable(model, 0 <= y₂ <= d₂)
        @objective(model, Min, q₁*y₁ + q₂*y₂)
        @constraint(model, 6*y₁ + 10*y₂ <= 60*x₁)
        @constraint(model, 8*y₁ + 5*y₂ <= 80*x₂)
    end
end

where the reserved keyword model is used throughout.

See also: @stage, @parameters, @decision, @uncertain

API

Base.getindexMethod
Base.getindex(stochasticprogram::StochasticProgram, stage::Integer, name::Symbol)

Returns the decision, or group of decisions, or decision constraint, or group of decision constraints, of the given name and stage of the stochasticprogram which were added to the model. This errors if regular variables or constraints are queried. If so, either annotate the relevant variables with @decision or first query the relevant JuMP subproblem and use the regular [] syntax.

JuMP.dual_statusMethod
dual_status(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return the status of the most recent dual solution of the solver of the node at stage stage and scenario scenario_index.

JuMP.dual_statusMethod
dual_status(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return the status of the most recent dual solution of the solver of scenario scenario_index.

JuMP.dual_statusMethod
dual_status(stochasticprogram::StochasticProgram; result::Int = 1)

Return the status of the most recent dual solution of the solver of the stochasticprogram.

JuMP.num_variablesMethod
num_variables(stochasticprogram::StochasticProgram, stage::Integer = 1)

Return the total number of variables at stage in the stochasticprogram. Defaults to the first stage.

JuMP.objective_valueMethod
objective_value(stochasticmodel::StochasticModel; result::Int = 1)

Returns a confidence interval around the value of the recourse problem after a call to optimize!(stochasticmodel).

JuMP.optimize!Method
optimize!(stochasticmodel::StochasticModel, sampler::AbstractSampler; crash::AbstractCrash = Crash.None(), kw...)

Approximately optimize the stochasticmodel when the underlying scenario distribution is inferred by sampler. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

JuMP.optimize!Method
optimize!(stochasticprogram::StochasticProgram; crash::AbstractCrash = Crash.None(), cache::Bool = false; kw...)

Optimize the stochasticprogram in expectation. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown. An optional crash procedure can be set to warm-start. Setting the cache flag to true will, upon sucessful termination, try to cache the solution values for all relevant attributes in the model. The values will then persist after future evaluate calls that would otherwise overwrite the optimal solution.

Examples

The following solves the stochastic program sp using the L-shaped algorithm.

set_optimizer(sp, LShaped.Optimizer)
set_optimizer_attribute(sp, MasterOptimizer(), GLPK.Optimizer)
set_optimizer_attribute(sp, SubProblemOptimizer(), GLPK.Optimizer)
optimize!(sp);

# output

L-Shaped Gap  Time: 0:00:02 (6 iterations)
  Objective:       -855.8333333333358
  Gap:             0.0
  Number of cuts:  8
  Iterations:      6

The following solves the stochastic program sp using GLPK on the extended form.

using GLPK

set_optimizer(sp, GLPK.Optimizer)
optimize!(sp)

See also: VRP

JuMP.primal_statusMethod
primal_status(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer; result::Int = 1)

Return the status of the most recent primal solution of the solver of the node at stage stage and scenario scenario_index.

JuMP.primal_statusMethod
primal_status(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer; result::Int = 1)

Return the status of the most recent primal solution of the solver of the scenario scenario_index.

JuMP.primal_statusMethod
primal_status(stochasticprogram::StochasticProgram; result::Int = 1)

Return the status of the most recent primal solution of the solver of the stochasticprogram.

JuMP.raw_statusMethod
raw_status(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the reason why the solver of the node at stage stage and scenario scenario_index stopped in its own words.

JuMP.raw_statusMethod
raw_status(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

Return the reason why the solver of scenario scenario_index stopped in its own words.

JuMP.raw_statusMethod
raw_status(stochasticprogram::StochasticProgram)

Return the reason why the solver of the stochasticprogram stopped in its own words.

JuMP.set_optimizerMethod
set_optimizer(stochasticmodel::StochasticModel, optimizer)

Set the optimizer of the stochasticmodel.

JuMP.set_optimizerMethod
set_optimizer(stochasticprogram::StochasticProgram, optimizer)

Set the optimizer of the stochasticprogram.

JuMP.set_optimizer_attributesMethod
set_optimizer_attributes(stochasticprogram::StochasticProgram, pairs::Pair...)

Given a list of attribute => value pairs or a collection of keyword arguments, calls set_optimizer_attribute(stochasticprogram, attribute, value) for each pair.

See also: get_optimizer_attribute

JuMP.solve_timeMethod
solve_time(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

If available, returns the solve time reported by the solver of the node at stage stage and scenario scenario_index.

JuMP.solve_timeMethod
solve_time(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

If available, returns the solve time reported by the solver of scenario scenario_index.

JuMP.solve_timeMethod
solve_time(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

If available, returns the solve time reported by the solver of the stochasticprogram.

JuMP.termination_statusMethod
termination_status(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the reason why the solver of the node at stage stage and scenario scenario_index stopped.

JuMP.termination_statusMethod
termination_status(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

Return the reason why the solver of scenario scenario_index stopped.

JuMP.termination_statusMethod
termination_status(stochasticprogram::StochasticProgram)

Return the reason why the solver of the stochasticprogram stopped.

StochasticPrograms.add_scenario!Method
add_scenario!(scenariogenerator::Function, stochasticprogram::StochasticProgram, stage::Integer)

Store the scenario returned by scenariogenerator in the stage of the stochasticprogram. If the stochasticprogram is distributed, the scenario will be defined on the node that currently has the fewest scenarios.

StochasticPrograms.add_scenario!Method
add_scenario!(scenariogenerator::Function, stochasticprogram::StochasticProgram)

Store the scenario returned by scenariogenerator in the two-stage stochasticprogram. If the stochasticprogram is distributed, the scenario will be defined on the node that currently has the fewest scenarios.

StochasticPrograms.add_scenario!Method
add_scenario!(stochasticprogram::StochasticProgram, stage::Integer, scenario::AbstractScenario)

Store the second stage scenario in the stochasticprogram at stage.

If the stochasticprogram is distributed, the scenario will be defined on the node that currently has the fewest scenarios.

StochasticPrograms.add_scenario!Method
add_scenario!(stochasticprogram::TwoStageStochasticProgram, scenario::AbstractScenario)

Store the second stage scenario in the two-stage stochasticprogram.

StochasticPrograms.add_scenarios!Method
add_scenarios!(scenariogenerator::Function, stochasticprogram::StochasticProgram, stage::Integer, n::Integer)

Generate n scenarios using scenariogenerator and store in the stochasticprogram at stage. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.add_scenarios!Method
add_scenarios!(scenariogenerator::Function, stochasticprogram::TwoStageStochasticProgram, n::Integer)

Generate n scenarios using scenariogenerator and store in the two-stage stochasticprogram. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.add_scenarios!Method
add_scenarios!(stochasticprogram::StochasticProgram, stage::Integer, scenarios::Vector{<:AbstractScenario})

Store the collection of scenarios in the stochasticprogram at stage. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.add_scenarios!Method
add_scenarios!(stochasticprogram::TwoStageStochasticProgram, scenarios::Vector{<:AbstractScenario})

Store the collection of scenarios in the two-stage stochasticprogram. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.add_worker_scenario!Method
add_worker_scenario!(scenariogenerator::Function, stochasticprogram::StochasticProgram, stage::Integer, w::Integer)

Store the scenario returned by scenariogenerator in worker node w of the stochasticprogram at stage.

StochasticPrograms.add_worker_scenario!Method
add_worker_scenario!(scenariogenerator::Function, stochasticprogram::TwoStageStochasticProgram, w::Integer)

Store the scenario returned by scenariogenerator in worker node w of the two-stage stochasticprogram.

StochasticPrograms.add_worker_scenario!Method
add_worker_scenario!(stochasticprogram::StochasticProgram, stage::Integer, scenario::AbstractScenario, w::Integer)

Store the second stage scenario in worker node w of the stochasticprogram at stage.

StochasticPrograms.add_worker_scenario!Method
add_worker_scenario!(stochasticprogram::StochasticProgram, stage::Integer, scenario::AbstractScenario, w::Integer)

Store the second stage scenario in worker node w of the two-stage stochasticprogram.

StochasticPrograms.add_worker_scenarios!Method
add_worker_scenarios!(scenariogenerator::Function, stochasticprogram::StochasticProgram, stage::Integer, n::Integer, w::Integer)

Generate n scenarios using scenariogenerator and store them in worker node w of the stochasticprogram at stage.

StochasticPrograms.add_worker_scenarios!Method
add_worker_scenarios!(scenariogenerator::Function, stochasticprogram::TwoStageStochasticProgram, n::Integer, w::Integer)

Generate n scenarios using scenariogenerator and store them in worker node w of the two-stage stochasticprogram.

StochasticPrograms.add_worker_scenarios!Method
add_worker_scenarios!(stochasticprogram::StochasticProgram, stage::Integer, scenarios::Vector{<:AbstractScenario}, w::Integer)

Store the collection of scenarios in in worker node w of the stochasticprogram at stage.

StochasticPrograms.add_worker_scenarios!Method
add_worker_scenarios!(stochasticprogram::StochasticProgram, stage::Integer, scenarios::Vector{<:AbstractScenario}, w::Integer)

Store the collection of scenarios in in worker node w of the two-stage stochasticprogram.

StochasticPrograms.all_decision_variablesMethod
all_decision_variables(stochasticprogram::StochasticProgram{N}, stage::Integer = 1) where N

Returns a list of all decisions currently in the stochasticprogram at stage. The decisions are ordered by creation time.

StochasticPrograms.all_decision_variablesMethod
all_decision_variables(stochasticprogram::StochasticProgram{N}) where N

Returns a stage-wise list of all decisions currently in the stochasticprogram. The decisions are ordered by creation time. Defaults to the first stage.

StochasticPrograms.cache_solution!Method
cache_solution!(stochasticprogram::StochasticProgram)

Cache the optimal solution, including as many model/variable/constraints attributes as possible, after a call to optimize!

StochasticPrograms.decisionMethod
decision(stochasticprogram::StochasticProgram, index::MOI.VariableIndex)

Return the current value of the first-stage decision at index of stochasticprogram.

StochasticPrograms.decisionMethod
decision(stochasticprogram::StochasticProgram)

Return the current first-stage decision values of stochasticprogram.

StochasticPrograms.deferredMethod
deferred(stochasticprogram::StochasticProgram)

Return true if stochasticprogram is not fully generated.

StochasticPrograms.distributedFunction
distributed(stochasticprogram::StochasticProgram, s::Integer = 2)

Return true if the stochasticprogram is memory distributed at stage s. Defaults to the second stage.

StochasticPrograms.expectedMethod
expected(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return the exected scenario of all scenarios of the stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.generatorMethod
generator(stochasticprogram::StochasticProgram, key::Symbol)

Return the problem generator associated with key in stochasticprogram.

StochasticPrograms.has_generatorMethod
has_generator(stochasticprogram::StochasticProgram, key::Symbol)

Return true if a problem generator with key exists in stochasticprogram.

StochasticPrograms.instantiateMethod
instantiate(stochasticmodel::StochasticModel{2},
            scenarios::Vector{<:AbstractScenario};
            instantiation::StochasticInstantiation = UnspecifiedInstantiation(),
            optimizer = nothing;
            defer::Bool = false,
            kw...)

Instantiate a two-stage stochastic program using the model definition stored in the two-stage stochasticmodel, and the given collection of scenarios. Optionally, supply an optimizer. If no explicit instantiation is provided, the structure is induced by the optimizer. The structure is Deterministic by default.

StochasticPrograms.instantiateMethod
instantiate(stochasticmodel::StochasticModel,
            scenarios::Vector{<:AbstractScenario};
            instantiation::StochasticInstantiation = UnspecifiedInstantiation(),
            optimizer = nothing,
            defer::Bool = false,
            kw...)

Instantiate a stochastic program using the model definition stored in stochasticmodel, and the given collection of scenarios. Optionally, supply an optimizer. If no explicit instantiation is provided, the structure is induced by the optimizer. The structure is Deterministic by default.

StochasticPrograms.instantiateMethod
instantiate(stochasticmodel::StochasticModel{2};
            instantiation::StochasticInstantiation = UnspecifiedInstantiation(),
            optimizer = nothing,
            scenario_type::Type{S} = Scenario,
            defer::Bool = false,
            kw...) where S <: AbstractScenario

Instantiate a deferred two-stage stochastic program using the model definition stored in the two-stage stochasticmodel over the scenario type S. Optionally, supply an optimizer. If no explicit instantiation is provided, the structure is induced by the optimizer. The structure is Deterministic by default.

StochasticPrograms.instantiateMethod
instantiate(stochasticmodel::StochasticModel,
            sampler::AbstractSampler,
            n::Integer;
            instantiation::StochasticInstantiation = UnspecifiedInstantiation(),
            optimizer = nothing,
            defer::Bool = false,
            kw...)

Generate a sampled instance of size n using the model stored in the two-stage stochasticmodel, and the provided sampler. Optionally, supply an optimizer. If no explicit instantiation is provided, the structure is induced by the optimizer. The structure is Deterministic by default.

StochasticPrograms.master_optimizerMethod
master_optimizer(stochasticprogram::StochasticProgram)

Return a MOI optimizer using the currently provided optimizer of stochasticprogram.

StochasticPrograms.num_decisionsMethod
num_decisions(stochasticprogram::StochasticProgram, stage::Integer = 1)

Return the number of decisions at stage in the stochasticprogram. Defaults to the first stage.

StochasticPrograms.num_scenariosFunction
num_scenarios(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return the number of scenarios in the stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.num_subproblemsFunction
num_subproblems(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return the number of subproblems in the stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.optimal_decisionMethod
optimal_decision(stochasticmodel::StochasticModel)

Return the optimal first stage decision of stochasticmodel, after a call to optimize!(stochasticmodel).

StochasticPrograms.optimal_decisionMethod
optimal_decision(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the optimal decision in the node at stage stage and scenario scenario_index of stochasticprogram, after a call to optimize!(stochasticprogram).

StochasticPrograms.optimal_decisionMethod
optimal_decision(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

Return the optimal decision in scenario scenario_index of the two-stage stochasticprogram, after a call to optimize!(stochasticprogram).

StochasticPrograms.optimal_decisionMethod
optimal_decision(stochasticprogram::StochasticProgram)

Return the optimal first stage decision of stochasticprogram, after a call to optimize!(stochasticprogram).

StochasticPrograms.optimal_recourse_decisionMethod
optimal_recourse_decision(stochasticprogram::StochasticProgram, scenario_index::Integer)

Return the optimal recourse decision in the final stage of stochasticprogram in the scenario scenario_index, after a call to optimize!(stochasticprogram).

StochasticPrograms.probabilityMethod
probability(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

Return the probability of the scenario at scenario_index in the two-stage stochasticprogram occuring.

StochasticPrograms.probabilityMethod
probability(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the probability of the scenario at scenario_index in the stochasticprogram at stage occuring.

StochasticPrograms.proxyMethod
proxy(stochasticprogram::StochasticProgram, stage::Integer)

Return the proxy model of the stochasticprogram at stage.

StochasticPrograms.sample!Method
sample!(stochasticprogram::StochasticProgram, stage::Integer, sampler::AbstractSampler, n::Integer)

Sample n scenarios using sampler and add to the stochasticprogram at stage. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.sample!Method
sample!(stochasticprogram::TwoStageStochasticProgram, sampler::AbstractSampler, n::Integer)

Sample n scenarios using sampler and add to the two-stage stochasticprogram. If the stochasticprogram is distributed, scenarios will be distributed evenly across workers.

StochasticPrograms.scenarioMethod
scenario(stochasticprogram::TwoStageStochasticProgram, scenario_index::Integer)

Return the scenario at scenario_index of the two-stage stochasticprogram

StochasticPrograms.scenarioMethod
scenario(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the scenario at scenario_index of stochasticprogram at stage stage.

StochasticPrograms.scenario_typeMethod
scenario_type(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return the type of the scenario structure associated with stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.scenariosMethod
scenarios(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return an array of all scenarios of the stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.stage_probabilityMethod
stage_probability(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return the probability of any scenario in the stochasticprogram at stage occuring. A well defined model should return 1. Defaults to the second stage.

StochasticPrograms.structureMethod
structure(stochasticprogram::StochasticProgram)

Return the underlying structure of the stochasticprogram.

StochasticPrograms.structure_nameMethod
structure_name(stochasticprogram::StochasticProgram)

Return the name of the underlying structure of the stochasticprogram.

StochasticPrograms.subproblemMethod
subproblem(stochasticprogram::TwoStasgeStochasticProgram, scenario_index::Integer)

Return the subproblem at scenario_index of the two-stage stochasticprogram.

StochasticPrograms.subproblemMethod
subproblem(stochasticprogram::StochasticProgram, stage::Integer, scenario_index::Integer)

Return the subproblem at scenario_index of the stochasticprogram at stage.

StochasticPrograms.subproblem_optimizerMethod
subproblem_optimizer(stochasticprogram::StochasticProgram)

Return a MOI optimizer for solving subproblems using the currently provided optimizer of stochasticprogram.

StochasticPrograms.subproblemsMethod
subproblems(stochasticprogram::StochasticProgram, stage::Integer = 2)

Return an array of all subproblems of the stochasticprogram at stage. Defaults to the second stage.

StochasticPrograms.update_decisions!Method
update_decisions!(stochasticprogram::Stochasticprogram, stage::Integer, scenario_index::Integer)

Update all known decision values in the node at stage stage and scenario scenario_index of stochasticprogram.

StochasticPrograms.clear!Method
clear!(stochasticprogram::StochasticProgram)

Clear the stochasticprogram, removing all model definitions.

StochasticPrograms.generate!Method
generate!(stochasticprogram::StochasticProgram)

Generate the stochasticprogram using the model definitions from @stage and available data.

StochasticPrograms.outcome_modelMethod
outcome_model(stochasticprogram::TwoStageStochasticProgram,
              decision::AbstractVector,
              scenario::AbstractScenario;
              optimizer = nothing)

Return the resulting second stage model if decision is the first-stage decision in the provided scenario, in stochasticprogram. The supplied decision must match the defined decision variables in stochasticprogram. Optionally, supply a capable optimizer to the outcome model.

StochasticPrograms.outcome_modelMethod
outcome_model(stochasticprogram::StochasticProgram{N},
              decisions::NTuple{N-1,AbstractVector}
              scenario_path::NTuple{N-1,AbstractScenario},
              optimizer = nothing)

Return the resulting N:th stage model if decisions are the decisions taken in the previous stages and scenario_path are the realized scenarios up to stage N in stochasticprogram. Optionally, supply a capable solver to the outcome model.

StochasticPrograms.stage_modelMethod
stage_model(stochasticprogram::StochasticProgram, stage::Integer, scenario::AbstractScenario; optimizer = nothing)

Return a generated stage model corresponding to scenario, in stochasticprogram. Optionally, supply a capable optimizer to the stage model.

StochasticPrograms.stage_one_modelMethod
stage_one_model(stochasticprogram::StochasticProgram; optimizer = nothing)

Return a generated copy of the first stage model in stochasticprogram. Optionally, supply a capable optimizer to the stage model.

StochasticPrograms.confidence_intervalMethod
confidence_interval(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler)

Generate a confidence interval around the true optimum of the two-stage stochasticmodel at level confidence using SAA, over the scenario distribution induced by sampler.

The attribute NumSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The attribute NumLowerTrials is the number of sampled models used in the lower bound calculation and the attribute NumUpperTrials is the number of sampled models used in the upper bound calculation. The attribute NumEvalSamples is the size of the sampled models used in the upper bound calculation. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.evaluate_decisionMethod
evaluate_decision(stochasticmodel::StochasticModel{2}, decision::AbstractVector, sampler::AbstractSampler; kw...)

Return a statistical estimate of the objective of the two-stage stochasticmodel at decision in the form of a confidence interval at the current confidence level, over the scenario distribution induced by sampler.

In other words, evaluate decision on a sampled model and generate an confidence interval using the sample variance of the evaluation. The confidence level can be set through the Confidence attribute and the sample size can be set through the NumEvalSamples attribute.

The supplied decision must match the defined decision variables in stochasticmodel. If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: confidence_interval

StochasticPrograms.evaluate_decisionMethod
evaluate_decision(stochasticprogram::TwoStageStochasticProgram, decision::AbstractVector, scenario::AbstractScenario)

Evaluate the result of taking the first-stage decision if scenario is the actual outcome in stochasticprogram. The supplied decision must match the defined decision variables in stochasticprogram. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.evaluate_decisionMethod
evaluate_decision(stochasticprogram::TwoStageStochasticProgram, decision::AbstractVector)

Evaluate the first-stage decision in stochasticprogram.

In other words, evaluate the first-stage objective at decision and solve outcome models of decision for every available scenario. The supplied decision must match the defined decision variables in stochasticprogram. If a optimal solution to stochasticprogram has been determined, but cache_solution! has not been called, then the solution will be overwritten by this call. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.gapMethod
gap(stochasticmodel::StochasticModel{2}, decision::UnionAbstractVector, sampler::AbstractSampler)

Generate a confidence interval around the gap between the result of using decision and the true optimum of the two-stage stochasticmodel at the current confidence level, over the scenario distribution induced by sampler.

The attribute NumSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The attribute NumLowerTrials is the number of sampled models used in the lower bound calculation and the attribute NumUpperTrials is the number of sampled models used in the upper bound calculation. The attribute NumEvalSamples is the size of the sampled models used in the upper bound calculation. The confidence level can be set through the Confidence attribute.

The supplied decision must match the defined decision variables in stochasticmodel. If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.lower_confidence_intervalMethod
lower_confidence_interval(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler; kw...)

Generate a confidence interval around a lower bound on the true optimum of the two-stage stochasticmodel at the current confidence level, over the scenario distribution induced by sampler.

The attribute NumSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The attribute NumLowerTrials is the number of sampled models. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.recourse_decisionMethod
recourse_decision(stochasticprogram::TwoStageStochasticProgram, decision::AbstractVector, scenario::AbstractScenario)

Determine the optimal recourse decision after taking the first-stage decision if scenario is the actual outcome in stochasticprogram. The supplied decision must match the defined decision variables in stochasticprogram. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.statistically_evaluate_decisionMethod
statistically_evaluate_decision(stochasticprogram::TwoStageStochasticProgram, decision::AbstractVector)

Statistically evaluate the first-stage decision in stochasticprogram, returning the evaluated value and the spread over the scenarios.

The supplied decision must match the defined decision variables in stochasticprogram. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.upper_confidence_intervalMethod
upper_confidence_interval(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler; kw...)

Generate a confidence interval around an upper bound of the true optimum of the two-stage stochasticmodel at the current confidence level, over the scenario distribution induced by sampler, by generating and evaluating a candidate decision.

The attribute NumSamples is the size of the sampled model used to generate a candidate decision. The attribute NumUpperTrials is the number of sampled models and the attribute NumEvalSamples is the size of the evaluation models. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.upper_confidence_intervalMethod
upper_confidence_interval(stochasticmodel::StochasticModel{2}, decision::AbstractVector, sampler::AbstractSampler; kw...)

Generate a confidence interval around an upper bound of the expected value of decision in the two-stage stochasticmodel at the current confidence level, over the scenario distribution induced by sampler.

The attribute NumUpperTrials is the number of sampled models and the attribute NumEvalSamples is the size of the evaluation models. The confidence level can be set through the Confidence attribute.

The supplied decision must match the defined decision variables in stochasticmodel. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

Stochastic programming constructs

StochasticPrograms.DEPMethod
DEP(stochasticprogram::TwoStageStochasticProgram; optimizer = nothing)

Generate the deterministically equivalent problem (DEP) of the two-stage stochasticprogram, unless a cached version already exists.

In other words, generate the extended form the stochasticprogram as a single JuMP model. Optionally, a capable optimizer can be supplied to DEP.

See also: VRP, WS

StochasticPrograms.EEVMethod
EEV(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler)

Approximately calculate the expected value of the expected value decision (EEV) of the two-stage stochasticmodel to the current confidence level, over the scenario distribution induced by sampler.

The attribute NumEEVSamples is the size of the sampled models used in the eev calculation. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: EVP, EV

StochasticPrograms.EEVMethod
EEV(stochasticprogram::TwoStageStochasticProgram)

Calculate the expected value of the expected value solution (EEV) of the two-stage stochasticprogram.

In other words, evaluate the EVP decision. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: EVP, EV

StochasticPrograms.EVPMethod
EVP(stochasticprogram::TwoStageStochasticProgram; optimizer = nothing)

Generate the expected value problem (EVP) of the two-stage stochasticprogram.

In other words, generate a wait-and-see model corresponding to the expected scenario over all available scenarios in stochasticprogram. Optionally, a capable optimizer can be supplied to WS.

See also: expected_value_decision, EEV, EV, WS

StochasticPrograms.EVPIMethod
EVPI(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler)

Approximately calculate the expected value of perfect information (EVPI) of the two-stage stochasticmodel to the current confidence level, over the scenario distribution induced by sampler.

In other words, calculate confidence intervals around VRP and EWS. If they do not overlap, the EVPI is statistically significant, and a confidence interval is calculated and returned.

The attribute NumSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The attribute NumLowerTrials is the number of sampled models used in the lower bound calculation and the attribute NumUpperTrials is the number of sampled models used in the upper bound calculation. The attribute NumEvalSamples is the size of the sampled models used in the upper bound calculation. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: VRP, EWS, VSS

StochasticPrograms.EVPIMethod
EVPI(stochasticprogram::TwoStageStochasticProgram)

Calculate the expected value of perfect information (EVPI) of the two-stage stochasticprogram.

In other words, calculate the gap between VRP and EWS. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: VRP, EWS, VSS

StochasticPrograms.EWSMethod
EWS(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler)

Approximately calculate the expected wait-and-see result (EWS) of the two-stage stochasticmodel to the current confidence level, over the scenario distribution induced by sampler.

The attribute NumEWSSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: VRP, WS

StochasticPrograms.EWSMethod
EWS(stochasticprogram::StochasticProgram)

Calculate the expected wait-and-see result (EWS) of the stochasticprogram.

In other words, calculate the expectated result of all possible wait-and-see models, using the provided scenarios in stochasticprogram.

If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: VRP, WS

StochasticPrograms.VRPMethod
VRP(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler; confidence = 0.95)

Return a confidence interval around the value of the recouse problem (VRP) of stochasticmodel to the given confidence level.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: EVPI, VSS, EWS

StochasticPrograms.VRPMethod
VRP(stochasticprogram::StochasticProgram)

Calculate the value of the recourse problem (VRP) in stochasticprogram.

In other words, optimize the stochastic program and return the optimal value.

If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: EVPI, EWS

StochasticPrograms.VSSMethod
VSS(stochasticmodel::StochasticModel{2}, sampler::AbstractSampler)

Approximately calculate the value of the stochastic solution (VSS) of the two-stage stochasticmodel to the current confidence level, over the scenario distribution induced by sampler.

In other words, calculate confidence intervals around EEV and VRP. If they do not overlap, the VSS is statistically significant, and a confidence interval is calculated and returned. is the number of samples in the out-of-sample evaluation of EEV.

The attribute NumSamples is the size of the sampled models used to generate the interval and generally governs how tight it is. The same size is used to generate the expected value decision. The attribute NumLowerTrials is the number of sampled models used in the lower bound calculation and the attribute NumUpperTrials is the number of sampled models used in the upper bound calculation. The attribute NumEvalSamples is the size of the sampled models used in the upper bound calculation and the attribute [NumEEVSamples] is the size of the sampled models used in the EEV calculation. The confidence level can be set through the Confidence attribute.

If a sample-based optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: VRP, EEV, EVPI

StochasticPrograms.VSSMethod
VSS(stochasticprogram::TwoStageStochasticProgram)

Calculate the value of the stochastic solution (VSS) of the two-stage stochasticprogram.

In other words, calculate the gap between EEV and VRP. If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

StochasticPrograms.WSMethod
WS(stochasticprogram::TwoStageStochasticProgram, scenario::AbstractScenarioaData; optimizer = nothing)

Generate a wait-and-see (WS) model of the two-stage stochasticprogram, corresponding to scenario.

In other words, generate the first stage and the second stage of the stochasticprogram as if scenario is known to occur. Optionally, a capable optimizer can be supplied to WS.

See also: DEP, EVP

StochasticPrograms.wait_and_see_decisionMethod
wait_and_see_decision(stochasticprogram::TwoStageStochasticProgram, scenario::AbstractScenario, optimizer_constructor = nothing)

Calculate the optimizer of the wait-and-see (WS) model of the two-stage stochasticprogram, corresponding to scenario.

If an optimizer has not been set yet (see set_optimizer), a NoOptimizer error is thrown.

See also: WS