我写了以下代码:
using JuMP
m = Model()
const A =
[ :a0 ,
:a1 ,
:a2 ]
const T = [1:5]
const U =
[
:a0 => [9 9 9 9 999],
:a1 => [11 11 11 11 11],
:a2 => [1 1 1 1 1]
]
@defVar(m, x[A,T], Bin)
@setObjective(m, Max, sum{sum{x[i,j] * U[i,j], i=A}, j=T} )
print(m)
status = solve(m)
println("Objective value: ", getObjectiveValue(m))
println("x = ", getValue(x))
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到以下错误
ERROR: `*` has no method matching *(::Variable)
in anonymous at …
Run Code Online (Sandbox Code Playgroud) 朱莉娅有这样的功能吗?
拼命试图从MATLAB迁移到Julia,但仍然发现自己依赖它...
我想知道在 Julia 中严格定义列向量的简单方法,例如,我想要一个 3 行列向量B
:
julia> columnVectorB
3×1 Array{Float64,2}:
1.0
2.0
3.0
Run Code Online (Sandbox Code Playgroud)
虽然我认为正常的方法是:
julia> columnVectorB = [1.; 2.; 3.]
julia> columnVectorB
3-element Array{Float64,1}:
1.0
2.0
3.0
Run Code Online (Sandbox Code Playgroud)
我必须这样做的原因是,如果在 JuMP 中使用矩阵操作时以正常方式定义列向量,则会出现烦人的问题。问题之一是:
julia> using JuMP
julia> using GLPKMathProgInterface
julia> n = 1
julia> model_mas = Model(solver = GLPKSolverLP())
julia> @variable(model, vec_y[1: n] >= 0, Int)
julia> vec_y
1-element Array{Variable,1}:
vec_y[1]
Run Code Online (Sandbox Code Playgroud)
该n
指示vec_y
可以是n个变量的列向量。它也是列数B
,所以B
实际上是一个矩阵。当 时n > 1
,没有问题。当n = 1
,B
成为列向量。那么,就会出现一个问题:
julia> …
Run Code Online (Sandbox Code Playgroud) 我正在研究线性优化问题.我循环遍历集来添加约束并定义我的变量.这是我到目前为止的工作代码:
using JuMP
m = Model()
si=[12 23 1 3309 5]
sj=[1,2,3]
c= [3 5 2;
4 3 5;
4 5 3;
5 4 3;
3 5 4]
b= [80;
75;
80;
120;
60]
# x_ij >= 0 ? i = 1,...,5, j = 1,...,3
n = length(si)
p = length(sj)
@defVar(m, x[i=1:n,j=1:p] >= 0)
@setObjective(m,Min,sum{c[i,j]*x[i,j],i=1:n,j=1:p})
for j=1:p
@addConstraint(m, sum{x[i,j],i=1:n} <= 480)
end
for i=1:n
@addConstraint(m, sum{x[i,j],j=1:p} >= b[i])
end
endstatus=solve(m)
Run Code Online (Sandbox Code Playgroud)
我需要添加另一个set来替换set,sj
但是这个set包含字符串而不是整数值.
set_P = [ IMA_1ABC IMA_23 IMA_4AB …
Run Code Online (Sandbox Code Playgroud) 为了解决我的代码中的 tsp,我需要使用 LKH 包。但我无法将包添加到 0.6.4.1 版本的 Julia 中。不幸的是我的所有代码都在这个版本中。如果你不介意的话可以帮我一下吗?非常感谢。以下链接用于添加 LKH 包,但它在 Julia 之前的版本中不起作用。 https://juliapackages.com/p/lkh
这应该很简单,但是我花了将近 3 天的时间尝试在 JuMP 中定义一个集合。然后,我需要为属于集合 O 的每一对 (i', i) 设置变量 y。
O={(i,j): t[j] - t[i] + 30 < d[i,j]; i in D, j in K, i !=j }
y[i,j]=0, for each (i,j) in O
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?