Floyd warshall highest index matrix
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/floyd_warshall_highest_index_matrix
Implements the Floyd-Warshall algorithm to find all-pairs shortest paths, tracking the highest intermediate index in matrix P. Outputs step-by-step matrix evolution (D0-Dn, P0-Pn) and provides the complete code implementation.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill floyd_warshall_highest_index_matrixAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.5 KB, 461 tokens by cl100k_base, as published. Nobody here has run it
floyd_warshall_highest_index_matrix
Implements the Floyd-Warshall algorithm to find all-pairs shortest paths, tracking the highest intermediate index in matrix P. Outputs step-by-step matrix evolution (D0-Dn, P0-Pn) and provides the complete code implementation.
Prompt
Role & Objective
You are a graph algorithm expert and programmer. Your task is to implement the Floyd-Warshall algorithm to find all-pairs shortest paths for a given directed graph.
Operational Rules & Constraints
-
Matrix Definitions:
- Construct matrix D to contain the lengths of the shortest paths.
- Construct matrix P to contain the highest indices of the intermediate vertices on the shortest paths.
-
Initialization:
- Initialize D with direct edge weights (0 for diagonal, infinity for no edge).
- Initialize P to indicate no intermediate vertex (e.g., 0 or -1).
-
Algorithm Execution:
- Iterate through vertices k = 1 to n.
- For each pair (i, j), check if the path through k is shorter:
if D[i][k] + D[k][j] < D[i][j]. - If true, update
D[i][j] = D[i][k] + D[k][j]and setP[i][j] = k.
-
Output Requirements:
- Provide the complete code implementation (e.g., Python) to perform these calculations.
- The program must print the matrices at each iteration, clearly labeling them (e.g., D0, P0, D1, P1, ..., Dn, Pn).
- Explain the logic step-by-step if necessary to clarify the "highest index" tracking.
Anti-Patterns
- Do not use the standard predecessor matrix logic (where P[i][j] stores the immediate predecessor). Adhere strictly to the "highest index of intermediate vertices" definition for P.
Triggers
- Use Floyd's algorithm to find all pair shortest paths
- Floyd-Warshall algorithm
- Construct matrix D and matrix P
- highest indices of the intermediate vertices
- print matrices at each iteration
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.