I'm trying to find a path of least resistance using a matrix c of resistance and a given exogenous vector kOne of the total least resistance from point(n) to point(4) (the destination):
c={{inf, 5, 2, inf},
{inf, inf, 1, inf},
{inf, inf, inf, 2},
{inf, inf, inf, 0}}
KOne={4,3,2,0}
Using this I want to find the variable kTwo[a] by minimizing the following function:
kTwo[[a]] = min{c[[a,b]]+kOne[[b]]} subject to c[[a,b]] does not equal inf.
The point being that it should create a vector of the path of least resistance from the start to destination.
The rough code I've written so far is
n = 1;
kTwo = Range[4];
(*to create a vector for kTwo that I can overwrite in the while function below*)
While[n < 5,
kTwo[[n]] = Minimize[{c[[n, a]] + KOne[[a]], c[[n, a]] < Infinity}, a]; n++];
My big issue is that I get the error "expression a cannot be used as a part specification" and I'm not quite sure how to fix it so I cant really tell what else is wrong with the code. Any help or suggestions with the error or how to tackle the minimization problem would be greatly appreciated as I'm still new to Mathematica.