Floyd Warshall Matrix Calculator

Solve weighted graph matrices with Floyd Warshall. Compare routes, detect negative cycles, and export reports. Clear matrix steps help students verify answers accurately online.

Calculator Input

Use 2 to 12 nodes for readable output.
Separate labels with commas.
Use numbers for weights. Use INF, X, ∞, or blank-style tokens for missing edges.

Formula Used

Initialization: distance[i][j] equals the direct edge weight. Missing edges are INF. The diagonal is usually zero.

Transition: Dk[i][j] = min(Dk-1[i][j], Dk-1[i][k] + Dk-1[k][j])

Negative cycle test: after the algorithm, any D[i][i] < 0 indicates a negative cycle.

Path reconstruction: the next-hop matrix stores the first vertex used on the best route from source to target.

How to Use This Calculator

  1. Enter the number of vertices in your graph.
  2. Add labels, such as A, B, C, and D.
  3. Paste a square adjacency matrix with one row per vertex.
  4. Use INF for missing direct connections.
  5. Select directed or undirected mode.
  6. Choose a source and target to reconstruct one route.
  7. Press the calculate button and review results above the form.
  8. Export the final matrix as CSV or PDF.

Example Data Table

This sample has four vertices and uses INF for missing direct edges.

From / ToABCD
A03INF7
B802INF
C5INF01
D2INFINF0

Understanding Floyd Warshall Matrices

The Floyd Warshall method finds shortest paths between every pair of vertices. It works with directed graphs and weighted matrices. It can also work with undirected graphs when opposite edges are mirrored. The calculator treats INF as no direct route. A zero diagonal means every node reaches itself with no cost.

Why This Calculator Helps

Manual matrix updates are slow. Each intermediate vertex can change many routes. This page compares every route through every possible middle node. It then shows the final distance matrix, next-hop matrix, route summary, and warning messages. It also highlights negative cycles when they appear. A negative cycle can make a shortest path undefined, because the route cost can keep falling.

Input Quality Matters

Use one row for each vertex. Keep the same number of values in every row. Enter numbers for edge costs. Use INF, X, or ∞ for missing edges. Negative weights are allowed. They are useful in many algebraic graph examples. Avoid negative cycles when you need stable shortest paths.

Reading The Results

The final matrix gives the best known cost from each source to each target. INF means the target is unreachable. The next-hop matrix tells which vertex should be visited first. The selected path box expands one route into a readable sequence. The heatmap makes low and high costs easier to compare.

Practical Uses

This method is useful in network routing, logistics, operations research, game maps, and dependency analysis. It is best for dense graphs or small teaching examples. For very large sparse graphs, repeated Dijkstra searches may be faster. Floyd Warshall is still valuable because it is simple, complete, and easy to audit.

Export And Review

CSV export is helpful for spreadsheets. PDF export is useful for reports, homework, and records. Save the results after checking the input units. Review the formula section when explaining your work. Compare the example table with your own matrix before using critical results.

Helpful Checks

Confirm row count before solving. Match labels to columns. Use the same unit for every edge. A route cost means nothing when minutes, miles, and fees are mixed without conversion. This prevents confusing final decisions later.

FAQs

1. What does this calculator solve?

It solves all-pairs shortest paths. It takes a weighted adjacency matrix and returns the lowest path cost between every source and target.

2. Can I use negative weights?

Yes. Negative edge weights are allowed. However, negative cycles make shortest paths unstable, so the calculator warns when one appears.

3. What does INF mean?

INF means there is no direct edge between two vertices. The algorithm may still find an indirect route through other vertices.

4. Is the graph directed?

It is directed by default. Uncheck directed mode when your matrix represents an undirected graph and opposite edges should match.

5. What is a next-hop matrix?

It shows the first vertex to visit when traveling from one vertex to another along the calculated shortest route.

6. Why force a zero diagonal?

A zero diagonal means the cost from a vertex to itself is zero. This is the usual setup for shortest path matrices.

7. Can I export the result?

Yes. Use the CSV button for spreadsheet work. Use the PDF button for printable reports and saved calculation records.

8. When should I use this method?

Use it for small or dense weighted graphs when every pair of shortest paths is needed in one complete matrix.

Related Calculators

Paver Sand Bedding Calculator (depth-based)Paver Edge Restraint Length & Cost CalculatorPaver Sealer Quantity & Cost CalculatorExcavation Hauling Loads Calculator (truck loads)Soil Disposal Fee CalculatorSite Leveling Cost CalculatorCompaction Passes Time & Cost CalculatorPlate Compactor Rental Cost CalculatorGravel Volume Calculator (yards/tons)Gravel Weight Calculator (by material type)

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.