Code Monkey home page Code Monkey logo

stochasticprograms.jl's People

Contributors

isoron avatar juliatagbot avatar martinbiel avatar metab0t avatar rtwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stochasticprograms.jl's Issues

Help with formulation

Hi Martin,
This is an amazing package for stochastic programming in Julia and I really like it. Thanks for the great contribution!

I have coded a CVaR optimisation problem using the extensive form (deterministic equivalent), but I would like to solve it using Lshaped method using your package. This is because I run into memory issues if number of scenarios or number of investments are increased.

I have given both my implementation using the the extensive form and my attempt at using your package. Would you be able to suggest corrections to the code in my attempt at using your package?

#Extensive form without using StochasticPrograms.jl
using JuMP
using Clp
# Generate random data for initial value of 5 investments
InitialValue= float(rand(80:140,1,5))
# Generate 10,000 scenarios for future value of investments and uncertain demand
FutureValue = float(rand(40:150,10000,5))
Demand = float(rand(40:50,10000))
nscen = size(FutureValue,1)
ninvestments = size(FutureValue,2)
# Create a vector of probabilities for scenarios 
prob = 1/nscen*ones(nscen)
# Calculate loss amount based on changes in value of investments
Loss = zeros(Float64,nscen,ninvestments)
Loss = -FutureValue.+InitialValue
# Assume 95% confidence level
α = 0.05
cvarRanmodel = Model(Clp.Optimizer)
@variable(cvarRanmodel,x[b=1:ninvestments]>=0)
@variable(cvarRanmodel,y[b=1:nscen]>=0)
@variable(cvarRanmodel,γ)
@constraint(cvarRanmodel,budget,sum(x[i] for i =1:ninvestments) == 1)
@constraint(cvarRanmodel,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:ninvestments) + γ >= 0)
@constraint(cvarRanmodel,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:ninvestments)-Demand[j] >= 0)
@objective(cvarRanmodel,Min,γ+1/(α)*sum(y[j]*prob[j] for j =1:nscen))
optimize!(cvarRanmodel)
println("")
println("VaR ", JuMP.value.(γ))
println("CVaR ", objective_value(cvarRanmodel))
println("Investment allocation",JuMP.value.(x))

My attempt at formulating it using your package is given below:

using StochasticPrograms
using GLPK
# Generate random data for initial value of 5 investments
InitialValue= float(rand(80:140,1,5))
# Generate 10,000 scenarios for future value of investments and uncertain demand
FutureValue = float(rand(40:150,10000,5))
Demand = float(rand(40:50,10000))
nscen = size(FutureValue,1)
ninvestments = size(FutureValue,2)
# Create a vector of probabilities for scenarios 
prob = 1/nscen*ones(nscen)
# Calculate loss amount based on changes in value of investments
Loss = zeros(Float64,nscen,ninvestments)
Loss = -FutureValue.+InitialValue
# Assume 95% confidence level
α = 0.05

sp_model = @stochastic_model begin
    @stage 1 begin
        @decision(model, x[b=1:ninvestments]>=0)
        @variable(model,γ)
        @objective(model, Min, γ)
        @constraint(model, sum(x[i] for i =1:ninvestments) == 1)
    end
    @stage 2 begin
        @uncertain Loss FutureValue Demand
        @variable(model,y[b=1:nscen]>=0)
        @objective(model,Min,1/(α)*sum(y[j]*prob[j] for j =1:nscen)) #Not sure how to write in StochasticPrograms.jl format
        @constraint(model,constraint2[j in 1:nscen], y[j]-sum(Loss[j,i]*x[i] for i in 1:ninvestments) + γ >= 0)  #Not sure how to write in StochasticPrograms.jl format
        @constraint(model,constraint3[j in 1:nscen], sum(FutureValue[j,i]*x[i] for i in 1:ninvestments)-Demand[j] >= 0)  #Not sure how to write in StochasticPrograms.jl format
    end
end
ξ = Scenario(Loss,FutureValue, Demand, y,prob ) #This is the part I am not getting right
sp_lshaped = instantiate(model, [ξ], optimizer = LShaped.Optimizer)
set_optimizer_attribute(sp_lshaped, MasterOptimizer(), GLPK.Optimizer)
set_optimizer_attribute(sp_lshaped, SubproblemOptimizer(), GLPK.Optimizer)
optimize!(sp_lshaped)

Can I use StochasticPrograms.jl with Conic Constraints?

Hi,

My second stage problem has a linear objective and the constraint is a power cone. Currently I am solving this second stage problem with Mosek. Can I use Stochastic Programs to solve the first stage?

edit:

Looks like it does not work :(

Solver name: Mosek
ERROR: LoadError: Unable to transform a quadratic constraint into a second-order cone
constraint because the quadratic constraint is not strongly convex.

Convex constraints that are not strongly convex (i.e., the matrix is
positive semidefinite but not positive definite) are not supported
yet.

Note that a quadratic equality constraint is non-convex.
Stacktrace:
  [1] error(s::String)
    @ Base .\error.jl:33
  [2] bridge_constraint(#unused#::Type{MathOptInterface.Bridges.Constraint.QuadtoSOCBridge{Float64}}, model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges.Constraint C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\Constraint\quad_to_soc.jl:82
  [3] add_bridged_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, f::MathOptInterface.ScalarQuadraticFunction{Float64}, s::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:1404
  [4] add_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, f::MathOptInterface.ScalarQuadraticFunction{Float64}, s::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:1483
  [5] normalize_and_add_constraint(model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64}; allow_modify_function::Bool)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\constraints.jl:19
  [6] normalize_and_add_constraint(model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\constraints.jl:19
  [7] bridge_objective(#unused#::Type{MathOptInterface.Bridges.Objective.SlackBridge{Float64, MathOptInterface.ScalarQuadraticFunction{Float64}, MathOptInterface.ScalarQuadraticFunction{Float64}}}, model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges.Objective C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\Objective\slack.jl:43
  [8] _bridge_objective(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:957
  [9] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, attr::MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarQuadraticFunction{Float64}}, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:995
 [10] bridge_objective
    @ C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\bridges\objectives\quadratic.jl:13 [inlined]
 [11] _bridge_objective(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, func::QuadraticDecisionFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:957
 [12] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, attr::MathOptInterface.ObjectiveFunction{QuadraticDecisionFunction{Float64}}, func::QuadraticDecisionFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:995
 [13] _pass_attributes(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}, idxmap::MathOptInterface.Utilities.IndexMap, attrs::Vector{MathOptInterface.AbstractModelAttribute}, supports_args::Tuple{}, get_args::Tuple{}, set_args::Tuple{}, pass_attr!::Function)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:300
 [14] pass_attributes
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:206 [inlined]
 [15] pass_attributes
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:202 [inlined]
 [16] default_copy_to(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}, copy_names::Bool, filter_constraints::Nothing)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:711
 [17] #automatic_copy_to#127
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:24 [inlined]
 [18] #copy_to#4
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:401 [inlined]
 [19] attach_optimizer(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\cachingoptimizer.jl:185
 [20] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\cachingoptimizer.jl:248
 [21] optimize!(structure::DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}, optimizer::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, x₀::Vector{Float64})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\deterministic_equivalent\optimization.jl:13
 [22] optimize!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}, StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}}; crash::StochasticPrograms.Crash.None, cache::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\api.jl:209
 [23] optimize!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}, StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\api.jl:201
 [24] top-level scope
    @ c:\Users\juan\Dropbox\Projects\JMP\others\MWE_2.jl:196
in expression starting at c:\Users\juan\Dropbox\Projects\JMP\others\MWE_2.jl:196

caused by: PosDefException: matrix is not positive definite; Cholesky factorization failed.
Stacktrace:
  [1] cholesky!(F::SuiteSparse.CHOLMOD.Factor{Float64}, A::SuiteSparse.CHOLMOD.Sparse{Float64}; shift::Float64, check::Bool)
    @ SuiteSparse.CHOLMOD C:\Users\juan\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\SuiteSparse\src\cholmod.jl:1150
  [2] #cholesky#8
    @ C:\Users\juan\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\SuiteSparse\src\cholmod.jl:1185 [inlined]
  [3] cholesky
    @ C:\Users\juan\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\SuiteSparse\src\cholmod.jl:1182 [inlined]
  [4] #cholesky#9
    @ C:\Users\juan\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\SuiteSparse\src\cholmod.jl:1297 [inlined]
  [5] cholesky
    @ C:\Users\juan\AppData\Local\Programs\Julia-1.7.1\share\julia\stdlib\v1.7\SuiteSparse\src\cholmod.jl:1297 [inlined]
  [6] bridge_constraint(#unused#::Type{MathOptInterface.Bridges.Constraint.QuadtoSOCBridge{Float64}}, model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges.Constraint C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\Constraint\quad_to_soc.jl:78
  [7] add_bridged_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, f::MathOptInterface.ScalarQuadraticFunction{Float64}, s::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:1404
  [8] add_constraint(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, f::MathOptInterface.ScalarQuadraticFunction{Float64}, s::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:1483
  [9] normalize_and_add_constraint(model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64}; allow_modify_function::Bool)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\constraints.jl:19
 [10] normalize_and_add_constraint(model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64}, set::MathOptInterface.GreaterThan{Float64})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\constraints.jl:19
 [11] bridge_objective(#unused#::Type{MathOptInterface.Bridges.Objective.SlackBridge{Float64, MathOptInterface.ScalarQuadraticFunction{Float64}, MathOptInterface.ScalarQuadraticFunction{Float64}}}, model::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges.Objective C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\Objective\slack.jl:43
 [12] _bridge_objective(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:957
 [13] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, attr::MathOptInterface.ObjectiveFunction{MathOptInterface.ScalarQuadraticFunction{Float64}}, func::MathOptInterface.ScalarQuadraticFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:995
 [14] bridge_objective
    @ C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\bridges\objectives\quadratic.jl:13 [inlined]
 [15] _bridge_objective(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, BridgeType::Type, func::QuadraticDecisionFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:957
 [16] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, attr::MathOptInterface.ObjectiveFunction{QuadraticDecisionFunction{Float64}}, func::QuadraticDecisionFunction{Float64})
    @ MathOptInterface.Bridges C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:995
 [17] _pass_attributes(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}, idxmap::MathOptInterface.Utilities.IndexMap, attrs::Vector{MathOptInterface.AbstractModelAttribute}, supports_args::Tuple{}, get_args::Tuple{}, set_args::Tuple{}, pass_attr!::Function)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:300
 [18] pass_attributes
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:206 [inlined]
 [19] pass_attributes
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:202 [inlined]
 [20] default_copy_to(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{MosekModel}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}, copy_names::Bool, filter_constraints::Nothing)
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:711
 [21] #automatic_copy_to#127
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\copy.jl:24 [inlined]
 [22] #copy_to#4
    @ C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Bridges\bridge_optimizer.jl:401 [inlined]
 [23] attach_optimizer(model::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\cachingoptimizer.jl:185
 [24] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}})
    @ MathOptInterface.Utilities C:\Users\juan\.julia\packages\MathOptInterface\YDdD3\src\Utilities\cachingoptimizer.jl:248
 [25] optimize!(structure::DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}, optimizer::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, x₀::Vector{Float64})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\deterministic_equivalent\optimization.jl:13
 [26] optimize!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}, StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}}; crash::StochasticPrograms.Crash.None, cache::Bool, kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\api.jl:209
 [27] optimize!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}, StochasticPrograms.Stage{NamedTuple{(), Tuple{}}}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:z₁, :z₂), Tuple{Float64, Float64}}}}}}})
    @ StochasticPrograms C:\Users\juan\.julia\packages\StochasticPrograms\Jl6sf\src\methods\api.jl:201
 [28] top-level scope
    @ c:\Users\juan\Dropbox\Projects\JMP\others\MWE_2.jl:196

