Вопрос к домашнему заданию, чтобы вернуть наборы путей с наименьшим весом в матрице. Однако код дает мне ошибку как: UndefVarError 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
Iinput: pathweights = [3 6 8 6 3 10 9 11 10 6 13 19 13 7 12 23 17 10 8 9 23 11 15 11 17] Ожидаемый результат: bestpath = [(5,2), (4,3), (3,4), (2,5), (1,5)]