JuMP 变量声明:MethodError
JuMP variable declaration: MethodError
我正在关注 JuMP 上的 quickstart guide。
我的julia版本是0.7,代码是这样的:
using JuMP
m = Model()
l = zeros(10)
u = ones(10)
#@variable(m, x)
#@variable(m, 0 <= x[1:10] <= 1)
@variable(m, l<=x[1:10]<=u)
前两个变量宏(注释掉)工作正常,但最后一个产生错误。
MethodError: no method matching constructvariable!(::Model, ::getfield(JuMP, Symbol("#_error#107")){Tuple{Symbol,Expr}}, ::Array{Float64,1}, ::Array{Float64,1}, ::Symbol, ::String, ::Float64)
Closest candidates are:
constructvariable!(::Model, ::Function, !Matched::Number, !Matched::Number, ::Symbol, ::AbstractString, ::Number; extra_kwargs...) at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:968
constructvariable!(::Model, ::Function, !Matched::Number, !Matched::Number, ::Symbol, !Matched::Number, !Matched::Array{T,1} where T, !Matched::Array{Float64,1}, !Matched::AbstractString, !Matched::Number; extra_kwargs...) at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:961
Stacktrace:
[1] top-level scope at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:1259
[2] top-level scope at In[18]:7
如何为向量值变量中的每个条目设置不同的界限?
哎呀,这其实很简单:
l = zeros(10)
u = ones(10)
@variable(m, l[idx] <= x[idx = 1:10] <= u[idx])
我正在关注 JuMP 上的 quickstart guide。
我的julia版本是0.7,代码是这样的:
using JuMP
m = Model()
l = zeros(10)
u = ones(10)
#@variable(m, x)
#@variable(m, 0 <= x[1:10] <= 1)
@variable(m, l<=x[1:10]<=u)
前两个变量宏(注释掉)工作正常,但最后一个产生错误。
MethodError: no method matching constructvariable!(::Model, ::getfield(JuMP, Symbol("#_error#107")){Tuple{Symbol,Expr}}, ::Array{Float64,1}, ::Array{Float64,1}, ::Symbol, ::String, ::Float64)
Closest candidates are:
constructvariable!(::Model, ::Function, !Matched::Number, !Matched::Number, ::Symbol, ::AbstractString, ::Number; extra_kwargs...) at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:968
constructvariable!(::Model, ::Function, !Matched::Number, !Matched::Number, ::Symbol, !Matched::Number, !Matched::Array{T,1} where T, !Matched::Array{Float64,1}, !Matched::AbstractString, !Matched::Number; extra_kwargs...) at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:961
Stacktrace:
[1] top-level scope at /home/lhk/.julia/packages/JuMP/Xvn0n/src/macros.jl:1259
[2] top-level scope at In[18]:7
如何为向量值变量中的每个条目设置不同的界限?
哎呀,这其实很简单:
l = zeros(10)
u = ones(10)
@variable(m, l[idx] <= x[idx = 1:10] <= u[idx])