Closed gganetlepage closed 3 years ago
Hello everyone, The same problem comes to me. I will be very grateful to anyone who can find the solution
Thanks,
Hey, StochasticPrograms seems incompatible with the latest MathOptInterface version released a few days ago. Until I have sorted that out, downgrading MOI should remove the error temporarily.
Hello, you mean using MathOptInterface v0.9.17 ?, but that package I don't use. Besides StochasticPrograms, I use GLPK (v0.14.2) as an optimizer. Is GLPK using MathOptInterface??? , I must downgrade the GLPX package....
[c52e3926] Atom v0.12.25 [60bf3e95] GLPK v0.14.2 [e5e0dc1b] Juno v0.8.4 [b8f27783] MathOptInterface v0.9.17 [8b8459f2] StochasticPrograms v0.4.1
StochasticPrograms has MOI as a dependency, so you get it automatically. pgk> add StochasticPrograms#master
and pkg> add MathOptInterface@0.9.17
should work as a temporary fix.
Thanks , it works. We keep on waiting for the final solution
In this example: https://martinbiel.github.io/StochasticPrograms.jl/dev/manual/examples/
What is the function to obtain the value of variables of tons bought and sold (y, w) -recourses var-? ... I think it is optimal_recourse_decision... but not work...
See #15 for a discussion about this.
Hi, thank you, the trick works.
Keeping this open until I have fixed the bug.
Hello ! Seems that fixing MOI by downgrading it (v0.9.17 but also v0.9.16) doesn't work either. Thank you for your work and good luck to fix this !
(stochastic-kep) pkg> status
Status `~/Documents/INSA/5GM/stochastic-kep/Code/Project.toml`
[60bf3e95] GLPK v0.14.2
[4076af6c] JuMP v0.21.4
[b8f27783] MathOptInterface v0.9.17
[8b8459f2] StochasticPrograms v0.4.1
julia> using StochasticPrograms, GLPK
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 copy(::StochasticPrograms.SingleDecisionSet{Float64})
Closest candidates are:
copy(::Expr) at expr.jl:36
copy(::Core.CodeInfo) at expr.jl:64
copy(::BitSet) at bitset.jl:46
...
Stacktrace:
[1] add_constraint(::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}, ::MathOptInterface.SingleVariable, ::StochasticPrograms.SingleDecisionSet{Float64}) at /Users/theoguyard/.julia/packages/MathOptInterface/8Mxwr/src/Utilities/universalfallback.jl:460
[2] add_constrained_variable(::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}, ::StochasticPrograms.SingleDecisionSet{Float64}) at /Users/theoguyard/.julia/packages/MathOptInterface/8Mxwr/src/variables.jl:88
[3] add_constrained_variable(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}}, ::StochasticPrograms.SingleDecisionSet{Float64}) at /Users/theoguyard/.julia/packages/MathOptInterface/8Mxwr/src/Utilities/cachingoptimizer.jl:289
[4] add_variable(::Model, ::VariableConstrainedOnCreation{StochasticPrograms.SingleDecisionSet{Float64},ScalarVariable{Int64,Float64,Float64,Float64}}, ::String) at /Users/theoguyard/.julia/packages/StochasticPrograms/g8Qnj/src/types/decisions/macros.jl:25
[5] macro expansion at /Users/theoguyard/.julia/packages/JuMP/e0Uc2/src/macros.jl:91 [inlined]
[6] (::var"#15#20")(::Model, ::NamedTuple{(),Tuple{}}) at ./PI�:0
[7] 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 /Users/theoguyard/.julia/packages/StochasticPrograms/g8Qnj/src/methods/deterministic_equivalent/generation.jl:28
[8] 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 /Users/theoguyard/.julia/packages/StochasticPrograms/g8Qnj/src/methods/deterministic_equivalent/generation.jl:11
[9] 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 /Users/theoguyard/.julia/packages/StochasticPrograms/g8Qnj/src/methods/generation.jl:92
[10] 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/theoguyard/.julia/packages/StochasticPrograms/g8Qnj/src/methods/api.jl:37
[11] top-level scope at REPL[15]:1
You need to be on the master branch as well. pkg> add StochasticPrograms#master
Fixed on master.
Hi, Seems the problem still exists as I am getting the same error, for the same toy problem:
using StochasticPrograms using GLPK using Ipopt
simple_model = @stochastic_model begin @stage 1 begin @decision(model, x₁ >= 40) @decision(model, x₂ >= 20) @objective(model, Min, 100x₁ + 150x₂) @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, 6y₁ + 10y₂ <= 60x₁) @constraint(model, 8y₁ + 5y₂ <= 80x₂) 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 = GLPK.Optimizer)
I have downgraded the MathOptInterface and use StochasticPrograms v0.4.1 #master as you can see below:
(SAA) pkg> status
Status C:\Users\Less\Julia\SAA\Project.toml
[60bf3e95] GLPK v0.14.2
[b6b21f68] Ipopt v0.6.3
[4076af6c] JuMP v0.21.4
[b8f27783] MathOptInterface v0.9.17
[8b8459f2] StochasticPrograms v0.4.1 #master (https://github.com/martinbiel/StochasticPrograms.jl.git)
julia> versioninfo() Julia Version 1.2.0 Commit c6da87ff4b (2019-08-20 00:03 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32)
Any idea, why this happens?
Thank you
With the latest fix, downgrading MOI should no longer be necessary. Maybe you need to re-add master to get the latest commits? I only test on 1.0 and 1.5 as well, so your Julia version might matter. What exact error are you getting?
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,
Edit: added a fenced code block