Normalized coefficient of "decision" variables

I'm running into errors using the normalized_coefficient function on variables that are of type DecisionRef or KnownRef.
If the decision variable isn't in the constraint, I'd prefer it to return 0 rather than throwing an error.

Of course I can do some filtering on the front end to avoid calling normalized_coefficient for constraints that aren't AffineDecisonFunctions, but for the sake of convenience/completeness, I wanted to check whether you would be open to a PR adding the following methods?

function JuMP._affine_coefficient(f::_VariableAffExpr{C}, decision::DecisionRef) where C
    return zero(C)
end
function JuMP._affine_coefficient(f::_VariableAffExpr{C}, known::KnownRef) where C
    return zero(C)
end

Precompiling StochasticPrograms Error: LoadError

I am running Julia 1.6.2 and attempting to run StochasticPrograms.jl v0.6.2. I successfully added the StochasticPrograms package, but when I try to run "using StochasticPrograms" I get the following error:

┌ Info: Precompiling StochasticPrograms [8b8459f2-c380-502b-8633-9aed2d6c2b35]
└ @ Base loading.jl:1278
ERROR: LoadError: LoadError: LoadError: LoadError: LoadError: UndefVarError: coefficient not defined
Stacktrace:
[1] getproperty(::Module, ::Symbol) at .\Base.jl:26
[2] top-level scope at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\affine.jl:97
[3] include(::Function, ::Module, ::String) at .\Base.jl:380
[4] include at .\Base.jl:368 [inlined]
[5] include(::String) at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[6] top-level scope at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\expressions.jl:1
[7] include(::Function, ::Module, ::String) at .\Base.jl:380
[8] include at .\Base.jl:368 [inlined]
[9] include(::String) at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[10] top-level scope at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\decisions.jl:313
[11] include(::Function, ::Module, ::String) at .\Base.jl:380
[12] include at .\Base.jl:368 [inlined]
[13] include(::String) at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[14] top-level scope at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\types.jl:8
[15] include(::Function, ::Module, ::String) at .\Base.jl:380
[16] include at .\Base.jl:368 [inlined]
[17] include(::String) at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:2
[18] top-level scope at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:236
[19] include(::Function, ::Module, ::String) at .\Base.jl:380
[20] include(::Module, ::String) at .\Base.jl:368
[21] top-level scope at none:2
[22] eval at .\boot.jl:347 [inlined]
[23] eval(::Expr) at .\client.jl:467
[24] top-level scope at .\none:3
in expression starting at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\affine.jl:97
in expression starting at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\expressions\expressions.jl:1
in expression starting at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\decisions\decisions.jl:313
in expression starting at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\types\types.jl:8
in expression starting at C:\Users\russn.julia\packages\StochasticPrograms\Jl6sf\src\StochasticPrograms.jl:236

I am fairly new to Julia, but haven't encountered this problem with JuMP or Gurobi. I appreciate any insights.

All the first-stage decision must be binary in the integer strategies

Hi,

I'm trying to solve an integer problem by using one of the Integer strategies proposed in the manual. I've tried both CombinatorialCuts and Convexification, but when I run the optimization the following error appears:

ERROR: LoadError: Combinatorial cuts require all first-stage decisions to be binary.

I was wondering if there is a solution to avoid this request. Thank you for your time.

Could not run in distributed mode

Hi,
I'm trying to make Distributed solving work on my model. Nevertheless, this error arises:

julia> include("src_new\\main.jl")
ERROR: On worker 2:
ArgumentError: Package StochasticPrograms not found in current path:
- Run `import Pkg; Pkg.add("StochasticPrograms")` to install the StochasticPrograms package.

require at .\loading.jl:892
eval at .\boot.jl:331
#101 at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Distributed\src\process_messages.jl:290
run_work_thunk at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Distributed\src\process_messages.jl:79
run_work_thunk at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Distributed\src\process_messages.jl:88
#94 at .\task.jl:358

...and 5 more exception(s).

Stacktrace:
 [1] sync_end(::Array{Any,1}) at .\task.jl:316
 [2] macro expansion at .\task.jl:335 [inlined]
 [3] remotecall_eval(::Module, ::Array{Int64,1}, ::Expr) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Distributed\src\macros.jl:217
 [4] top-level scope at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.4\Distributed\src\macros.jl:201
 [5] include(::String) at .\client.jl:439
 [6] top-level scope at C:\Users\M435719\OneDrive\OneDrive - Air France KLM\TARGETS\thor_poc\src_new\main.jl:15
 [7] include(::String) at .\client.jl:439
 [8] top-level scope at REPL[4]:1

My main does not contain the model, which is instantiated in another file. The header of such file is the following:

module StochOptModel
using Distributed
addprocs(3)
@everywhere using StochasticPrograms
@everywhere using Gurobi

Am I missing something?
Thanks in advance
Kind regards

Small problem in the Quick Start tutorial

In the quick start tutorial, when associating the model with the Progressive Hedging algorithm, it appears the following code

set_optimizer_attribute(sp_progressivehedging, SubProblemOptimizer(), Ipopt.Optimizer)
set_suboptimizer_attribute(sp_progressivehedging, MOI.RawParameter("print_level"), 0) # Silence Ipopt

It seems like MOI does not suppoer RawParamter anymore. I could make the algorithm run by changing the code to

set_optimizer_attribute(
    sp_progressivehedging, SubProblemOptimizer(), 
    MOI.OptimizerWithAttributes(Ipopt.Optimizer, MOI.Silent() => true)
)

Creating instant model issue with scenario defined type vector

Hello,
I'm trying to create a stochastic model with a defined scenario using the instantiate function. However, I'm being stuck at the step of generating the model.

# Generating scenario object
@define_scenario SampleScenario = begin
  d::Vector{Float64}

  @zero begin
    return SampleScenario([])
  end
end

sampled_d = []

for i in 1:size(new_d,2)
  scen_d = SampleScenario(new_d[:,i], probability = 1/s)
  push!(sampled_d,scen_d)
end

##### Sample Average Approximation (SAA)
SAA_model = @stochastic_model begin
  @stage 1 begin
      @decision(model, x[i in loc], Bin)
      @objective(model, Min, sum(f[i]*x[i] for i in loc))
      @constraint(model, max_d <= sum(q[i]*x[i] for i in loc))
  end
  @stage 2 begin
      @uncertain d
      @variable(model, y[i in loc, j in cust] >= 0)
      @objective(model, Min, sum(c[i,j]*y[i,j] for i in loc, j in cust))
      for j in cust
        @constraint(m, sum(y[i,j] for i in loc) == 1)
      end
      @constraint(model, sum(d[j]*y[i,j] for i in loc, j in cust) <= (q[i]*x[i] for i in loc))
  end
end

sp = instantiate(SAA_model, sampled_d, optimizer = Gurobi.Optimizer)

This is the errors that i got :

julia> sp = instantiate(SAA_model, sampled_d, optimizer = Gurobi.Optimizer)
ERROR: MethodError: no method matching instantiate(::StochasticModel{2,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}}}}, ::Array{Any,1}; optimizer=Gurobi.Optimizer)
Closest candidates are:
  instantiate(::StochasticModel{2,P} where P<:Tuple{StageParameters,StageParameters}; instantiation, optimizer, scenario_type, kw...) at C:\Users\thvoe\.julia\packages\StochasticPrograms\54439\src\methods\api.jl:51
  instantiate(::StochasticModel{2,P} where P<:Tuple{StageParameters,StageParameters}, ::Array{var"#s313",1} where var"#s313"<:AbstractScenario; instantiation, optimizer, defer, direct_model, kw...) at C:\Users\thvoe\.julia\packages\StochasticPrograms\54439\src\methods\api.jl:13
  instantiate(::StochasticModel{N,P} where P<:Tuple{Vararg{StageParameters,N}}, ::Tuple{Vararg{Array{var"#s313",1} where var"#s313"<:AbstractScenario,M}}; instantiation, optimizer, defer, kw...) where {N, M} at C:\Users\thvoe\.julia\packages\StochasticPrograms\54439\src\methods\api.jl:75
  ...
Stacktrace:
 [1] top-level scope at REPL[36]:1

This is a scenario that I created - I created 10 scenarios and stored them in sampled_d

SampleScenario with probability 0.1
 d: [2.988512125542072e7, 1.82191958067763e7, 1.6796811372859593e7, 1.2689287123169903e7, 1.2078740851981416e7, 1.1504444297988124e7, 1.1032095197107881e7, 9.268044238581678e6, 7.744850040767815e6, 6.6352522102797e6, 6.339484999019626e6, 6.3095052556271525e6, 
6.031037127521951e6, 5.545212596396539e6, 5.197903683791194e6, 4.829404886428685e6, 4.881395579573187e6, 4.936513209080188e6, 5.008080425502865e6, 4.39200793904869e6, 4.0712369579552263e6, 3.9271770918271123e6, 3.739408541525981e6, 3.602130358768027e6, 3.4117168988347184e6, 3.243302016049922e6, 3.347707426277846e6, 3.2215137658458822e6, 2.798349753356594e6, 2.8439707818016275e6, 2.5755031919725165e6, 2.4840354253501585e6, 2.41716560820301e6, 1.8032710521427672e6, 1.7415367789567339e6, 1.561161983844303e6, 1.5362675149438747e6, 1.2259069179470218e6, 1.2056343414727375e6, 1.1159628408654933e6, 1.0212575397324166e6, 1.0220766953609476e6, 832085.879686038, 709216.1856799318, 650942.8530383029, 639527.8115793295, 602692.494167077, 569459.1519526091, 464521.8452150164]

I don't know how to solve this problem. Hope you can help!
Thank you.

Using @expression with an LShaped.Optimizer

I'm not sure whether this one counts as a bug or a feature request, but using JuMP expressions inside of a model seems to give the LShaped.Optimizer some trouble.

Here is an example using the model from the Quick Start:

simple_model = @stochastic_model begin
    @stage 1 begin
        @decision(model, x₁ >= 40)
        @decision(model, x₂ >= 20)
        objective = @expression(model, 100*x₁ + 150*x₂)
        @objective(model, Min, objective)
        @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, Max, q₁*y₁ + q₂*y₂)
        @constraint(model, 6*y₁ + 10*y₂ <= 60*x₁)
        @constraint(model, 8*y₁ + 5*y₂ <= 80*x₂)
    end
end
julia> sp = instantiate(simple_model, [ξ₁, ξ₂])
Stochastic program with:
 * 2 decision variables
 * 2 scenarios of type Scenario
Structure: Deterministic equivalent
Solver name: No optimizer attached.
julia> sp_progressivehedging = instantiate(simple_model, [ξ₁, ξ₂], optimizer = ProgressiveHedging.Optimizer)
Stochastic program with:
 * 2 decision variables
 * 2 scenarios of type Scenario
