使用Julia跳转时出现意外错误

使用Julia跳转时出现意外错误,julia,gurobi,julia-jump,Julia,Gurobi,Julia Jump,我试图解决一个优化问题,我得到的错误如下 错误:m应为跳转模型,但其类型为Int64 在C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:247的validmodel(::Int64,::Symbol)中 在宏扩展中;位于C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:252[内联] 在宏扩展中;在。\REPL[608]:3[内联] 在匿名地址。\:?” 请参阅以下代码(约束2中的错误)。请不要介意我定义数组的方式,非

我试图解决一个优化问题,我得到的错误如下 错误:m应为跳转模型,但其类型为Int64 在C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:247的validmodel(::Int64,::Symbol)中 在宏扩展中;位于C:\Users\Ting.julia\v0.5\JuMP\src\macros.jl:252[内联] 在宏扩展中;在。\REPL[608]:3[内联] 在匿名地址。\:?”

请参阅以下代码(约束2中的错误)。请不要介意我定义数组的方式,非常感谢您的帮助。多谢各位

using JuMP
using Gurobi

m = Model(solver = GurobiSolver()) #if GurobiSolver is to be used .
## insert all matrixs here
#this is the cost for plant to warehouse

plant=4 #last index for {1,2,3}
product=5 #ast index for {2,3,4}
customer=50
warehouse=4


@variable(m, x[i=1:product ,k=1:plant,l=1:warehouse]>=0) #plant to warehouse
@variable(m, y[i=1:product ,k=1:warehouse,l=1:customer]>=0) #warehouse to customer
@variable(m, z[i=1:product ,k=1:plant,l=1:customer ]>=0) #plant to customer
@variable(m, p[i=1:product ,k=1:plant]>=0) #any product i produced at plant k

#THIS GIVES COST OF PRODUCING AT ANY PRODUCT I AT PLANT K
PC=[500 500 500 500;
400 400 400 400;
300 300 300 300;
200 200 200 200;
100 100 100 100]

#DEMAND OF I AT ANY COSTOMER M, SHOULD BE A MATRIX OF (5*50)
D=[4650.28 10882.70 7920.68 2099.06 4920.32 5077.80 2259.10 9289.30 9782.28 4671.85 6625.68 6956.80 5288.12 4144.78 11121.56 9152.47 10206.88 4601.63 2718.91 1439.39 2984.38 3631.17 3934.48 12314.28 4188.04 8437.43 6302.34 1248.62 6286.56 7333.46 11027.86 6233.33 7240.82 5652.13 10276.03 1197.22 11160.13 4510.31 8850.49 8291.09 1081.47 7652.23 3936.85 2640.47 7726.72 1422.96 1644.78 1060.39 6858.66 6554.45;
 528.11 4183.80 352.45 366.34 1961.78 3419.11 337.44 708.15 3556.56 1649.95 583.25 1525.97 1569.92 349.93 1904.59 2221.80 2139.63 1822.87 546.11 784.93 948.33 1424.26 1910.64 2275.11 1527.57 2477.49 1592.14 90.86 2635.48 131.02 2402.35 2669.67 105.34 1350.60 4233.60 411.54 687.88 89.09 213.23 2817.29 8.08 1586.51 577.07 1529.34 2919.06 393.97 85.45 214.93 3193.94 1565.64;
 480.26 622.67 131.04 14.45 1299.71 599.27 83.08 197.37 1986.77 409.08 371.12 1249.92 216.21 62.43 34.96 1752.75 227.06 184.26 219.92 577.37 138.71 36.23 1659.02 1323.50 236.64 2557.64 76.74 74.08 363.64 52.96 456.67 1589.86 81.89 617.11 509.86 145.52 14.13 83.22 215.03 2749.34 7.12 490.00 120.42 456.03 430.22 165.02 66.16 150.70 2806.58 1403.70;
 307.36 474.39 7.56 11.76 882.03 222.62 27.29 158.13 55.94 332.98 171.36 492.81 44.12 24.08 15.57 739.97 11.09 199.51 136.46 194.40 63.72 2.42 355.99 1005.42 66.33 1647.51 47.22 21.32 218.06 11.54 305.81 387.71 8.50 248.38 9.20 76.05 13.12 39.83 146.52 379.44 2.75 239.53 94.06 136.96 290.16 237.75 9.04 110.64 842.58 395.08;
 76.52 280.62 5.06 6.75 281.41 215.58 5.78 54.69 20.79 22.08 78.50 322.13 34.13 6.37 11.66 178.33 3.40 142.11 60.70 46.17 6.96 1.15 227.70 669.39 3.21 526.85 45.91 17.00 131.43 11.19 189.00 43.93 3.36 110.66 1.75 41.34 0   38.63 50.78 241.19 0   176.32 94.25 99.59 153.50 123.02 3.76 122.52 853.48 99.62]



