1. Introduction
Shortest path problems have been studied in the last few decades to compute the shortest path in graph theory scenarios [
1,
2,
3,
4,
5,
6,
7]. However, this topic continues to be applied and actively researched in recent years [
8,
9], especially in the context of graph theory [
10] and graph visualization [
11,
12,
13]. In parallel, several tools have been presented and studied to compute the shortest path in the graph theory as well as to analyse and visualize the networks, in particular using free or opensource tools [
14,
15].
NetworkX Library (NetworkX Library:
https://networkx.org (accessed on 15 April 2025)) is a Python library that provides a handle for the creation and manipulation of graphs and networks. It is written in Python 3.11, and its source code is opensource. It was created by Aric Hagberg, Dan Schult and Pieter Swart [
16], and over time with the contribution of other software developers. Being supported by some research centres, the first release version was published on 8 January 2020, and the current release version is the 3.4.2 published on 21 October 2024. For graph visualizations, many free and opensource tools have been studied [
12,
13,
17], with NetworkX as one of the most promising options. It provides tools, a programming interface and a development environment for the creation, manipulation and study of the structure, dynamics and functions of complex networks, such as data structures for graphs, digraphs, multigraphs and standard graph algorithms, as well as network structures and analysis measures for complex network problems or representations. The library has been successfully used in many works and projects for graph or network visualization and analysis purposes, such as those presented in [
17,
18,
19,
20].
Actually, the NetworkX library includes algorithms to compute the shortest paths and path lengths between nodes in a graph as undirected and directed graphs. It includes the basic algorithm to compute shortest paths in a graph and shortest path algorithms for weighted and unweighted graphs, as well as for dense graphs [
21]. The first set is oriented to compute all the shortest simple paths in the graph and the advanced set is centred on computing the shortest path lengths from a source to all reachable nodes for unweighted graphs. For the weighted graphs, it provides the implementation of the Dijkstra algorithm [
22,
23], Bellman-Ford path [
24,
25] and Jonhson path [
26]. For dense graphs, the library provides the Floyd–Warshall algorithm [
27,
28] for shortest paths and the A* (“A star”) algorithm [
29] for shortest paths and path lengths. Besides the potentiality of the library in other domains and the code availability for different graph types and methods or algorithms, it presents a limitation of extensions or improvements of the A* (Hart et al. 1968) [
29], such as the Bidirectional A* [
30], IDA* [
31], SMA* [
32], Dynamic A* [
33], D* Lite [
34] and RTAA* [
35], among others.
The objective of this work is centred on the lack of algorithm diversity in the field of shortest path and path finding available within the NetworkX platform. The goal or challenge is to address the limitations of the A* in specific scenarios, such as searching for an optimal path repeatedly or when confronted with memory limitations, as exemplified by the library. In this sense, using the NetworkX code framework, we implemented D* Lite, Bidirectional A*, IDA*, SMA* and RTAA*, which have been submitted to network environment validation and passed the tests. We tested using a general graph scenario with tri-objective scenario parameters (length, cost and toll) to find a shortest path between an origin and a destination. We have performed the benchmarking of the A*, comparing it with the new ones, and compared their performance in terms of cost of the path found, search time, memory used and recalculation time for dynamic algorithms. To foster further research the dataset and the code of the algorithms are available on the GitHub 2.48.1 at:
https://github.com/migcruzz/Testing_NetworkX_Algorithms.git (accessed on 3 June 2025) opensource repository.
The document is structured as follows.
Section 2 presents the literature review on NetworkX usage.
Section 3 presents the foundations of the implemented algorithms, and
Section 4 presents the experimental results and discussion. Finally,
Section 5 presents the conclusions and future work, followed by the references that supported this work.
2. Literature Review
Based on free and opensource tools, several tools have been presented over the last few decades for graph visualization as well as for representing scenarios of shortest path problems. With promising results, the NetworkX library, created by Aric Hagberg, Dan Schult and Pieter Swart [
16], has been explored and improved, especially for network analysis and visualization, as well as for shortest path problems using classic algorithms, as compiled and published in research papers and in published books [
34,
35,
36].
Analysing the literature review of the usage and exploration of NetworkX, the main use is centred on network analysis, such as the works of Abdelhamid et al. (2012) [
37], Pacer (2015) [
38], Gharibi et al. (2018) [
39], Yan et al. (2019) [
40], Boeing, G. (2020) [
17], Bontonou et al. (2021) [
18], Gao et al. (2022) [
19] and Uribe et al. (2023) [
20].
However, besides the main usage and exploration in graph and network analysis as well as in visualization, NetworkX has also been applied and explored in shortest path problems, particularly in both undirected and directed graphs with weighted and unweighted constraints between nodes in the graphs, as well as in scenarios involving dense graphs.
In the context of path search, path planning or route planning, there are several well-known algorithms. Dijkstra’s algorithm [
22,
41] is a method used to find the shortest path from one node to another in a graph that only has positive weights. In 1968, Hart et al. (1968) [
29] presented a study that, with a formal basis for the heuristic determination of minimum cost paths, introduced the A* algorithm. The main difference between Dijkstra’s algorithm and A* is the use of a heuristic estimate function. This function estimates, for any node, the remaining distance to the destination. Dijkstra may be regarded as an instance of A* where the heuristic estimate function is identically zero (function ≡ 0) [
30]. However, as A* has shown limitations when applied to more complex problems, improved variants have emerged to achieve faster registration results and increase efficiency.
Consequently, several studies and extensions have been presented [
21,
31,
32,
41,
42,
43,
44], particularly in terms of performance time and memory usage.
Korf (1985) [
31] and Partha (1989) [
45] are two examples of those who started the research of analysing the memory constraints in heuristic search. Iterative Deepening A-Star (IDA*) was presented by Korf in 1985 and addresses the memory problem by combining depth first search with incrementally increasing f-cost limits and allowing for an optimal search without the need to maintain every node in the memory. Other studies have followed this limitation. Simplified Memory-bounded A* (SMA*) [
32,
46] is a shortest path algorithm that is based on the A* algorithm. The difference between SMA* and A* is that SMA* uses a bounded memory, while A* might need exponential memory. Dynamic A* (D*) [
33,
34] tries to deal with dynamic obstacles by updating edge weights in real time. D* maintains a list of nodes used to propagate information about changes of the cost function during the search of the path. D* Lite [
33] implements the same behaviour of D* using an incremental heuristic search algorithm, i.e., it incrementally repairs solution paths when changes occur, promoting fast replanning. Anytime Repairing A* (ARA*) [
47,
48], by using a flexible time cost, returns a valid solution to a search path problem, even if it is interrupted before it ends, generating a non-optimal solution before progressively optimizing the solution for the search problem. Lifelong Planning A* (LPA*) [
49,
50] adapts the search process to changes in the graph without the need for recomputation. It updates the distance-from-start estimates calculated in the previous search during the current search, correcting only those that have become inconsistent in order to maintain shortest-path optimality. LPA* is able to reduce the number of nodes that need to be analysed by reusing information from previous calculations.
Bidirectional A* [
51,
52,
53] runs two simultaneous heuristics searches: one forward from the initial state to a node
n (goal), and one backward from the goal to the start, stopping when the two meet. Learning Real-time A* (LRTA*) [
35,
54] produces feasible paths any time during its execution and minimum length paths if run to completion. Real-time Adaptive A* (RTAA*) [
55,
56] executes the behaviour of A* with limited lookahead, defining a trade-off between optimality and computational cost.
Several studies have applied A* in different scenarios. Zeng & Church (2009) [
57] explored A* in a scenario of real road networks. Rodríguez Puentes and Lazo-Cortés (2013) [
58] explored shortest path finding problem(s), applying a proposed algorithm alongside Dijkstra’s and A* in a Geographic Information System scenario. Zhaoxing, (2019) [
59] introduced a hybrid approach, A-Star+IDA*, as a simple hybrid search algorithm. Cadieux et al. (2020) [
60] presented a Python algorithm for shortest-path in the context of river networks, exploring the multiple single-source weighted Dijkstra shortest path calculations. Tao et al. (2020) [
61], using the Dijkstra algorithm, presented a study by finding minimum-weight link-disjoint paths with a few common nodes by building an integer linear programming model and designing a fast algorithm by using the techniques of augmenting paths and splitting nodes. Foead et al. (2021) [
42] presented a systematic review of the A* algorithm and proposed the HPA-star algorithm, an extension to the A* with a faster runtime at the cost of not always finding the optimal path. Junshu (2021) [
62] explored Dynamic A* to enhance dynamic path planning for unmanned vehicles used in epidemic prevention and disinfection tasks. Pardede et al. (2022) [
43] presented a similar review but applied the A* and Dijkstra in game development. They also presented the Theta* algorithm, an extension of A*, to game development, designed for any-angle pathfinding, which allows direct line-of-sight between nodes, producing smoother, more realistic paths instead of restricting movement to the grid’s edges in a matrix representation. Anbaroğlu et al. (2022) [
63], using a computationally reproducible approach to Dijkstra’s shortest path algorithm, developed an online education material to enable a researcher or analyst to understand how Dijkstra’s algorithm works. Lee at al. (2023) [
64] explored LRTA* in the context of real-time path planning for controllable UAVs by employing subgoals through goal-conditioned reinforcement learning. Silva et al. (2023) [
65] presented an application study to promote inclusive mobility through a multi-objective approach in a real city scenario involving bi-objective and tri-objective optimization. Schichler (2024) [
66] proposed a cost-effective approach to smooth A* path planning for autonomous vehicles.
Haeupler et al. (2024) [
67] explored Dijkstra and GyeongTaek et al. (2023) [
68] explored LRTA* in the context of real-time path planning for controllable UAVs by employing subgoals through goal-conditioned reinforcement learning using an internal data structure to demonstrate that their proposal guarantees universal optimality for the problem of ordering vertices by distance from the source vertex. Muthuvel et al. (2025) [
44] explored Q-learning algorithms in combination with the Dijkstra and A* algorithms. The hybrid approach can manage complex scenarios and guarantee optimal performance, even in a range of conditions in a road network scenario accounting for variables such as road conditions, length-to-width ratio and traffic conditions.
Another relevant point identified during the literature review is the availability of some algorithm’s implementations in open-source repositories such as GitHub. In our research, we identified the following repositories and Python implementations of A* extensions for path planning using a representation as graphs, namely, REP 1 [
68], with implementations of several A* algorithm extensions, and the pgrouting.org project also provides some implementations of A* and Bidirectional A*. Another project is pymoo.org [
69], which focuses on Multi-objective Optimization in Python.
5. Experiments and Results
5.1. Results of Algorithms Tests
Using the previously defined city connections graph, all the algorithms were executed using the same origin and destination, one at a time and using the same machine resources and graph data. We began by running the already existing and implemented A* algorithm in NetworkX to establish a benchmark to test and compare the results of the developed algorithms.
Figure 3 illustrates the optimal path identified by the A* algorithm (red line) in comparison with the other implemented algorithms.
The following subsections present the results obtained from executing all the developed algorithms, each compared against the A* benchmark to evaluate their real-time performance.
5.1.1. D* Lite Algorithm
Figure 4 presents the optimal path found between Tirana and Helsinki using the D* Lite algorithm, along with the performance metrics compared to the benchmark of the A* algorithm.
By analysing the result of the comparison run, we were able to conclude that the D* Lite is marginally slower than the A* while finding the same optimal path. However, the D* uses significantly more memory compared to A*. These results were somewhat expected since D* is designed for larger graphs with real-time graph changes, not static scenarios like the test case; its additional capabilities do not provide a clear advantage and may introduce overhead.
5.1.2. Bidirectional A* Algorithm
Figure 5 presents the results obtained from execution of the bidirectional A* algorithm, including its metrics.
Bidirectional A* required almost as much time as the A* algorithm. However, the optimal path found was slightly more expensive than the one found by A* and it also used more memory. In the remaining benchmarks, Bidirectional A* very closely resembles the A* capabilities. Since this algorithm is best suited for larger and more complex graphs, the results are consistent with what was expected.
5.1.3. IDA* Algorithm
The results of the execution of the IDA* algorithm, presented in
Figure 6, show that the algorithm was able to find the same cost optimal path as A* while taking marginally more time to compute the result. On the other hand, it used less memory in peak times and even less in terms of average usage. Also, recalculation times were significantly slower as IDA* is not well-suited for graph recalculations but rather to find optimal paths with relatively high speed but consuming less memory.
5.1.4. RTAA* Algorithm
Results and metrics of the execution of the RTAA* algorithm are presented in
Figure 7.
Real Time Adaptative A* required slightly more time to find the path when compared to A* and produced an optimal path with a higher overall cost, while also using more memory. These results are consistent with the algorithm characteristics, since the tests were focused on a static and small graph environment, which goes against the capabilities of the RTAA* algorithm since no real time adaptations were made.
5.1.5. SMA* Algorithm
As shown in
Figure 8, the SMA* algorithm was able to find the same optimal path as A*, but with significantly less execution time and using less memory than A* and even outperforming IDA* in terms of memory usage. Additionally, SMA* demonstrates a good recalculation time compared to both algorithms, being only slightly slower than A* and faster than IDA*, even though the algorithm is not focused on recalculations but rather on optimizing memory use. In terms of amount of memory that can be utilised, the SMA* algorithm imposes a limit, which can be particularly advantageous for devices with limited memory resources.
5.2. Analysis and Discussion
Following the foundations, context and dataset described in previous sections, we conducted a benchmarking of the A* algorithm in comparison with five newly implemented algorithms in the NetworkX library, within tri-objective scenario parameters (distance, cost and toll).
After the various simulations using the different algorithms, we observed that some algorithms have advantages over others depending on the metrics. For example, and according to the graphs and metrics shown in the previous section, with regards to determining the optimal path between an origin and a destination (between Tirana and Helsinki cities), we achieved the following results in terms of algorithm performance, summarised in
Table 1.
From the table and simulation results, and considering the overall metrics of each algorithm, it is noticeable that the A* algorithm and the SMA* algorithm demonstrated a good overall performance, although SMA* showed an overall good performance, demonstrating competitive results in comparison to all the other implemented algorithms. Nevertheless, almost all other algorithms were able to perform equally well, in particular in the metrics related to the characteristics where they were specifically developed to have an advantage, highlighting the implementation quality and robustness of the implemented algorithms.
Regarding the D* Lite and RTAA* algorithms that were developed for handling larger graphs and faster recalculation times on path changes during execution, these algorithms are more complex than the rest of the variants. Considering the small size of the test graph and the absence of path changes during executions, these algorithms were not able to fully leverage their advantages, thus justifying the worse results in certain fields when compared to the A* algorithm benchmark.
The IDA* algorithm is designed to enhance memory utilisation through the implementation of a depth-first search strategy and is relevant in scenarios where a graph contains numerous branches, potentially resulting in devices with insufficient memory to accommodate all branches.
The D*-Lite algorithm has been developed to address the limitations of the A* algorithm when searching for a given path that involves the reuse of parts of a previous path and is relevant in the context of large graphs, where the D*-Lite algorithm has been shown to enhance performance.
The SMA* algorithm imposes a limit on the amount of memory that can be utilised, which renders it particularly advantageous for devices with limited memory resources. Bidirectional A* aims to reduce the time taken to search for a given path by searching in both directions, whereas A* only searches from the source. The RTAA* aims to determine a given path faster than A*, and although it is not the optimal solution it returns a result according to certain limits imposed by its parameters, such as the search depth of a given node.
Despite the extensive utilisation of the A* algorithm and its notable efficacy in identifying optimal paths, its performance is suboptimal in specific scenarios, such as when confronted with memory constraints and dynamic environments. For instance, A* can become less efficient on large graphs with thousands of nodes because it needs to store and manage cost values and search paths for many nodes. This can lead to increased memory consumption and longer processing times, depending on the data structures used.
With this simulation in a specific context, we tried to demonstrate that the A* and the developed extensions address the challenges of solving shortest path problems. The integration of new algorithms into NetworkX has the objective of allowing use of the library in a more broader range of problems, namely when confronted with memory constraints and dynamic environments.
It is important to note that the scope of this work is centred on integrating and testing already defined algorithms, specifically D* Lite, Bidirectional A*, IDA*, SMA* and RTAA*, within the NetworkX library. Also, regarding the specific context of the dataset used in the simulations that allowed us to test the efficiency of the A* extensions in a tri-objective parameter scenario.
It is worth mentioning that the objective of this work was not to create new algorithms but to enhance the NetworkX library with implementations of known algorithms, thereby supporting future research and development in graph-based pathfinding and optimisation in complex, real-world scenarios.
6. Conclusions and Future Work
This paper presents a set of implementations of algorithms that improve the A* algorithm, including IDA*, D* Lite, SMA*, Bidirectional A* and RTA*, that have been integrated in the Python library NetworkX. By reviewing and validating the usage of these A* algorithm extensions and the implementations in Python within the NetworkX framework, the implementations have been submitted to the network environment validation and passed the tests. Benchmarking was also preformed using a tri-objective scenario (length, cost and toll in a road network), in order to compare A* with the implemented extensions and assess their efficiency.
We concluded that each algorithm developed had its own approach of finding the optimal path, which showed their respective advantages and disadvantages. Considering the objectives and functionalities of each algorithm, we can conclude that the A* and SMA* algorithms demonstrated the best overall general performance, being competitive in comparison to all the other algorithms implemented. Nevertheless, all algorithms were able to find good solutions for the test case, and some implementations were able to perform better or equally as good as the A* algorithm in specific metrics, highlighting the implementation quality and robustness of the implemented algorithms. In particular, the D* Lite and Real Time Adaptative A* (RTAA*) algorithms, which were developed for handling larger graphs and faster recalculation times on path changes during execution, are more complex than the other implementations. Considering the relatively small dimension of the test graph and absence of path changes during executions, these algorithms were not able to fully demonstrate their advantage, which explains their lower performance in some metrics when compared to the A* algorithm benchmark.
Furthermore, NetworkX is a Python library direcly targeted for graphs with small to medium dimensions, and the Python programming language is based on a more developer-friendly and readable syntax, which makes it slower than other languages and does not allow for micro-optimisations such as, for example, the C++ language. These factors limited the ability of more advanced algorithms like the D* Lite and RTAA* algorithms to reflect their full performance and key advantages.
All the implementations have been submitted to network environment validation, having successfully passed the tests. The source code of the algorithms is available on the GitHub opensource repository in order to foster future research and development in graph-based pathfinding and optimisation in complex, real-world scenarios.
Future directions for this research may include incorporating other A* extension algorithms, such as Lifelong Planning A* (LPA*), Anytime D* and Learning Real-time A* (LRTA*). It will also be important to test the algorithms in larger and more complex benchmarking datasets to assess their performance in different types of graph topologies and domain-specific constraints.