Structure: Horizontal
Solver name: Progressive-hedging with fixed penalty
julia> sp_lshaped = instantiate(simple_model, [ξ₁, ξ₂], optimizer = LShaped.Optimizer)
ERROR: UndefVarError: x₁ not defined
Stacktrace:
 [1] macro expansion at /Users/ryanwalker/.julia/packages/MutableArithmetics/NuiNA/src/rewrite.jl:227 [inlined]
 [2] #18 at /Users/ryanwalker/.julia/packages/JuMP/YXK4e/src/macros.jl:45 [inlined]
 [3] (::var"#18#23")(::Model, ::NamedTuple{(),Tuple{}}) at ./none:0
 [4] generate_vertical!(::StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}}}, ::var"#18#23", ::var"#21#26", ::NamedTuple{(),Tuple{}}, ::NamedTuple{(),Tuple{}}, ::Decisions, ::Nothing) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/vertical/generation.jl:65
 [5] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}}}}}}, ::VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}}}}}, ::Int64) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/vertical/generation.jl:40
 [6] generate! at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/vertical/generation.jl:6 [inlined]
 [7] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}}}}}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/generation.jl:92
 [8] instantiate(::StochasticModel{2,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}}}}, ::Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}; instantiation::StochasticPrograms.UnspecifiedInstantiation, optimizer::Type{T} where T, defer::Bool, direct_model::Bool, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/api.jl:37
 [9] top-level scope at REPL[19]:1

Error:Access to undefined reference - Problem with number of scenarios ?

Hello,

Thank you for your contribution. I would like it very much if I could use it in a Julia Lab for students in OR.

While designing my lab, I bumped into a weird "ERROR: LoadError: UndefRefError: access to undefined reference" that is thrown when executing the solve command on a stochastic program. My concern is that this issue appears on my example with 80+ scenarios, but it does not with 70 and less scenarios. What is more, the print command works with any number of scenarios.
Finally, I checked by directly modeling the DEP with JuMP and the solution is indeed correct for 70 and less scenarios.

