Closed maramos874 closed 3 years ago
Could you post a MWE of what you want to achieve so I can reproduce the error?
Finally managed to produce a MWE after figuring out what was causing the error, when using structures to store parameters, Note that by replacing p.cc by its value, the error is not raised.
using Gurobi
using StochasticPrograms
struct params
cc::Float64
end
p = params(240.0)
function main()
model = @stochastic_model begin
@stage 1 begin
@parameters begin
tasks = 1:5
shifts = 1:5
agents = 1:5
qualifs = 1:3
end
@decision(model, 0 <= extime[sh in shifts, ag in agents])
@decision(model, 0 <= yqual[sh in shifts, ag in agents, qu in qualifs] <= 1, Int)
@objective(model, Min, sum(yqual[sh, ag, qu] for sh in shifts for ag in agents for qu in qualifs))
@constraint(model, sh_con5[sh=shifts, ag=agents],
extime[sh, ag]
<=
p.cc *
sum(yqual[sh, ag, qu]
for qu in qualifs
)
)
end
@stage 2 begin
@parameters begin
c = 1:5
end
@uncertain e
@variable(model, y[i in c] >= 0)
@objective(model, Min, sum(y[i] for i in c))
@constraint(model, test2[i in 2:5], y[i] + e >= y[i-1])
end
end
ξ₁ = Scenario(e=1, probability = 1/3)
ξ₂ = Scenario(e=2, probability = 1/3)
ξ₃ = Scenario(e=3, probability = 1/3)
model = instantiate(model, [ξ₁, ξ₂, ξ₃], optimizer=Gurobi.Optimizer)
print(model)
optimize!(model)
x = optimal_decision(model)
println("Wheat: $(x[1])")
println("Corn: $(x[2])")
println("Beets: $(x[3])")
println("Profit: $(objective_value(model))")
println("EVPI: $(EVPI(model))")
println("VSS: $(VSS(model))")
end
main()
Thank you for the MWE. I am very busy this week with paper revision, but I will look into this as well as the other issues you have posted afterwards :slightly_smiling_face:
Ok, no problem! Happy to help.
Should be fixed now. Your MWE pointed me to another bug as well, so thanks a lot! :slightly_smiling_face:
Nice! Happy to help.
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):
Apparently, JuMP.add_to_expression! has not been implemented for Int64 on the middle argument, or for the combination of argument types:![image](https://user-images.githubusercontent.com/29888045/93607743-058c1d00-f9ca-11ea-84a6-59f040638e44.png)
In my case, expr and x are StochasticPrograms.DecisionAffExpr{Float64} type. What can be the issue here?
Thanks in advance