作业题返回矩阵中权重最小的路径元组但是代码给了我一个错误:undefarerror st未定义?
我试过在没有for循环的情况下运行这个程序,并且只返回s,这是有效的。

function backtrack(pathweights)
    s = size(pathweights)[1]
    bestpath = []
    a = argmin(pathweights[:, s])
    push!(bestpath, (size(pathweights)[1]-1,a))

    for j = size(pathweights)[1]:-1:1
        b = argmin(pathweights[:, j])
        for i = 1: size(pathweights)
            if isdefined[pathweights[b+1,j-1]] &&
            isdefined[pathweights[b-1,j-1]]
                push!(bestpath, (min(pathweights[b, j-1],
                pathweights[b-1,j-1], pathweights[b+1, j-1]), j))
            else if isempty[pathweights[a+1,j-1]]
                push!(bestpath, (min(pathweights[b-1, j-
                1],pathweights[b, j-1]), j))
            else
                push!(bestpath, (min(pathweights[b, j-1],
                pathweights[b+1,j-1]), j))
            end
        end
    end
    return bestpath
 end

输入:
路径权重=[36 8 6 3
10 9 11 10 6
13 19 13 7 12年
23 17 10 8 9
23 11 15 11 17]
预期产量:
最佳路径=[(5,2),(4,3),(3,4),(2,5),(1,5)]

最佳答案

看起来您正在使用juno并试图计算包含错误的文件。
此错误被报告为here并由此修复,因此请更新到atom.jl 0.11.1(使用using Pkg; Pkg.update()并重试。

10-06 05:05