I attach the two Julia files that are necessary to reproduce the error (had to change the extension to .txt to upload them), and I copy/paste the complete text of the error I get below :
ERROR: LoadError: UndefRefError: access to undefined reference
Stacktrace:
[1] DEP(::JuMP.Model, ::Clp.ClpMathProgSolverInterface.ClpSolver) at /Users/jeremy/.julia/v0.6/StochasticPrograms/src/methods/spconstructs.jl:129
[2] #_solve#44(::Bool, ::JuMP.UnsetSolver, ::Array{Any,1}, ::Function, ::JuMP.Model) at /Users/jeremy/.julia/v0.6/StochasticPrograms/src/types/twostage.jl:74
[3] (::StochasticPrograms.#kw##_solve)(::Array{Any,1}, ::StochasticPrograms.#_solve, ::JuMP.Model) at ./:0
[4] #solve#116(::Bool, ::Bool, ::Bool, ::Array{Any,1}, ::Function, ::JuMP.Model) at /Users/jeremy/.julia/v0.6/JuMP/src/solvers.jl:151
[5] solve(::JuMP.Model) at /Users/jeremy/.julia/v0.6/JuMP/src/solvers.jl:150
[6] include_string(::String, ::String) at ./loading.jl:522
[7] include_string(::String, ::String, ::Int64) at /Users/jeremy/.julia/v0.6/CodeTools/src/eval.jl:30
[8] include_string(::Module, ::String, ::String, ::Int64, ::Vararg{Int64,N} where N) at /Users/jeremy/.julia/v0.6/CodeTools/src/eval.jl:34
[9] (::Atom.##92#97{String,Int64,String})() at /Users/jeremy/.julia/v0.6/Atom/src/eval.jl:52
[10] withpath(::Atom.##92#97{String,Int64,String}, ::String) at /Users/jeremy/.julia/v0.6/CodeTools/src/utils.jl:30
[11] withpath(::Function, ::String) at /Users/jeremy/.julia/v0.6/Atom/src/eval.jl:38
[12] hideprompt(::Atom.##91#96{String,Int64,String}) at /Users/jeremy/.julia/v0.6/Atom/src/repl.jl:67
[13] macro expansion at /Users/jeremy/.julia/v0.6/Atom/src/eval.jl:49 [inlined]
[14] (::Atom.##90#95{Dict{String,Any}})() at ./task.jl:80
while loading /Users/jeremy/Dropbox/Cours/5GM_OptimisationStochastique/TP/Implementation avec CPLEX/TestStochasticPrograms.jl, in expression starting on line 54

Thanks for your help !

Jeremy

generedonnees.txt
TestStochasticPrograms.txt

ERROR on the instantiation of a stochastic model

I try to do the quick start example, same error as Issue #13 was happening.
So, I run pgk> add StochasticPrograms#master and now this error is obtained. The same behavior happens for the farm example.
Below versioninfo, status and the code.

Thank you in advance,

julia> versioninfo()
Julia Version 1.5.2
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

(@v1.5) pkg> status
Status `C:\Users\PC\.julia\environments\v1.5\Project.toml`
  [a076750e] CPLEX v0.7.2
  [9961bab8] Cbc v0.7.1
  [e2554f3b] Clp v0.8.3
  [60bf3e95] GLPK v0.14.2
  [2e9cd046] Gurobi v0.9.3
  [7073ff75] IJulia v1.22.0
  [43edad99] InstantiateFromURL v0.5.0
  [b6b21f68] Ipopt v0.6.3
  [4076af6c] JuMP v0.21.4
  [b8f27783] MathOptInterface v0.9.18
  [91a5bcdd] Plots v1.7.3
  [8b8459f2] StochasticPrograms v0.4.1 `https://github.com/martinbiel/StochasticPrograms.jl.git#master`

julia> using StochasticPrograms, GLPK, Ipopt

julia> simple_model = @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, Max, q₁*y₁ + q₂*y₂)
               @constraint(model, 6*y₁ + 10*y₂ <= 60*x₁)
               @constraint(model, 8*y₁ + 5*y₂ <= 80*x₂)
           end
       end
Two-Stage Stochastic Model

minimize f₀(x) + �[f(x,ξ)]
  x∈�

where

f(x,ξ) = min  f(y; x, ξ)
              y ∈ � (x, ξ)


julia> ξ₁ = Scenario(q₁ = 24.0, q₂ = 28.0, d₁ = 500.0, d₂ = 100.0, probability = 0.4)
Scenario with probability 0.4
  q₁: 24.0
  q₂: 28.0
  d₁: 500.0
  d₂: 100.0

julia> ξ₂ = Scenario(q₁ = 28.0, q₂ = 32.0, d₁ = 300.0, d₂ = 300.0, probability = 0.6)
Scenario with probability 0.6
  q₁: 28.0
  q₂: 32.0
  d₁: 300.0
  d₂: 300.0

julia> sp = instantiate(simple_model, [ξ₁, ξ₂], optimizer = GLPK.Optimizer)
ERROR: MethodError: no method matching is_coefficient_type(::Type{VectorAffineDecisionFunction{Float64}}, ::Type{Float64})
Closest candidates are:
  is_coefficient_type(::Type{var"#s280"} where var"#s280"<:Union{MathOptInterface.SingleVariable, MathOptInterface.VectorOfVariables}, ::Type) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Utilities\functions.jl:2058
  is_coefficient_type(::Type{var"#s280"} where var"#s280"<:Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}}, ::Type{T}) where T at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Utilities\functions.jl:2059
  is_coefficient_type(::Type{var"#s280"} where var"#s280"<:(Union{MathOptInterface.ScalarAffineFunction{T}, MathOptInterface.ScalarQuadraticFunction{T}, MathOptInterface.VectorAffineFunction{T}, MathOptInterface.VectorQuadraticFunction{T}} where T), ::Type) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Utilities\functions.jl:2060
Stacktrace:
 [1] supports_constraint(::Type{MathOptInterface.Bridges.Constraint.ScalarizeBridge{Float64,F,S} where S where F}, ::Type{VectorAffineDecisionFunction{Float64}}, ::Type{MathOptInterface.Nonnegatives}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\Constraint\scalarize.jl:31
 [2] node(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Type{VectorAffineDecisionFunction{Float64}}, ::Type{MathOptInterface.Nonnegatives}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:168
 [3] edge(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Int64, ::Type{MathOptInterface.Bridges.Constraint.NonposToNonnegBridge{Float64,VectorAffineDecisionFunction{Float64},VectorAffineDecisionFunction{Float64}}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:94
 [4] node(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Type{VectorAffineDecisionFunction{Float64}}, ::Type{MathOptInterface.Nonpositives}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:169
 [5] edge(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Int64, ::Type{MathOptInterface.Bridges.Constraint.VectorizeBridge{Float64,VectorAffineDecisionFunction{Float64},MathOptInterface.Nonpositives,AffineDecisionFunction{Float64}}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:94
 [6] node(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Type{AffineDecisionFunction{Float64}}, ::Type{MathOptInterface.LessThan{Float64}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:169
 [7] edge(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Int64, ::Type{MathOptInterface.Bridges.Constraint.GreaterToLessBridge{Float64,AffineDecisionFunction{Float64},AffineDecisionFunction{Float64}}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:94
 [8] node(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Type{AffineDecisionFunction{Float64}}, ::Type{MathOptInterface.GreaterThan{Float64}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:169
 [9] edge(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Int64, ::Type{MathOptInterface.Bridges.Objective.SlackBridge{Float64,AffineDecisionFunction{Float64},AffineDecisionFunction{Float64}}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:101
 [10] node(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::Type{AffineDecisionFunction{Float64}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:190
 [11] bridge_index at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:277 [inlined]
 [12] supports_bridging_objective_function at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\lazy_bridge_optimizer.jl:299 [inlined]
 [13] supports(::MathOptInterface.Bridges.LazyBridgeOptimizer{GLPK.Optimizer}, ::MathOptInterface.ObjectiveFunction{AffineDecisionFunction{Float64}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Bridges\bridge_optimizer.jl:670
 [14] supports(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.ObjectiveFunction{AffineDecisionFunction{Float64}}) at C:\Users\PC\.julia\packages\MathOptInterface\VjkSQ\src\Utilities\cachingoptimizer.jl:572
 [15] set_objective_function(::Model, ::AffineDecisionFunction{Float64}) at C:\Users\PC\.julia\packages\JuMP\e0Uc2\src\objective.jl:95
 [16] set_objective_function at C:\Users\PC\.julia\packages\JuMP\e0Uc2\src\objective.jl:110 [inlined]
 [17] set_objective at C:\Users\PC\.julia\packages\JuMP\e0Uc2\src\objective.jl:128 [inlined]
 [18] macro expansion at C:\Users\PC\.julia\packages\JuMP\e0Uc2\src\macros.jl:831 [inlined]
 [19] #3 at .\REPL[4]:5 [inlined]
 [20] (::var"#3#8")(::Model, ::NamedTuple{(),Tuple{}}) at .\none:0
 [21] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}}, ::DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}, ::Int64) at C:\Users\PC\.julia\packages\StochasticPrograms\yFtc7\src\methods\deterministic_equivalent\generation.jl:28
 [22] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}}, ::DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}) at C:\Users\PC\.julia\packages\StochasticPrograms\yFtc7\src\methods\deterministic_equivalent\generation.jl:11
 [23] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}}) at C:\Users\PC\.julia\packages\StochasticPrograms\yFtc7\src\methods\generation.jl:96
 [24] instantiate(::StochasticModel{2,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}}}}, ::Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}; instantiation::StochasticPrograms.UnspecifiedInstantiation, optimizer::Type{T} where T, defer::Bool, direct_model::Bool, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\PC\.julia\packages\StochasticPrograms\yFtc7\src\methods\api.jl:37
 [25] top-level scope at REPL[7]:1

Edit: added a fenced code block

How to stop the optimization of a stochastic program

Hi,

I'm having some troubles trying to interrupt the optimization of a model that I have built by using StochasticPrograms.

After a lot of test I decided to use progressive-hedging algorithms to solve the model, but it is still difficult to find the optimal solution. Thus, I decided to put an optimality gap to stop the execution, but it seem that it doesn't work. This is what I put in the code:

op_model_user = instantiate(model_user, possible_scenarios, optimizer = ProgressiveHedging.Optimizer)
set_optimizer_attribute(op_model_user, SubProblemOptimizer(), CPLEX.Optimizer)
set_optimizer_attribute(op_model_user, PrimalTolerance(), 5e-1)
MOI.set(op_model_user, RawSubProblemOptimizerParameter("CPX_PARAM_EPGAP"), 5e-1)

optimize!(op_model_user)

These are some lines of the optimization after 30 minutes from the start:

CPXPARAM_MIP_Tolerances_MIPGap                   0.10000000000000001
1 of 1 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 1.4695e+10.
Tried aggregator 2 times.
MIQCP Presolve eliminated 11393 rows and 11395 columns.
Aggregator did 1078 substitutions.
Reduced MIQCP has 29012 rows, 45200 columns, and 93954 nonzeros.
Reduced MIQCP has 0 binaries, 8 generals, 0 SOSs, and 0 indicators.
Reduced MIQCP has 1 quadratic constraints.
Presolve time = 0.10 sec. (78.89 ticks)

Root node processing (before b&c):
  Real time             =    4.34 sec. (2335.55 ticks)
Parallel b&c, 16 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    4.34 sec. (2335.55 ticks)
Version identifier: 20.1.0.0 | 2020-11-10 | 9bedb6d68
CPXPARAM_MIP_Tolerances_MIPGap                   0.10000000000000001
1 of 1 MIP starts provided solutions.
MIP start 'm1' defined initial solution with objective 1.5373e+09.
Tried aggregator 2 times.
MIQCP Presolve eliminated 11393 rows and 11392 columns.
Aggregator did 1078 substitutions.
Reduced MIQCP has 29013 rows, 45203 columns, and 93954 nonzeros.
Reduced MIQCP has 0 binaries, 8 generals, 0 SOSs, and 0 indicators.
Reduced MIQCP has 1 quadratic constraints.
Presolve time = 0.10 sec. (78.90 ticks)

Root node processing (before b&c):
  Real time             =    4.09 sec. (2202.25 ticks)
Parallel b&c, 16 threads:
  Real time             =    0.00 sec. (0.00 ticks)
  Sync time (average)   =    0.00 sec.
  Wait time (average)   =    0.00 sec.
                          ------------
Total (root+branch&cut) =    4.09 sec. (2202.25 ticks)

Moreover, sometimes the status of the solution appears and it seems that the Primal Gap is very good:

Schermata

Why execution is still running? Is there something I can do to interrupt it? If I use Ctrl+C it stops but there aren't solutions saved, so I can't have any information. I also tried to set a time limit, but also in this case I'm not able to find which is the optimal solution found.

Thank you very much for your time.

Conversion failed (MathOptInterface.Utilities.VectorOfConstraints)

Hi all!

I've been trying to run the farmer problem example but it failed (this in Julia 1.5.3). I made a fresh Julia 1.6.1 installation and the exampled failed as well. Furthermore, I run the test and many failed. I attatch you the test summary as well as the the error in common.

I hope it helps :)

Cheers,

Test Summary: | Pass Error Total
DecisionVariable | 48 40 88
Deterministic() | 12 10 22
test_all_decision_variables | 1 1
test_decision_custom_index_sets | 1 1
test_decision_fix | 1 1
test_decision_lower_bound | 1 1
test_decision_no_bound | 1 1
test_decision_upper_bound | 1 1
test_variable_bounds_set_get | 1 1
test_variable_integrality_set_get | 1 1
test_variable_is_valid_delete | 1 1
test_variable_starts_set_get | 1 1
test_variables_constrained_on_creation | 12 12
Vertical() | 12 10 22
test_all_decision_variables | 1 1
test_decision_custom_index_sets | 1 1
test_decision_fix | 1 1
test_decision_lower_bound | 1 1
test_decision_no_bound | 1 1
test_decision_upper_bound | 1 1
test_variable_bounds_set_get | 1 1
test_variable_integrality_set_get | 1 1
test_variable_is_valid_delete | 1 1
test_variable_starts_set_get | 1 1
test_variables_constrained_on_creation | 12 12
Horizontal() | 12 10 22
test_all_decision_variables | 1 1
test_decision_custom_index_sets | 1 1
test_decision_fix | 1 1
test_decision_lower_bound | 1 1
test_decision_no_bound | 1 1
test_decision_upper_bound | 1 1
test_variable_bounds_set_get | 1 1
test_variable_integrality_set_get | 1 1
test_variable_is_valid_delete | 1 1
test_variable_starts_set_get | 1 1
test_variables_constrained_on_creation | 12 12
Deterministic() with decision bridges | 12 10 22
test_all_decision_variables | 1 1
test_decision_custom_index_sets | 1 1
test_decision_fix | 1 1
test_decision_lower_bound | 1 1
test_decision_no_bound | 1 1
test_decision_upper_bound | 1 1
test_variable_bounds_set_get | 1 1
test_variable_integrality_set_get | 1 1
test_variable_is_valid_delete | 1 1
test_variable_starts_set_get | 1 1
test_variables_constrained_on_creation | 12 12
ERROR: LoadError: Some tests did not pass: 48 passed, 0 failed, 40 errored, 0 broken.

test_all_decision_variables: Error During Test at /home/victor/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:496
Got exception outside of a @test
MethodError: Cannot convert an object of type
OrderedCollections.OrderedDict{MathOptInterface.ConstraintIndex{SingleDecision, StochasticPrograms.FreeDecision}, Tuple{SingleDecision, StochasticPrograms.FreeDecision}} to an object of type
MathOptInterface.Utilities.VectorOfConstraints
Closest candidates are:
convert(::Type{T}, ::DecisionAffExpr{T}) where T at /home/victor/.julia/packages/StochasticPrograms/54439/src/types/decisions/expressions/affine.jl:71
convert(::Type{T}, ::T) where T at essentials.jl:205
Stacktrace:
[1] get!(default::StochasticPrograms.var"#401#402"{DataType, DataType}, h::OrderedCollections.OrderedDict{Tuple{DataType, DataType}, MathOptInterface.Utilities.VectorOfConstraints}, key0::Tuple{DataType, DataType})
@ OrderedCollections ~/.julia/packages/OrderedCollections/cP9uu/src/ordered_dict.jl:365
[2] add_constraint(uf::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}, f::SingleDecision, s::StochasticPrograms.FreeDecision)
@ StochasticPrograms ~/.julia/packages/StochasticPrograms/54439/src/types/decisions/moi_overrides.jl:167
[3] add_constraint(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, func::SingleDecision, set::StochasticPrograms.FreeDecision)
@ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/1EYfq/src/Utilities/cachingoptimizer.jl:441
[4] _moi_constrain_decision(backend::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.GenericModel{Float64, MathOptInterface.Utilities.ModelFunctionConstraints{Float64}}}}, index::MathOptInterface.VariableIndex, info::VariableInfo{Float64, Float64, Float64, Float64}, set::StochasticPrograms.SingleDecisionSet{Float64})
@ StochasticPrograms ~/.julia/packages/StochasticPrograms/54439/src/types/decisions/macros.jl:212
[5] add_variable(model::Model, variable::VariableConstrainedOnCreation{StochasticPrograms.SingleDecisionSet{Float64}, ScalarVariable{Float64, Float64, Float64, Float64}}, name::String)
@ StochasticPrograms ~/.julia/packages/StochasticPrograms/54439/src/types/decisions/macros.jl:39
[6] macro expansion
@ ~/.julia/packages/JuMP/MIPb6/src/macros.jl:111 [inlined]
[7] macro expansion
@ ~/.julia/packages/StochasticPrograms/54439/src/methods/creation.jl:570 [inlined]
[8] #298
@ ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:466 [inlined]
[9] (::Main.TestDecisionVariable.var"#298#302")(model::Model, stage::Nothing)
@ Main.TestDecisionVariable ./none:0
[10] generate_proxy!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:a,), Tuple{Int64}}}}}}})
@ StochasticPrograms ~/.julia/packages/StochasticPrograms/54439/src/methods/generation.jl:84
[11] generate!(stochasticprogram::StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, DeterministicEquivalent{2, 1, Tuple{Vector{Scenario{NamedTuple{(:a,), Tuple{Int64}}}}}}})
@ StochasticPrograms ~/.julia/packages/StochasticPrograms/54439/src/methods/generation.jl:142
[12] test_all_decision_variables(Structure::Tuple{Deterministic, Main.TestDecisionVariable.var"#305#306"})
@ Main.TestDecisionVariable ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:469
[13] macro expansion
@ ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:497 [inlined]
[14] macro expansion
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
[15] macro expansion
@ ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:497 [inlined]
[16] macro expansion
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
[17] macro expansion
@ ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:491 [inlined]
[18] macro expansion
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
[19] runtests()
@ Main.TestDecisionVariable ~/.julia/packages/StochasticPrograms/54439/test/decisions/decision_variable.jl:485
[20] top-level scope
@ ~/.julia/packages/StochasticPrograms/54439/test/runtests.jl:13
[21] include(fname::String)
@ Base.MainInclude ./client.jl:444
[22] top-level scope
@ none:6
[23] eval
@ ./boot.jl:360 [inlined]
[24] exec_options(opts::Base.JLOptions)
@ Base ./client.jl:261
[25] _start()
@ Base ./client.jl:485

How to access the optimal values of the second stage variables

Hello, I am trying to run the farmer.jl example. The model works find and the optimal solution is found. However when I enter JuMP.value.(w) following command to get the values of the second stage variables w, it says UndefVarError: w not defined. Could you please let me know if I am missing something here? Thanks!

Multi-Stage Instantiation

I ran into an error with instantiating multistage models.

Taking the inventory example from the multistage chapter of Birge and Louveaux:

inventory_model = @stochastic_model begin
    @stage 1 begin
        # number of units produced in regular time work during month 1
        @variable(model, x₁ >= 0)
        # number of units produced in overtime work during month 1
        @variable(model, w₁ >= 0)
        # number of units stored at month 1
        @decision(model, y₁ >= 0)
        # minimize total cost = production cost + holding cost
        @objective(model, Min, x₁ + 3*w₁ + 0.5*y₁)
        # constraint on production capacity
        @constraint(model, x₁ <= 2)
        # must meet already known month 1 demand
        @constraint(model, x₁ + w₁ - y₁ == 1)
    end
    
    @stage 2 begin
        @uncertain d
        # number of units produced in regular time work during month 2
        @variable(model, x₂ >= 0)
        # number of units produced in overtime work during month 2
        @variable(model, w₂ >= 0)
        # number of units stored at month 2
        @decision(model, y₂ >= 0)
        # minimize total cost = production cost + holding cost
        @objective(model, Min, x₂ + 3*w₂ + 0.5*y₂)
        # constraint on production capacity
        @constraint(model, x₂ <= 2)
        # must meet month 2 demand
        @constraint(model, x₂ + w₂ - y₂ == d - y₁)
    end

    @stage 3 begin
        @uncertain d
        # number of units produced in regular time work during month 3
        @variable(model, x₃ >= 0)
        # number of units produced in overtime work during month 3
        @variable(model, w₃ >= 0)
        # number of units stored at month 3
        @decision(model, y₃ >= 0)
        # minimize total cost = production cost + holding cost
        @objective(model, Min, x₃ + 3*w₃ + 0.5*y₃)
        # constraint on production capacity
        @constraint(model, x₃ <= 2)
        # must meet month 3 demand
        @constraint(model, x₃ + w₃ - y₃ == d - y₂)
    end
