Path Finder Algorithm for Network Graph
Path-Finder is written in Python 3 and no external library needed.
This project based on these 4 class; Container, Node, Route, and main.
Container is a singleton and responsible to create and store Node objects.
Node objects represents unique node on the graph. It stores route objects that visited the node itself. It also evaluates the route with the minimum distance.
Route objects are representing the path that are unique. It contains path data with related node objects.
For path finding algorithm there are a few well-known algorithm. But in this project I aimed to develop a new approach.
This project has 3 main feature:
- Divide and Conquer
- Simplifier
- Infinite Loop Detection
It is the main approach of this path-finder algorithm. When a node has more than one edge, It duplicates the arrived route as much as edge count.
T Route Path (Visited Nodes)
0 Route #1 -
1 Route #1 1
2 Route #1 1, 2
3 Route #1 1, 2, 4
Route #2 1, 2, 3
If a node have more than one arrived route, it removes all routes but the shortest distance. Thus, it prevents the parabolic rise of number of route objects and increases the performance.
As shown in the graph, at the Node 5, Route #1 and Route #3 arrived. Route #1 has been deleted because Route #3 travels a shorter distance. Another important issue in this section is that Route #1 and Route #3 do not have to reach the Node 5 at the same time. Even if they arrive in different time zones, the related Route is deleted.
T Route Path (Visited Nodes)
.
.
4 Route #1 1, 2, 4, 5
Route #2 1, 2, 3, ..
Route #3 1, 2, 3, 5
5 Route #1 (Removed)
Route #2 1, 2, 3, ..
Route #3 1, 2, 3, 5, ..
Avoiding infinite loops was an important part of the project. Therefore, each route object contains a list of nodes it has passed through before. Thus, the Route object is deleted when the same node is visited again.
You can call run.sh
with File Path, Initial Node ID and Target Node ID parameters.
./run.sh basic.txt 1 8
bash run.sh basic.txt 1 8
There are two samples under the files/sample
directory.
Here is the visual of the network graph that sample.txt represent:
bash run.sh file/sample/basic.txt 1 8
26
This project available at eminsafa/Path-Finder