a = Array{Float64}(5,4,4)
a[1,1,1]=a[2,1,1]=a[3,1,1]=a[4,1,1]=a[5,1,1]=0.2*528.42
a[1,2,1]=a[2,2,1]=a[3,2,1]=a[4,2,1]=a[5,2,1]=0.2*1366.16
a[1,3,1]=a[2,3,1]=a[3,3,1]=a[4,3,1]=a[5,3,1]=0.2*1525.41
a[1,4,1]=a[2,4,1]=a[3,4,1]=a[4,4,1]=a[5,4,1]=0.2*878.11


a[1,1,2]=a[2,1,2]=a[3,1,2]=a[4,1,2]=a[5,1,2]=0.2*1692.25
a[1,2,2]=a[2,2,2]=a[3,2,2]=a[4,2,2]=a[5,2,2]=0.2*1553.06
a[1,3,2]=a[2,3,2]=a[3,3,2]=a[4,3,2]=a[5,3,2]=0.2*817.18
a[1,4,2]=a[2,4,2]=a[3,4,2]=a[4,4,2]=a[5,4,2]=0.2*2164.69

a[1,1,3]=a[2,1,3]=a[3,1,3]=a[4,1,3]=a[5,1,3]=0.2*2006.5
a[1,2,3]=a[2,2,3]=a[3,2,3]=a[4,2,3]=a[5,2,3]=0.2*1385.04
a[1,3,3]=a[2,3,3]=a[3,3,3]=a[4,3,3]=a[5,3,3]=0.2*998.58
a[1,4,3]=a[2,4,3]=a[3,4,3]=a[4,4,3]=a[5,4,3]=0.2*2148.45

a[1,1,4]=a[2,1,4]=a[3,1,4]=a[4,1,4]=a[5,1,4]=0.2*1073.07
a[1,2,4]=a[2,2,4]=a[3,2,4]=a[4,2,4]=a[5,2,4]=0.2*368.35
a[1,3,4]=a[2,3,4]=a[3,3,4]=a[4,3,4]=a[5,3,4]=0.2*450.12
a[1,4,4]=a[2,4,4]=a[3,4,4]=a[4,4,4]=a[5,4,4]=0.2*1129.27   



@objective(m, Min ,sum(a[i,k,l]* x[i,k,l] for i=1:product for k=1:plant for l=1:warehouse) + sum(c_dash[i,l,m]* y[i,l,m] for i=1:product for l=1:warehouse for m=1:plant) +sum(c_dash_dash[i,k,m]* z[i,k,m] for i=1:product for k=1:plant for m=1:customer)+sum(PC[i,k]* p[i,k] for i=1:product for k=1:plant))  #to be changes






@constraint(m,p[1,2]==0)
@constraint(m,p[1,3]==0)
@constraint(m,p[1,4]==0)
@constraint(m,p[2,1]==0)
@constraint(m,p[2,3]==0)
@constraint(m,p[2,4]==0)
@constraint(m,p[3,1]==0)
@constraint(m,p[3,2]==0)
@constraint(m,p[3,4]==0)
@constraint(m,p[4,1]==0)
@constraint(m,p[4,2]==0)
@constraint(m,p[4,3]==0)
@constraint(m,p[5,1]==0)
@constraint(m,p[5,2]==0)
@constraint(m,p[5,3]==0)
@constraint(m,p[1,1]<=450000)
@constraint(m,p[2,2]<=108000)
@constraint(m,p[3,3]<=45000)
@constraint(m,p[4,4]<=18000)
@constraint(m,p[5,4]<=9000)