end

s₂₁ = Scenario(d = 1.0, probability = 0.5)
s₂₂ = Scenario(d = 3.0, probability = 0.5)

s₃₁ = Scenario(d = 1.0, probability = 0.25)
s₃₂ = Scenario(d = 3.0, probability = 0.25)
s₃₃ = Scenario(d = 1.0, probability = 0.25)
s₃₄ = Scenario(d = 3.0, probability = 0.25)

Instantiating the DEP gives the following error:

julia> inventory_dep = instantiate(inventory_model, ([s₂₁,s₂₂], [s₃₁,s₃₂,s₃₃,s₃₄]))
ERROR: KeyError: key :y₂ not found
Stacktrace:
 [1] getindex at /Users/ryanwalker/.julia/packages/JuMP/YXK4e/src/JuMP.jl:936 [inlined]
 [2] (::var"#9#16")(::Model, ::NamedTuple{(),Tuple{}}, ::Scenario{NamedTuple{(:d,),Tuple{Float64}}}) at ./none:0
 [3] generate!(::StochasticProgram{3,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{3,2,Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}}}, ::DeterministicEquivalent{3,2,Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}}, ::Int64) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/deterministic_equivalent/generation.jl:44
 [4] generate!(::StochasticProgram{3,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{3,2,Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}}}, ::DeterministicEquivalent{3,2,Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/deterministic_equivalent/generation.jl:11
 [5] generate!(::StochasticProgram{3,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},DeterministicEquivalent{3,2,Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/generation.jl:92
 [6] instantiate(::StochasticModel{3,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}}}}, ::Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}; instantiation::StochasticPrograms.UnspecifiedInstantiation, optimizer::Nothing, defer::Bool, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/api.jl:93
 [7] instantiate(::StochasticModel{3,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(),Tuple{}}}}}, ::Tuple{Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1},Array{Scenario{NamedTuple{(:d,),Tuple{Float64}}},1}}) at /Users/ryanwalker/.julia/dev/StochasticPrograms/src/methods/api.jl:81
 [8] top-level scope at REPL[10]:1

The LShaped.Optimizer seems to handle the same model correctly however:

julia> inventory_lshaped = instantiate(inventory_model, ([s₂₁,s₂₂], [s₃₁,s₃₂,s₃₃,s₃₄]), optimizer = LShaped.Optimizer)
Stochastic program with:
 * Stage 1:
   * 1 decision variable
 * Stage 2:
   * 1 decision variable
   * 2 scenarios of type Scenario
 * Stage 3:
   * 4 scenarios of type Scenario
Structure: Vertical
Solver name: L-shaped with disaggregate cuts

Undefined variable error when defining integer variables

Hi, I did a quick test by modifying the farmer example, transforming it to integer form. However, UndefVarError is thrown when trying to instantiate the model. I've done other tests and the error is thrown with binary variables too and with all solvers. Is this a bug or are integer variables not supported yet?

Thanks!

using Gurobi
using StochasticPrograms
farmer_model = @stochastic_model begin
@stage 1 begin
@parameters begin
Crops = [:wheat, :corn, :beets]
Cost = Dict(:wheat=>150, :corn=>230, :beets=>260)
Budget = 500
end
@Decision(model, x[c in Crops] >=0, integer=true)
@objective(model, Min, sum(Cost[c]*x[c] for c in Crops))
@constraint(model, sum(x[c] for c in Crops) <= Budget)
@constraint(model, sum(x[c] for c in Crops) <= Budget)
end
@stage 2 begin
@parameters begin
Crops = [:wheat, :corn, :beets]
Required = Dict(:wheat=>200, :corn=>240, :beets=>0)
PurchasePrice = Dict(:wheat=>238, :corn=>210)
SellPrice = Dict(:wheat=>170, :corn=>150, :beets=>36, :extra_beets=>10)
end
@Uncertain ξ[c in Crops]
@variable(model, y[p in setdiff(Crops, [:beets])] >= 0)
@variable(model, w[s in Crops ∪ [:extra_beets]] >= 0)
@objective(model, Min, sum(PurchasePrice[p] * y[p] for p in setdiff(Crops, [:beets]))
- sum(SellPrice[s] * w[s] for s in Crops ∪ [:extra_beets]))
@constraint(model, minimum_requirement[p in setdiff(Crops, [:beets])],
ξ[p] * x[p] + y[p] - w[p] >= Required[p])
@constraint(model, minimum_requirement_beets,
ξ[:beets] * x[:beets] - w[:beets] - w[:extra_beets] >= Required[:beets])
@constraint(model, beets_quota, w[:beets] <= 6000)
end
end

ξ₁ = Scenario(wheat = 3.0, corn = 3.6, beets = 24.0, probability = 1/3)
ξ₂ = Scenario(wheat = 2.5, corn = 3.0, beets = 20.0, probability = 1/3)
ξ₃ = Scenario(wheat = 2.0, corn = 2.4, beets = 16.0, probability = 1/3)

farmer = instantiate(farmer_model, [ξ₁,ξ₂,ξ₃], optimizer = LShaped.Optimizer)
print(farmer)

set_optimizer_attribute(farmer, MasterOptimizer(), Gurobi.Optimizer)
set_optimizer_attribute(farmer, SubproblemOptimizer(), Gurobi.Optimizer)

optimize!(farmer)
x = optimal_decision(farmer)
println("Wheat: $(x[1])")
println("Corn: $(x[2])")
println("Beets: $(x[3])")
println("Profit: $(objective_value(farmer))")
println("EVPI: $(EVPI(farmer))")
println("VSS: $(VSS(farmer))")

ERROR: UndefVarError: x not defined
Stacktrace:
[1] macro expansion at /mnt/workspace/.julia/packages/MutableArithmetics/NuiNA/src/rewrite.jl:227 [inlined]
[2] macro expansion at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/macros.jl:416 [inlined]
[3] (::var"#71#84"{Model,Dict{Symbol,Int64},JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Symbol,1}},Tuple{Dict{Symbol,Int64}}},JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Symbol,1}},Tuple{Dict{Symbol,Int64}}}})(::Symbol) at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/Containers/macro.jl:183
[4] #28 at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/Containers/container.jl:85 [inlined]
[5] iterate at ./generator.jl:47 [inlined]
[6] collect(::Base.Generator{JuMP.Containers.VectorizedProductIterator{Tuple{Array{Symbol,1}}},JuMP.Containers.var"#28#29"{var"#71#84"{Model,Dict{Symbol,Int64},JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Symbol,1}},Tuple{Dict{Symbol,Int64}}},JuMP.Containers.DenseAxisArray{VariableRef,1,Tuple{Array{Symbol,1}},Tuple{Dict{Symbol,Int64}}}}}}) at ./array.jl:665
[7] map(::Function, ::JuMP.Containers.VectorizedProductIterator{Tuple{Array{Symbol,1}}}) at ./abstractarray.jl:2098
[8] container(::Function, ::JuMP.Containers.VectorizedProductIterator{Tuple{Array{Symbol,1}}}, ::Type{JuMP.Containers.DenseAxisArray}) at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/Containers/container.jl:85
[9] container at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/Containers/container.jl:65 [inlined]
[10] #67 at /mnt/workspace/.julia/packages/JuMP/YXK4e/src/macros.jl:79 [inlined]
[11] (::var"#67#80")(::Model, ::NamedTuple{(:Crops, :Required, :PurchasePrice, :SellPrice),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Dict{Symbol,Int64},Dict{Symbol,Int64}}}, ::Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}}) at ./none:0
[12] generate_vertical!(::StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}}}, ::var"#60#73", ::var"#67#80", ::NamedTuple{(:Crops, :Cost, :Budget),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Int64}}, ::NamedTuple{(:Crops, :Required, :PurchasePrice, :SellPrice),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Dict{Symbol,Int64},Dict{Symbol,Int64}}}, ::Decisions, ::Nothing) at /mnt/workspace/.julia/packages/StochasticPrograms/g8Qnj/src/methods/vertical/generation.jl:66
[13] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(:Crops, :Cost, :Budget),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Int64}}},StochasticPrograms.Stage{NamedTuple{(:Crops, :Required, :PurchasePrice, :SellPrice),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Dict{Symbol,Int64},Dict{Symbol,Int64}}}}},VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}}}}}}, ::VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}}}}}, ::Int64) at /mnt/workspace/.julia/packages/StochasticPrograms/g8Qnj/src/methods/vertical/generation.jl:40
[14] generate! at /mnt/workspace/.julia/packages/StochasticPrograms/g8Qnj/src/methods/vertical/generation.jl:6 [inlined]
[15] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(:Crops, :Cost, :Budget),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Int64}}},StochasticPrograms.Stage{NamedTuple{(:Crops, :Required, :PurchasePrice, :SellPrice),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Dict{Symbol,Int64},Dict{Symbol,Int64}}}}},VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}}}}}}) at /mnt/workspace/.julia/packages/StochasticPrograms/g8Qnj/src/methods/generation.jl:92
[16] instantiate(::StochasticModel{2,Tuple{StageParameters{NamedTuple{(:Crops, :Cost, :Budget),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Int64}}},StageParameters{NamedTuple{(:Crops, :Required, :PurchasePrice, :SellPrice),Tuple{Array{Symbol,1},Dict{Symbol,Int64},Dict{Symbol,Int64},Dict{Symbol,Int64}}}}}}, ::Array{Scenario{NamedTuple{(:wheat, :corn, :beets),Tuple{Float64,Float64,Float64}}},1}; instantiation::StochasticPrograms.UnspecifiedInstantiation, optimizer::Type{T} where T, defer::Bool, direct_model::Bool, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /mnt/workspace/.julia/packages/StochasticPrograms/g8Qnj/src/methods/api.jl:37
[17] top-level scope at /mnt/workspace/projects/targets/src/example_stochprogs.jl:50
[18] include(::String) at ./client.jl:439
[19] top-level scope at REPL[1]:1

Incompatibility of L-Shaped with CBC

Hi,
I'm running quick tests with CBC and it appears to be incompatible with MOI methods to extract duals:

