Crates.io | path_finder |
lib.rs | path_finder |
version | 0.1.0 |
source | src |
created_at | 2023-01-06 23:41:32.408295 |
updated_at | 2023-01-06 23:41:32.408295 |
description | Find non-looping paths in a graph |
homepage | |
repository | |
max_upload_size | |
id | 752674 |
size | 11,390 |
Find non-looping paths in a graph
cargo build --release
The graph is represented as a symmetrical square matrix with zeros for unconnected vertices and ones for connected vertices.
For example, the following graph
Is going to be represented with the following matrix: $$\LARGE{\begin{bmatrix} 0 & 1 & 0 \\ 1 & 0 & 1 \\ 0 & 1 & 0 \end{bmatrix}}$$
Note that the diagonal of the matrix is filled with zeros because a vertex doesn't connect to itself.
The first input of the program is the start vertex, the second is the end vertex and the third is the matrix.
The output are all the paths from the start to the end vertex that don't repeat any vertex.
For example, for discovering the paths from vertex $0$ to vertex $2$ you would execute:
./target/release/path_finder
0 2
0 1 0
1 0 1
0 1 0
[0, 1, 2]
Just to you have an idea, this is a benchmark:
time echo "0 9
0 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
1 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 0" | ./target/release/path_finder
[0, 1, 9]
[0, 1, 2, 9]
[0, 1, 2, 8, 9]
...
[0, 8, 7, 9]
[0, 8, 9]
[0, 9]
real 0m1.054s
user 0m0.143s
sys 0m0.186s