Julia LoadError:MethodError:没有匹配addconstraint的方法(:: Int64,:: Jump.GenericRangeConstarint {JuMP.GenericAffExpr {Float64,JuMP.Variable}})

时间:2017-01-30 20:17:01

标签: julia julia-jump

我正在尝试运行以下文件。我试着一块一块地上传。这就是为什么有些组件被注释掉了。无论我激活哪个组件,我都会收到约束部分的错误。

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))

特别是"约束上传"?

的共鸣是什么?

2 个答案:

答案 0 :(得分:1)

如果您使用m作为索引,它将覆盖模型对象m。请注意,错误消息显示您尝试使用addconstraint参数而不是(integer,constraint)来呼叫(model,constraint)

答案 1 :(得分:0)

似乎JuMP需要右侧的所有常量,而另一侧则收集变量。当以这种方式重新排列约束时,它接受模型。