ERROR: ArgumentError: ModelLike of type Cbc.Optimizer does not support accessing the attribute MathOptInterface.ConstraintDual(1)
Stacktrace:
 [1] get(::Cbc.Optimizer, ::MathOptInterface.ConstraintDual, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\attributes.jl:272
 [2] get(::MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.ConstraintDual, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Utilities\cachingoptimizer.jl:568
 [3] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.ConstraintDual, ::MathOptInterface.ConstraintIndex{MathOptInterface.ScalarAffineFunction{Float64},MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:866
 [4] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.ConstraintDual, ::StochasticPrograms.AffineDecisionConstraintBridge{Float64,MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\types\decisions\bridges\constraints\affine.jl:73
 [5] (::MathOptInterface.Bridges.var"#54#55"{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}},MathOptInterface.ConstraintDual})(::StochasticPrograms.AffineDecisionConstraintBridge{Float64,MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:864
 [6] (::MathOptInterface.Bridges.var"#1#2"{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}},MathOptInterface.ConstraintIndex{StochasticPrograms.AffineDecisionFunction{Float64},MathOptInterface.LessThan{Float64}},MathOptInterface.Bridges.var"#54#55"{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}},MathOptInterface.ConstraintDual}})() at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:217
 [7] call_in_context(::MathOptInterface.Bridges.Variable.Map, ::Int64, ::MathOptInterface.Bridges.var"#1#2"{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}},MathOptInterface.ConstraintIndex{StochasticPrograms.AffineDecisionFunction{Float64},MathOptInterface.LessThan{Float64}},MathOptInterface.Bridges.var"#54#55"{MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}},MathOptInterface.ConstraintDual}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\Variable\map.jl:404
 [8] call_in_context at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\Variable\map.jl:435 [inlined]
 [9] call_in_context at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:216 [inlined]
 [10] get(::MathOptInterface.Bridges.LazyBridgeOptimizer{MathOptInterface.Utilities.CachingOptimizer{Cbc.Optimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}}, ::MathOptInterface.ConstraintDual, ::MathOptInterface.ConstraintIndex{StochasticPrograms.AffineDecisionFunction{Float64},MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Bridges\bridge_optimizer.jl:864
 [11] get(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::MathOptInterface.ConstraintDual, ::MathOptInterface.ConstraintIndex{StochasticPrograms.AffineDecisionFunction{Float64},MathOptInterface.LessThan{Float64}}) at C:\Users\M435719\.julia\packages\MathOptInterface\bygN7\src\Utilities\cachingoptimizer.jl:568
 [12] StochasticPrograms.LShaped.FeasibilityCut(::StochasticPrograms.LShaped.SubProblem{StochasticPrograms.LShaped.FeasibilityHandler,Float64}, ::Array{Float64,1}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\types\subproblem.jl:317
 [13] (::StochasticPrograms.LShaped.SubProblem{StochasticPrograms.LShaped.FeasibilityHandler,Float64})(::Array{Float64,1}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\types\subproblem.jl:268
 [14] resolve_subproblems!(::StochasticPrograms.LShaped.LShapedAlgorithm{Float64,Array{Float64,1},StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}},MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}},StochasticPrograms.LShaped.SerialExecution{StochasticPrograms.LShaped.FeasibilityHandler,Float64,Array{Float64,1}},StochasticPrograms.LShaped.HandleFeasibility{Float64},StochasticPrograms.LShaped.NoRegularization,StochasticPrograms.LShaped.NoAggregation,StochasticPrograms.LShaped.NoConsolidation}, ::StochasticPrograms.LShaped.SerialExecution{StochasticPrograms.LShaped.FeasibilityHandler,Float64,Array{Float64,1}}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\execution\serial.jl:64
 [15] resolve_subproblems! at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\execution\execution.jl:12 [inlined]
 [16] iterate!(::StochasticPrograms.LShaped.LShapedAlgorithm{Float64,Array{Float64,1},StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}},MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}},StochasticPrograms.LShaped.SerialExecution{StochasticPrograms.LShaped.FeasibilityHandler,Float64,Array{Float64,1}},StochasticPrograms.LShaped.HandleFeasibility{Float64},StochasticPrograms.LShaped.NoRegularization,StochasticPrograms.LShaped.NoAggregation,StochasticPrograms.LShaped.NoConsolidation}, ::StochasticPrograms.LShaped.SerialExecution{StochasticPrograms.LShaped.FeasibilityHandler,Float64,Array{Float64,1}}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\execution\common.jl:90
 [17] iterate! at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\execution\execution.jl:9 [inlined]
 [18] (::StochasticPrograms.LShaped.LShapedAlgorithm{Float64,Array{Float64,1},StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}},MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}},StochasticPrograms.LShaped.SerialExecution{StochasticPrograms.LShaped.FeasibilityHandler,Float64,Array{Float64,1}},StochasticPrograms.LShaped.HandleFeasibility{Float64},StochasticPrograms.LShaped.NoRegularization,StochasticPrograms.LShaped.NoAggregation,StochasticPrograms.LShaped.NoConsolidation})() at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\solver.jl:153
 [19] optimize!(::StochasticPrograms.LShaped.Optimizer) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\solvers\structured\lshaped\MOI_wrapper.jl:139
 [20] optimize!(::StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}}, ::StochasticPrograms.LShaped.Optimizer, ::Array{Float64,1}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\methods\vertical\optimization.jl:8
 [21] optimize!(::StochasticPrograms.StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(:tasks, :agents, :shifts, :pauses, :dqual, :pqual, :bigM, :min_tasks_per_shift, :max_extra_minutes),Tuple{Dict{Int64,Main.Tasks.task},Dict{Tuple,Main.Shifts.agent},Dict{Int64,Main.Shifts.shift},Dict{Int64,Main.Shifts.pause},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Float64,Float64}}},StochasticPrograms.Stage{NamedTuple{(:tasks, :agents, :shifts, :pauses, :dqual, :pqual, :bigM, :min_tasks_per_shift, :max_extra_minutes),Tuple{Dict{Int64,Main.Tasks.task},Dict{Tuple,Main.Shifts.agent},Dict{Int64,Main.Shifts.shift},Dict{Int64,Main.Shifts.pause},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Float64,Float64}}}},StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}}}; crash::StochasticPrograms.Crash.None, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\methods\api.jl:209
 [22] optimize!(::StochasticPrograms.StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(:tasks, :agents, :shifts, :pauses, :dqual, :pqual, :bigM, :min_tasks_per_shift, :max_extra_minutes),Tuple{Dict{Int64,Main.Tasks.task},Dict{Tuple,Main.Shifts.agent},Dict{Int64,Main.Shifts.shift},Dict{Int64,Main.Shifts.pause},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Float64,Float64}}},StochasticPrograms.Stage{NamedTuple{(:tasks, :agents, :shifts, :pauses, :dqual, :pqual, :bigM, :min_tasks_per_shift, :max_extra_minutes),Tuple{Dict{Int64,Main.Tasks.task},Dict{Tuple,Main.Shifts.agent},Dict{Int64,Main.Shifts.shift},Dict{Int64,Main.Shifts.pause},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Float64,Float64}}}},StochasticPrograms.VerticalStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Main.StochOptModel.CScenario}}}}) at C:\Users\M435719\.julia\packages\StochasticPrograms\yFtc7\src\methods\api.jl:201
 [23] solve_opt_model!(::Main.StochOptModel.opt_model) at C:\Users\M435719\OneDrive\OneDrive - Air France KLM\TARGETS\thor_poc\src_new\NEWFORM_opt_model_stoch_SP.jl:506
 [24] main() at C:\Users\M435719\OneDrive\OneDrive - Air France KLM\TARGETS\thor_poc\src_new\main.jl:32
 [25] top-level scope at C:\Users\M435719\OneDrive\OneDrive - Air France KLM\TARGETS\thor_poc\src_new\main.jl:45
 [26] include(::String) at .\client.jl:439
 [27] top-level scope at REPL[2]:1

Kind regards

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Performance issue with L-Shaped when using Gurobi in subproblems

Hi,
I was investigating why L-Shaped was not performing well and tracked the problem to subproblem generation with Gurobi. Linear subproblems are solved in less than 1/10 of second, and the master is solved in less than 10 seconds. Nevertheless, the overhead time between those two solves is overwhelming. Thus, I tried changing the subproblem solver to GLPK and to my surprise there was almost no overhead between solving the master and the subproblems. Please don't hesitate to tell me what can I provide you to track the issue.

Kind regards

Time Limit

Hello,

First of all thanks for this nice and useful project.

I am wondering if there is some parameter that determines the time limit of the whole optimization. I mean, we can set a time limit for the master optimizer and another time limit for the suboptimizer, but can we write just a single parameter for the whole optimization?

Thanks in advance.

Problem in Infinite sample space

Hi everyone

I am doing an exercise of Problem in Infinite sample space of

In this code:

@sampler SimpleSampler = begin
    N::StochasticPrograms.MvNormal

    SimpleSampler(μ, Σ) = new(StochasticPrograms.MvNormal(μ, Σ))

    @sample Scenario begin
        x = rand(sampler.N)
        return Scenario(q₁ = x[1], q₂ = x[2], d₁ = x[3], d₂ = x[4])
    end
end

μ = [24, 32, 400, 200]
Σ = [2 0.5 0 0
     0.5 1 0 0
     0 0 50 20
     0 0 20 30]

sampler = SimpleSampler(μ, Σ)

For now, we create a small sampled model of just 5 scenarios:

sampled_sp = instantiate(simple_model, sampler, 5, optimizer = GLPK.Optimizer)

I have a problem in the last line. The error is:

Given scenario Scenario with probability 0.2
  q₁: 25.786120623257716
  q₂: 33.627968929085654
  d₁: 397.440154821561
  d₂: 196.0127389756704 does not match @uncertain declaration.
in top-level scope at EjemploEstocastico2.jl:24
in  at StochasticPrograms\yFtc7\src\methods\api.jl:143
in #instantiate#487 at StochasticPrograms\yFtc7\src\methods\api.jl:158
in generate! at StochasticPrograms\yFtc7\src\methods\generation.jl:96
in generate! at StochasticPrograms\yFtc7\src\methods\deterministic_equivalent\generation.jl:11
in generate! at StochasticPrograms\yFtc7\src\methods\deterministic_equivalent\generation.jl:44
in  at base\none
in #11 at EjemploEstocastico.jl:18 
in error at base\error.jl:33

Can you help me, please?

Thanks in advance,
Adolfo

[Question] objective_value, evaluate_decision and the parts of the objective.

Hi,
thank you for your excellent package!

I am a bit confused about the interpretation of the various evaluate_decision and objective_value calls though and the documentation didn't clear things up.

Given a stochastic program like:

x_opt = min_x f(x) + E_s h(x, s)

We need the f(x_opt) variable and the h(x_opt, s) on various s.

We have a scenario that satisfies h(x_opt, s_zero) = 0.

Now the question is, what do the evaluate decision and objective value calls actually do? We noticed that

mean([objective_value(sp, i) for i in 1:n])  objective_value(sp)

is true

So objective_value(sp, i) should be f(x) + h(x, s_i)

However, evaluate_decision does not reproduce these objective values at all. E.g.:

evaluate_decision(sp, optimal_decision(sp), scens[i])

is larger, but of the same magnitude as

objective_value(sp, i)

Could you explain what is going on here? Is there a way to get to f(x) and h(x) separately?

LoadError: MethodError: no method matching copy(::StochasticPrograms.SingleDecisionSet{Float64})

Hi Martin,

I am trying to reproduce farmer example. Excact model is below:

##########################################
using GLPK
using StochasticPrograms

