Search code examples
juliajulia-jump

Julia LoadError: MethodError: no method matching addconstraint(::Int64, ::Jump.GenericRangeConstarint{JuMP.GenericAffExpr{Float64,JuMP.Variable}})


I am trying to run the following file. i tried uploading piece by piece. That is why some of the components are commented out. No matter which component I have activated I receive this error for the constraints part.

using JuMP
using Gurobi


pset = ["packaging1", "packaging2"]
size_pset = 2
fset = ["filling1", "filling2"]
size_fset = 2
mset = ["manufacturing1","manufacturing2"]
size_mset = 2
timeset = [1,2,3,4,5,6,7,8,9,10]
size_timeset = 10
fgset = ["product1","product2"]
size_fgset = 2
bulkset = ["bulk1","bulk2"]
size_bulkset = size_fgset
apiset = ["api1","api2"]
size_apiset = 2
scenarioset = ["s1","s2","s3","s4","s5","s6","s7","s8","s9","s10","s11","s12","s13","s14","s15","s16"]
size_scenarioset = 16
CFF = 0.7
CFP = 0.5
SR = 2
RW = 2
KGS = 2

ESTputP= 100
ESTputF= 100
ESTputM= 100

m = Model(solver=GurobiSolver())

@variable(m, ThputM[1:size_mset, 1:size_timeset, 1:size_apiset, 1:size_scenarioset] >= 0) 
@variable(m, InThputM[1:size_fset, 1:size_timeset, 1:size_apiset, 1:size_bulkset, 1:size_scenarioset] >= 0)
@variable(m, XP_p[1:size_pset, 1:size_timeset, 1:size_fgset] >= 0)
@variable(m, XP_n[1:size_pset, 1:size_timeset, 1:size_fgset] >= 0)
@variable(m, XF_p[1:size_fset, 1:size_timeset, 1:size_bulkset] >= 0)
@variable(m, XF_n[1:size_fset, 1:size_timeset, 1:size_bulkset] >= 0)
@variable(m, XM_p[1:size_mset, 1:size_timeset, 1:size_apiset] >= 0)
@variable(m, XM_n[1:size_mset, 1:size_timeset, 1:size_apiset] >= 0)

#objective
@objective(m, Min, sum(XM_p[m,t,a]+XM_n[m,t,a] for m=1:size_mset for t=1:size_timeset for a=1:size_apiset)+
                    sum(XF_p[f,t,b]+XF_n[f,t,b] for f=1:size_fset for t=1:size_timeset for b=1:size_bulkset)+
                    sum(XP_p[p,t,f]+XP_n[p,t,f] for p=1:size_pset for t=1:size_timeset for f=1:size_fgset))

# Constraints:
#@constraint(m, thput_relateM[m=1:size_mset, t=1:size_timeset, a=1:size_apiset, s=1:size_scenarioset],ThputM[m,t,a,s]==SR*RW*KGS)

@constraint(m, thput_relate_M_Bulk_API[m=1:size_mset, t=1:size_timeset, a=1:size_apiset, s=1:size_scenarioset],
              sum(InThputM[m,t,a,b,s] for b=1:size_bulkset)==ThputM[m,t,a,s])

writeLP(m, 'Sifomodel.lp'; genericnames=false)

status = solve(m)

println("Solve status: ", status)
println("Objective value: ", getobjectivevalue(m))

What can be the reson for particularly "constraint upload"?


Solution

  • It seems like JuMP wants all constants on the right hand side while variables are collected on the other side. When the constraints are re-arranged in this manner, it accepts the model.