#constraint 1
@constraint(m,415728.69-0.8* sum(y[i,l,m] for i=1:product for l=1:warehouse for m=1:customer) <=0)  


#constrainst 2
for m=1:customer
    for i=1:product 
@constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 )  #cant get
    end
end
使用跳转
使用古罗比
m=模型(solver=GurobiSolver())#如果要使用GurobiSolver。
##在此处插入所有矩阵
#这是工厂到仓库的成本
plant=4#{1,2,3}的最后一个索引
乘积=5#ast{2,3,4}索引
顾客=50
仓库=4
@变量(m,x[i=1:产品,k=1:工厂,l=1:仓库]>=0)#工厂到仓库
@变量(m,y[i=1:产品,k=1:仓库,l=1:客户]>=0)#仓库对客户
@变量(m,z[i=1:产品,k=1:工厂,l=1:客户]>=0)#工厂对客户
@变量(m,p[i=1:产品,k=1:工厂]>=0)#我在工厂k生产的任何产品
#这就给出了K工厂任何产品I的生产成本
PC=[500;
400 400 400 400;
300 300 300 300;
200 200 200 200;
100 100 100 100]
#任何客户M对I的需求应为(5*50)的矩阵
D=[4650.28 10882.70 7920.68 2099.06 4920.32 5077.80 2259.10 9289.30 9782.28 4671.85 6625.68 6956.80 5288.12 4144.78 11121.56 9152.47 10206.88 4601.63 2718.91 1439.39 2984.38 3631.17 3934.48 12314.28 4188.04 8437.43 6302.34 1248.62 6286.56 7333.46 11027.86 6233.33 7240.82 5652.13 10276.03 1197.22 11160.13 4510.31 8850.49 8291.09 1081.47 7652.23 3936.85 2640.47 7726.72 1422.96 1644.78 1060.39 6858.66 6554.45;
528.11 4183.80 352.45 366.34 1961.78 3419.11 337.44 708.15 3556.56 1649.95 583.25 1525.97 1569.92 349.93 1904.59 2221.80 2139.63 1822.87 546.11 784.93 948.33 1424.26 1910.64 2275.11 1527.57 2477.49 1592.14 90.86 2635.48 131.02 2402.35 2669.67 105.34 1350.60 4233.60 411.54 687.88 89.09 213.23 2817.29 8.08 1586.51 577.07 1529.34 2919.06 393.97 85.45 214.93 3193.94 1565.64;
480.26 622.67 131.04 14.45 1299.71 599.27 83.08 197.37 1986.77 409.08 371.12 1249.92 216.21 62.43 34.96 1752.75 227.06 184.26 219.92 577.37 138.71 36.23 1659.02 1323.50 236.64 2557.64 76.74 74.08 363.64 52.96 456.67 1589.86 81.89 617.11 509.86 145.52 14.13 83.22 215.03 2749.34 7.12 490.00 120.42 456.03 430.22 165.02 66.16 150.70 2806.58 1403.70;
307.36 474.39 7.56 11.76 882.03 222.62 27.29 158.13 55.94 332.98 171.36 492.81 44.12 24.08 15.57 739.97 11.09 199.51 136.46 194.40 63.72 2.42 355.99 1005.42 66.33 1647.51 47.22 21.32 218.06 11.54 305.81 387.71 8.50 248.38 9.20 76.05 13.12 39.83 146.52 379.44 2.75 239.53 94.06 136.96 290.16 237.75 9.04 110.64 842.58 395.08;
76.52 280.62 5.06 6.75 281.41 215.58 5.78 54.69 20.79 22.08 78.50 322.13 34.13 6.37 11.66 178.33 3.40 142.11 60.70 46.17 6.96 1.15 227.70 669.39 3.21 526.85 45.91 17.00 131.43 11.19 189.00 43.93 3.36 110.66 1.75 41.34 0   38.63 50.78 241.19 0   176.32 94.25 99.59 153.50 123.02 3.76 122.52 853.48 99.62]
a=数组{Float64}(5,4,4)
a[1,1,1]=a[2,1,1]=a[3,1,1]=a[4,1,1]=a[5,1,1]=0.2*528.42
a[1,2,1]=a[2,2,1]=a[3,2,1]=a[4,2,1]=a[5,2,1]=0.2*1366.16
a[1,3,1]=a[2,3,1]=a[3,3,1]=a[4,3,1]=a[5,3,1]=0.2*1525.41
a[1,4,1]=a[2,4,1]=a[3,4,1]=a[4,4,1]=a[5,4,1]=0.2*878.11
a[1,1,2]=a[2,1,2]=a[3,1,2]=a[4,1,2]=a[5,1,2]=0.2*1692.25
a[1,2,2]=a[2,2,2]=a[3,2,2]=a[4,2,2]=a[5,2,2]=0.2*1553.06
a[1,3,2]=a[2,3,2]=a[3,3,2]=a[4,3,2]=a[5,3,2]=0.2*817.18
a[1,4,2]=a[2,4,2]=a[3,4,2]=a[4,4,2]=a[5,4,2]=0.2*2164.69
[1,1,3]=a[2,1,3]=a[3,1,3]=a[4,1,3]=a[5,1,3]=0.2*2006.5
a[1,2,3]=a[2,2,3]=a[3,2,3]=a[4,2,3]=a[5,2,3]=0.2*1385.04
a[1,3,3]=a[2,3,3]=a[3,3,3]=a[4,3,3]=a[5,3,3]=0.2*998.58
a[1,4,3]=a[2,4,3]=a[3,4,3]=a[4,4,3]=a[5,4,3]=0.2*2148.45
a[1,1,4]=a[2,1,4]=a[3,1,4]=a[4,1,4]=a[5,1,4]=0.2*1073.07
a[1,2,4]=a[2,2,4]=a[3,2,4]=a[4,2,4]=a[5,2,4]=0.2*368.35
a[1,3,4]=a[2,3,4]=a[3,3,4]=a[4,3,4]=a[5,3,4]=0.2*450.12
a[1,4,4]=a[2,4,4]=a[3,4,4]=a[4,4,4]=a[5,4,4]=0.2*1129.27
@目标(m,Min,sum(i=1的a[i,k,l]*x[i,k,l]:k=1的产品:l=1的工厂:仓库)+和
@约束(m,p[1,2]==0)
@约束(m,p[1,3]==0)
@约束(m,p[1,4]==0)
@约束(m,p[2,1]==0)
@约束(m,p[2,3]==0)
@约束(m,p[2,4]==0)
@约束(m,p[3,1]==0)
@约束(m,p[3,2]==0)
@约束条件(m,p[3,4]==0)
@约束(m,p[4,1]==0)
@约束(m,p[4,2]==0)
@约束(m,p[4,3]==0)
@约束条件(m,p[5,1]==0)
@约束(m,p[5,2]==0)
@约束条件(m,p[5,3]==0)
@约束(m,p[1,1]
#约束2
对于m=1:客户
对于i=1:产品

@约束(m,D[i,m]-sum(z[i,k,m]表示k=1:plant)-sum(y[i,l,m]表示l=1:warehouse)您可能在某个地方发送了一个错误的变量,而不是您的模型
m
。代码中的错误具体发生在哪里?
validmodel(m::AbstractModel,name)
在发布的代码末尾的约束2处。
#constrainst 2
for m=1:customer
    for i=1:product 
@constraint(m, D[i,m]-sum(z[i,k,m] for k=1:plant)-sum(y[i,l,m] for l=1:warehouse) <=0 )  #cant get
    end
end