farmer_model = @stochastic_model begin
@stage 1 begin
@parameters begin
Crops = [:wheat, :corn, :beets]
Cost = Dict(:wheat=>150, :corn=>230, :beets=>260)
Budget = 500
end
@Decision(model, x[c in Crops] >=0, integer=true)
@objective(model, Min, sum(Cost[c]*x[c] for c in Crops))
@constraint(model, sum(x[c] for c in Crops) <= Budget)
@constraint(model, sum(x[c] for c in Crops) <= Budget)
end
@stage 2 begin
@parameters begin
Crops = [:wheat, :corn, :beets]
Required = Dict(:wheat=>200, :corn=>240, :beets=>0)
PurchasePrice = Dict(:wheat=>238, :corn=>210)
SellPrice = Dict(:wheat=>170, :corn=>150, :beets=>36, :extra_beets=>10)
end
@Uncertain ξ[c in Crops]
@variable(model, y[p in setdiff(Crops, [:beets])] >= 0)
@variable(model, w[s in Crops ∪ [:extra_beets]] >= 0)
@objective(model, Min, sum(PurchasePrice[p] * y[p] for p in setdiff(Crops, [:beets]))
- sum(SellPrice[s] * w[s] for s in Crops ∪ [:extra_beets]))
@constraint(model, minimum_requirement[p in setdiff(Crops, [:beets])],
ξ[p] * x[p] + y[p] - w[p] >= Required[p])
@constraint(model, minimum_requirement_beets,
ξ[:beets] * x[:beets] - w[:beets] - w[:extra_beets] >= Required[:beets])
@constraint(model, beets_quota, w[:beets] <= 6000)
end
end

ξ₁ = Scenario(wheat = 3.0, corn = 3.6, beets = 24.0, probability = 1/3)
ξ₂ = Scenario(wheat = 2.5, corn = 3.0, beets = 20.0, probability = 1/3)
ξ₃ = Scenario(wheat = 2.0, corn = 2.4, beets = 16.0, probability = 1/3)

farmer = instantiate(farmer_model, [ξ₁,ξ₂,ξ₃], optimizer = GLPK.Optimizer)

###################################

I get an error. Error message is below:

###################################
LoadError: MethodError: no method matching copy(::StochasticPrograms.SingleDecisionSet{Float64})
Closest candidates are:
copy(::BenchmarkTools.Parameters) at C:\Users\Ercan.julia\packages\BenchmarkTools\eCEpo\src\parameters.jl:60
copy(::SingleKnown) at C:\Users\Ercan.julia\packages\StochasticPrograms\g8Qnj\src\types\decisions\functions\decisions.jl:22
copy(::LinearAlgebra.Transpose{Bool,BitArray{2}}) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\LinearAlgebra\src\bitarray.jl:226
...
##########################

When I run the code line by line, I get following error at end of the line:

#####################
farmer = instantiate(farmer_model, [ξ₁,ξ₂,ξ₃], optimizer = GLPK.Optimizer)
##########################

Error displaying Atom.EvalError{MethodError}: BoundsError: attempt to access String
at index [8]

Can you please help me about this issue?

Thank you in advance.
Ercan

Typo in DecisionSparseAxisArray in macros.jl

Hi,
Just noticed that when using sparse-decisions arrays with the L-Shaped optimizer, an error was raised due to a typo in DecisionSparseAxisArray in macros.jl (Line 126, spelled "DecisionSpareAxisArray").

Kind regards

Write instantiated model to file

Instantiating a large model may take quite some time. Is there a way to save an instantiated model to a file? Ideally like write_to_file in JuMP.

Serializing and deserializing with the standard Julia functions did not work, causing the Julia session to crash when I optimized the deserialized model.

Downgrades the Gurobi version

Installing the package StochasticPrograms.jl downgrades Gurobi v0.11.5 to Gurobi v0.11.3. This results in "Failed to precompile Gurobi" error while importing the Gurobi package. I am using Gurobi version 9.1.2 on my mac.

ERROR: MethodError: no method matching add_to_expression!(::DecisionAffExpr{Float64}, ::Int64, ::DecisionAffExpr{Float64})

Hi,
I'm now working with a custom complicated model, and I'm having the Error stated above. By tracing the JuMP.add_to_expression! function, in one point StochasticPrograms.jl calls that function with the follow arguments (line 147, mutable_arithmetics.jl):

function MA.mutable_operate!(::typeof(-), expr::_DecisionAffOrQuadExpr, x)
    return JuMP.add_to_expression!(expr, -1, x)
end

Apparently, JuMP.add_to_expression! has not been implemented for Int64 on the middle argument, or for the combination of argument types:
image

In my case, expr and x are StochasticPrograms.DecisionAffExpr{Float64} type.
What can be the issue here?

Thanks in advance

Can't solve deterministic equivalent using SCS, COSMO or Xpress

Hi!
I was experimenting with the library and tried to solve some of examples on the Quickstart using different solvers to compare the performance.
Apparently the first example (deterministic equivalent) raises a method error on all_decisions if you substitute GLPK by SCS, COSMO or Xpress.
I also tested with Clp and the program runs fine.
Please tell me if there is any more info I can provide on the issues.

The code raising the error is the following:

using StochasticPrograms
import SCS
simple_model = @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₂
        @recourse(model, 0 <= y₁ <= d₁)
        @recourse(model, 0 <= y₂ <= d₂)
        @objective(model, Max, q₁*y₁ + q₂*y₂)
        @constraint(model, 6*y₁ + 10*y₂ <= 60*x₁)
        @constraint(model, 8*y₁ + 5*y₂ <= 80*x₂)
    end
end
ξ₁ = @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 = instantiate(simple_model, [ξ₁, ξ₂], optimizer = SCS.Optimizer)
optimize!(sp)

And the error message:

ERROR: LoadError: MethodError: no method matching all_decisions(::Determinist
icEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{
4,Float64}}},1}}})
Closest candidates are:
  all_decisions(::Model) at C:\Users\iago\.julia\packages\StochasticPrograms\
54439\src\types\decisions\variable_interface.jl:30
  all_decisions(::Decisions) at C:\Users\iago\.julia\packages\StochasticProgr
ams\54439\src\types\decisions\decisions.jl:123
  all_decisions(::Model, ::Integer) at C:\Users\iago\.julia\packages\Stochast
icPrograms\54439\src\types\decisions\variable_interface.jl:30
Stacktrace:
 [1] optimize!(::DeterministicEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{
(:q₁, :q₂, :d₁, :d₂),NTuple{4,Float64}}},1}}}, ::MathOptInterface.Utilities.C
achingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities
.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::Array{Float
64,1}) at C:\Users\iago\.julia\packages\StochasticPrograms\54439\src\methods\
deterministic_equivalent\optimization.jl:6
 [2] optimize!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTupl
e{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},Deterministi
cEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4
,Float64}}},1}}}}; crash::StochasticPrograms.Crash.None, kw::Base.Iterators.P
airs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\iago\.julia
\packages\StochasticPrograms\54439\src\methods\api.jl:209
 [3] optimize!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTupl
e{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(),Tuple{}}}},Deterministi
cEquivalent{2,1,Tuple{Array{Scenario{NamedTuple{(:q₁, :q₂, :d₁, :d₂),NTuple{4
,Float64}}},1}}}}) at C:\Users\iago\.julia\packages\StochasticPrograms\54439\
src\methods\api.jl:201

Why it tells me the MethodError when I use StochasticPrograms?

Hi, Martin
I have added the StochasticPrograms package,and use "using StochasticPrograms" ,but when I run the example"farmer" it tells me as following error:

ERROR: LoadError: MethodError: no method matching @stochastic_model(::LineNumberNode, ::Module, ::Symbol, ::Expr)
Closest candidates are:
  @stochastic_model(::LineNumberNode, ::Module, ::Any) at C:\Users\Lenovo\.julia\packages\StochasticPrograms\54439\src\types\stochasticmodel.jl:73
in expression starting at none:1

Also, it has the warning in the command window:
WARNING: both Distributions and JuMP export "shape"; uses of it in module StochasticPrograms must be qualified
How can I deal with it? Thanks a lot!

Solver hangs even when dual and primal problem gaps are set

Hi Martin, last week I've been working on a stochastic program using the L-Shaped implementation that you made. I've encountered an issue related with the issue #34, the optimization is not finishing, getting frozen, even when the gap is lower than one defined. I add the code snippet + the L-Shaped last status, I hope it is useful.

  set_optimizer_attribute(model, PrimalTolerance(), 1e-1)
  set_optimizer_attribute(model, DualTolerance(), 1e-1)

  sp = instantiate(model, program.scenarios, optimizer=LShaped.Optimizer)

  set_optimizer_attribute(sp, MasterOptimizer(),  GLPK.Optimizer)
  set_optimizer_attribute(sp, SubProblemOptimizer(),  GLPK.Optimizer)

  set_optimizer_attribute(sp, IntegerStrategy(), Convexification(strategy = Gomory()))
  set_optimizer_attribute(sp, FeasibilityStrategy(), FeasibilityCuts())

  StochasticPrograms.optimize!(sp)
L-Shaped Gap  Time: 0:03:35 (34 iterations)
  Objective:       40.998703442835755
  Gap:             1.7330858687984428e-16
  Number of cuts:  330
  Iterations:      34

Thanks in advanced 😄

Error during the instantiation of a program

Hi,

I have build a two-stage stochastic model using the package StochasticPrograms and now I am trying to instantiate this program.
The model is a little bit complicated so it is difficult to give all the information about it, but to summarize I have defined a new type of scenario made by two arrays of dictionaries providing the expectation function as described in the manual. Then I created an array of possible scenarios and all seems to work fine, I'm able to run the command expected on this array and it works as I was expecting. The problem appears when I try to run:

instantiate(model_user, possible_scenarios, optimizer = LShaped.Optimizer)

In this case, the following message is raised:

ERROR: LoadError: MethodError: no method matching build_variable(::JuMP.var"#_error#108"{LineNumberNode}, ::JuMP.Containers.SparseAxisArray{Any,3,Tuple{Any,Any,Any}}, ::StochasticPrograms.DecisionSet)
Closest candidates are:
  build_variable(::Function, ::VariableInfo, ::Any...; kwargs...) at /home/user/.julia/packages/JuMP/Xrr7O/src/macros.jl:1341
  build_variable(::Function, ::ScalarVariable, ::StochasticPrograms.DecisionSet) at /home/user/.julia/packages/StochasticPrograms/SjnV4/src/types/decisions/macros.jl:4
  build_variable(::Function, ::ScalarVariable, ::MathOptInterface.AbstractScalarSet) at /home/user/.julia/packages/JuMP/Xrr7O/src/macros.jl:1354
  ...
