0
def floydWarshall(self) :
    
    n = len(self._W)
    D = copy.deepcopy(self._W)
    P = copy.deepcopy(self._W)

    for i in range(n) :
        for j in range(n) :
            if i == j or self._W[i][j] == math.inf :
                P[i][j] = None
            else :
                P[i][j] = i

    for k in range(n) :
        for i in range(n) :
            for j in range(n) :
                if D[i][k] + D[k][j] < D[i][j] :
                    D[i][j] = D[i][k] + D[k][j]
                    P[i][j] = P[k][j]
    return D, P

I am trying to implement the floyd warshall algorithm. I am attempting to return the matrix that contains the predecessors of the matrix represented by P and a matrix D that consists of the weights between the shortest paths between vertices. I believe the the problem may be with my predecessor matrix, because it will return none in one case,

4
  • 3
    As far as I can tell there is no way that this function returns None. It always returns a tuple. Commented Apr 15, 2022 at 17:12
  • Ok I suppose I have not isolated my problem properly then. Commented Apr 15, 2022 at 17:14
  • "in one case" in which case? Commented Apr 15, 2022 at 17:17
  • Well I thought it might have had something to do with "P[i][j] = None" since im returning D, P Commented Apr 15, 2022 at 17:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.