An open API service indexing awesome lists of open source software.

https://github.com/tiagocavalcante/path_finder

Find non-looping paths in a graph
https://github.com/tiagocavalcante/path_finder

computer-science graph path-finding

Last synced: 10 months ago
JSON representation

Find non-looping paths in a graph

Awesome Lists containing this project

README

          

# path_finder

Find non-looping paths in a graph

## How to install?

```sh
cargo install path_finder
```

## How to use?

The graph is represented as a symmetrical square matrix with zeros for unconnected vertices and ones for connected vertices.

For example, the following graph

![3-vertex graph](https://user-images.githubusercontent.com/62714153/181908761-53dcf94a-a474-4bfe-b64f-8fe9d01f16c4.png)

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:

```sh
path_finder
0 2
0 1 0
1 0 1
0 1 0
[0, 1, 2]
```

## How fast is it?

Just to you have an idea, this is a benchmark:

```sh
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" | 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
```