Stacktrace:
 [1] macro expansion at /home/user/.julia/packages/JuMP/Xrr7O/src/macros.jl:142 [inlined]
 [2] #121 at /home/user/File_stoch_nuovo/Single_user_vf.jl:63 [inlined]
 [3] (::var"#121#329")(::Model, ::NamedTuple{(:price_MG_P, :price_MG_N_V, :price_MG_N_F, :price_F, :c_UP),Tuple{Dict{Int64,Float64},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Dict{String,Float64}}}, ::Scenario_Load_Renewable) at ./none:0
 [4] generate_proxy!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(:price_MG_P, :price_MG_N_V, :price_MG_N_F, :price_F, :c_UP),Tuple{Dict{Int64,Float64},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Dict{String,Float64}}}}},StageDecompositionStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario_Load_Renewable}}}}) at /home/user/.julia/packages/StochasticPrograms/SjnV4/src/methods/generation.jl:104
 [5] generate!(::StochasticProgram{2,Tuple{StochasticPrograms.Stage{NamedTuple{(),Tuple{}}},StochasticPrograms.Stage{NamedTuple{(:price_MG_P, :price_MG_N_V, :price_MG_N_F, :price_F, :c_UP),Tuple{Dict{Int64,Float64},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Dict{String,Float64}}}}},StageDecompositionStructure{2,1,Tuple{StochasticPrograms.ScenarioProblems{Scenario_Load_Renewable}}}}) at /home/user/.julia/packages/StochasticPrograms/SjnV4/src/methods/generation.jl:143
 [6] instantiate(::StochasticModel{2,Tuple{StageParameters{NamedTuple{(),Tuple{}}},StageParameters{NamedTuple{(:price_MG_P, :price_MG_N_V, :price_MG_N_F, :price_F, :c_UP),Tuple{Dict{Int64,Float64},Dict{Int64,Float64},Dict{Int64,Float64},Float64,Dict{String,Float64}}}}}}, ::Array{Scenario_Load_Renewable,1}; instantiation::UnspecifiedInstantiation, optimizer::Type{T} where T, defer::Bool, direct_model::Bool, kw::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at /home/user/.julia/packages/StochasticPrograms/SjnV4/src/methods/api.jl:37
 [7] top-level scope at /home/user/File_stoch_nuovo/Single_user_vf.jl:239
 [8] include(::String) at ./client.jl:439
 [9] top-level scope at REPL[1]:1
in expression starting at /home/user/File_stoch_nuovo/Single_user_vf.jl:239

Also, I tried to run the command instantiate with different optimizer but nothing changed.
Is there someone who could help me please? Thank you for your help.

Problem in get WS'values

Hello everyone:

In the example of: https://martinbiel.github.io/StochasticPrograms.jl/dev/manual/quickstart/
there are 2 scenarios (ξ₁ and ξ₂), for each I can obtain the formulation:
ws1 = WS(sp, ξ₁)
print(ws1)
and
ws2 = WS(sp, ξ₂)
print(ws2)
all is ok

Using print (ws1) and print (ws2) and later of coding them in Julia by my own, I can obtain the EWS. So value of ws1 is 37.5 and ws2 -2556.25 , all ok.

But to take advantage of wait_and_see_decision, I can obtain values of x₁ and x₂ correctly using
x₁ = wait_and_see_decision(sp, ξ₁)
x₂ = wait_and_see_decision(sp, ξ₂)
However, value of ws1 and value of ws2 are not correct when I use:
ws1 = evaluate_decision(sp, x₁) #---the result is -762.5
ws2 = evaluate_decision(sp, x₂) #---the result is -626.25
and these are not the correct values....

What's going on? , Can you help me?

Thanks in advance,
Adolfo

Maintenance of repo

I'm looking to build additional tooling for two-stage stochastic programs and ran across this excellent modeling package. The issue is it appears to have fallen behind on maintaining compat with the updates in JuMP, MathOptInterface and certain solvers (as other folks have pointed out).

Would you be open to transferring ownership (probably to JuMP-dev ?) or giving admin rights to new folks who can help take over maintenance? I can volunteer to maintain the package (compat etc.). Alternatively, I am considering factoring out a new repo (say called StochasticProgrammingModels.jl with files from /src/macros and updating that to fit JuMP syntax (in the spirit of having packages only doing one thing). Please let me know your thoughts.

Shadow price of named constraint

Hello, I am trying to retrieve the shadow price for a first stage constraint @constraint(slpr_bp, cap, x_1 + x_2 <= 4 - η_hat) as such but I get the error UndefVarError: cap not defined when calling shadow_price(cap, 1) JuMP method (1 for first stage). Is this expected? How do I explicitly reference a named constraint of a certain stage? Thanks!

Safeguard for Stochastic programs with Integer recourses

Hey ! There is no safeguard for model with integer recourses. The standard L-Shaped method (for instance) can not be used in such cases. A safeguard could prevent errors of type ERROR: Gurobi Error 10005: Unable to retrieve attribute 'Pi' when adding new cuts during the method.

model of different stages

Hi, Martin
I have used StochasticPrograms to solve my model, However,there is a warning:

┌ Warning: First-stage has binary/integer decisions and no `IntegerStrategy` has been set. Procedure will fail if second-stage has binary/integer variables. Otherwise, the master_optimizer must be integer-capable.
└ @ StochasticPrograms.LShaped C:\Users\Lenovo\.julia\packages\StochasticPrograms\Jl6sf\src\solvers\structured\lshaped\integer\ignore_integers.jl:13

the first stage of my model is an MILP model,the second stage of my model is a LP model,I use LShaped.Optimizer to do it, I find there is no convergence tendency of iteration and sometimes even large fluctuations of my subproblem objective function value, is it related to the MILP master problem. As my best knowledge, there is some difference between the L shaped method and the integer L-shaped method, if I use Lshaped.Optimizer, which method the optimizer use?
Thanks a lot!

Installing StochasticPrograms.jl downgrades CPLEX.jl

Hi. I am new to StochasticPrograms.jl

I installed this package and got following message:
Pasted Graphic

(@v1.9) pkg> st CPLEX
Status ~/.julia/environments/v1.9/Project.toml
[a076750e] CPLEX v1.0.0

(@v1.9) pkg> add StochasticPrograms
Resolving package versions...
Installed FillArrays ─ v1.6.0
Updating ~/.julia/environments/v1.9/Project.toml
⌃ [a076750e] ↓ CPLEX v1.0.0 ⇒ v0.9.3
[8b8459f2] + StochasticPrograms v0.6.4
Updating ~/.julia/environments/v1.9/Manifest.toml
⌅ [4fba245c] ↓ ArrayInterface v7.4.11 ⇒ v6.0.25
[015c0d05] + ArrayInterfaceOffsetArrays v0.1.7
[b0d46f97] + ArrayInterfaceStaticArrays v0.1.5
[dd5226c6] + ArrayInterfaceStaticArraysCore v0.1.4
⌃ [a076750e] ↓ CPLEX v1.0.0 ⇒ v0.9.3

So current CPLEX.jl v1.0.0 downgraded to CPLEX.jl v0.9.3

The problem is that, CPLEX.jl v0.9.3 does not support a recent CPLEX software v22.1.1, which I am currently using.

(CPLEX.jl v0.9.3 only supports CPLEX 12.10, 20.1, 22.1)

Could you please address this issue?

Asynchronous Progressive Hedging Solution fetch issue

There seems to be an issue with accessing the solution of a 2-stage stochastic programming model after using PG with Asynchronous option to solve the same. The error occurs when we use JuMP.value(model[2, :x], 25) for say a 25 scenario problem. The issue arises when I try to access the solution of the decision variables in the last scenario. This error is erratic, some times it throws an error with a certain number of scenarios and it does not with others. The error does not occur when we do the same solve in the Serial mode.

Here is the stack trace:

ERROR: LoadError: On worker 10:
BoundsError: attempt to access 3-element Vector{Model} at index [4]
Stacktrace:
 [1] getindex
   @ ./array.jl:861
 [2] #298
   @ ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:404
 [3] #110
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278
 [4] run_work_thunk
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:63
 [5] macro expansion
   @ ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/process_messages.jl:278 [inlined]
 [6] #109
   @ ./task.jl:429
Stacktrace:
  [1] remotecall_fetch(::Function, ::Distributed.Worker, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:469
  [2] remotecall_fetch(::Function, ::Distributed.Worker, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:461
  [3] remotecall_fetch(::Function, ::Int64, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:496
  [4] remotecall_fetch(::Function, ::Int64, ::RemoteChannel{Channel{StochasticPrograms.ScenarioProblems{AbstractScenario}}}, ::Vararg{Any})
    @ Distributed ~/Applications/Julia-1.7.app/Contents/Resources/julia/share/julia/stdlib/v1.7/Distributed/src/remotecall.jl:496
  [5] get_from_scenarioproblem(::Function, ::StochasticPrograms.DistributedScenarioProblems{AbstractScenario}, ::Int64, ::Function, ::Vararg{Any})
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:102
  [6] scenario_decision_dispatch(::Function, ::StochasticPrograms.DistributedScenarioProblems{AbstractScenario}, ::MathOptInterface.VariableIndex, ::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenarioproblems.jl:403
  [7] scenario_decision_dispatch(::Function, ::ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}, ::MathOptInterface.VariableIndex, ::Int64, ::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decomposition/scenario_decomposition.jl:392
  [8] decision(dvar::DecisionVariable, scenario_index::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:57
  [9] value(dvar::DecisionVariable, scenario_index::Int64; result::Int64)
    @ StochasticPrograms ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:427
 [10] value
    @ ~/.julia/packages/StochasticPrograms/pIScW/src/types/decision_variable.jl:426 [inlined]
 [11] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
 [12] _broadcast_getindex
    @ ./broadcast.jl:643 [inlined]
 [13] getindex
    @ ./broadcast.jl:597 [inlined]
 [14] macro expansion
    @ ./broadcast.jl:961 [inlined]
 [15] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [16] copyto!
    @ ./broadcast.jl:960 [inlined]
 [17] copyto!
    @ ./broadcast.jl:913 [inlined]
 [18] copy
    @ ./broadcast.jl:885 [inlined]
 [19] materialize
    @ ./broadcast.jl:860 [inlined]
 [20] broadcast(::typeof(value), ::Vector{DecisionVariable}, ::Int64)
    @ Base.Broadcast ./broadcast.jl:798
 [21] broadcasted(::Base.Broadcast.ArrayStyle{JuMP.Containers.DenseAxisArray}, ::Function, ::JuMP.Containers.DenseAxisArray{DecisionVariable, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, ::Int64)
    @ JuMP.Containers ~/.julia/packages/JuMP/60Bnj/src/Containers/DenseAxisArray.jl:437
 [22] broadcasted(::Function, ::JuMP.Containers.DenseAxisArray{DecisionVariable, 1, Tuple{Vector{Int64}}, Tuple{JuMP.Containers._AxisLookup{Dict{Int64, Int64}}}}, ::Int64)
    @ Base.Broadcast ./broadcast.jl:1303
 [23] (::var"#167#187"{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}})(i::Int64)
    @ Main ./none:0
 [24] iterate
    @ ./generator.jl:47 [inlined]
 [25] Dict{String, Any}(kv::Base.Generator{UnitRange{Int64}, var"#167#187"{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}}})
    @ Base ./dict.jl:104
 [26] save_preventive_control_model_results(ref::Dict{Symbol, Any}, cli_args::Dict{String, Any}, preventive_model::NamedTuple{(:model, :scenarios, :var, :extra), Tuple{StochasticProgram{2, Tuple{StochasticPrograms.Stage{Nothing}, StochasticPrograms.Stage{Nothing}}, ScenarioDecompositionStructure{2, 1, Tuple{StochasticPrograms.DistributedScenarioProblems{AbstractScenario}}}}, Vector{AbstractScenario}, Dict{Symbol, Any}, Dict{Symbol, Any}}}, off_branches::Vector{Any}, file::String)
    @ Main ~/Documents/codes/wildfire-bes/src/preventive.jl:266
 [27] run_preventive_control_model(ref::Dict{Symbol, Any}, input_cli_args::Dict{String, Any})
    @ Main ~/Documents/codes/wildfire-bes/src/main.jl:95
 [28] top-level scope
    @ ~/Documents/codes/wildfire-bes/src/main.jl:119

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.