using StochasticPrograms is at the top of the file.
I am using the latest documentation, but I think the example is using syntax which has been been deprecated, e.g.
optimize!(farmer, solver = GLPKSolverLP())
I have given my code below, which is replaces these two lines in the farmer example:
But, I still get “UndefVarError: @stochastic_model not defined” error.
farmer_model = @stochastic_model begin
@stage 1 begin
Crops = [:wheat, :corn, :beets]
Cost = Dict(:wheat=>150, :corn=>230, :beets=>260)
Budget = 500
@variable(model, x[c = Crops] >= 0)
@objective(model, Min, sum(Cost[c]*x[c] for c in Crops))
@constraint(model, sum(x[c] for c in Crops) <= Budget)
@stage 2 begin
Purchased = [:wheat, :corn]
Sold = [:wheat, :corn, :bquota, :bextra]
Required = Dict(:wheat=>200, :corn=>240, :beets=>0)
PurchasePrice = Dict(:wheat=>238, :corn=>210)
SellPrice = Dict(:wheat=>170, :corn=>150, :bquota=>36, :bextra=>10)
@uncertain ξ::YieldScenario = begin
@variable(model, y[p = Purchased] >= 0)
@variable(model, w[s = Sold] >= 0)
@objective(model, Min, sum( PurchasePrice[p] * y[p] for p = Purchased) - sum( SellPrice[s] * w[s] for s in Sold))
ξ[p] * x[p] + y[p] - w[p] >= Required[p])
ξ[:beets] * x[:beets] - w[:bquota] - w[:bextra] >= Required[:beets])
@constraint(model, const_aux, w[:bquota] <= 6000)
ξ₁ = YieldScenario(3.0, 3.6, 24.0, probability = 1/3)
ξ₂ = YieldScenario(2.5, 3.0, 20.0, probability = 1/3)
ξ₃ = YieldScenario(2.0, 2.4, 16.0, probability = 1/3)
farmer = instantiate(farmer_model, [ξ₁,ξ₂,ξ₃])
x = optimal_decision(farmer, :x)
Currently, I am going through the examples of the various stochastic programs given. But I will be looking to solve two stage stochastic programming problems with uncertain variables both in the objective function and constraints.