了解Julia Lang中的JuMP?

时间:2019-11-16 17:12:51

标签: julia julia-jump

package com.matan;

@SpringBootApplication
class Main

我是Julia语言的新手。我正在使用上面的代码进行练习。但是我遇到了一个我似乎不理解的错误。错误是:

using JuMP, Clp
d = [40 60 75 25] # monthly demand for boats
m = Model(with_optimizer(Clp.Optimizer))

@variables(m, begin
0 <= x[1:4] <= 40 #boats produced with regular labor
y[1:4]>= 0 #boats produced with overtime labor
h[1:5] >= 0 #boats held in inventory
end)
@constraint(m, h[1] == 10)
@constraint(m, flow[i in 1:4], h[i]+x[i]+y[i]==d[i]+h[i+1])     # conservation of boats
@objective(m, Min, 400*sum(x) + 450*sum(y) + 20*sum(h))         # minimize costs

status = optimize!(m)
println("Build ", Array{Int64}(value(x')), " using regular labor")
println("Build ", Array{Int64}(value(x')), " using regular labor")
println("Build ", Array{Int64}(value(y')), " using overtime labor")
println("Inventory: ", Array{Int64}(value(h'))

请帮帮我。谢谢

1 个答案:

答案 0 :(得分:2)

要对向量或数组应用标量函数(如Jump.value),需要使用dot notation for broadcasting。因此,您需要将所有value(...)呼叫替换为value.(...)