I want to reconstruct the path from source to destination vertex in this graph problem.
How can I store the path, and how can I retrieve it after I have found the minimal cost from s to d?
Please help me to find a simple answer?
For example at the point,
adjmat[i][j] = Math.min(adjMat[i][j],adjMat[i][k]+adjMat[k][j]);
I need to add a path and I need to retrieve it.
The Wikipedia article about the Floyd-Warshall algorithm provides an explanation and pseudocode for your problem.
Use optimal matrix with Floyd-Warshall Algorithm to reconstruct path. It construct path simulatneously.
Refer to Introduction to graph theory- by Narsingh Deo for actual algorithm
Related
I'm using igraph in academic research and I need to provide a proper citation for the algorithm used in the components() command. This algorithm returns the connected components of the graph. The command in question is documented here. It's part of the R/CRAN igraph library.
I think the algorithm used is the one below, which seems to be the canonical workhourse algoirthm cited on the Wikipedia page for connected components.
Hopcroft, J.; Tarjan, R. (1973), "Algorithm 447: efficient algorithms for graph manipulation", Communications of the ACM, 16 (6): 372–378, doi:10.1145/362248.362272
Does anyone know what algorithm is used?
It should be noticed that, igraph in R is actually written in c/c++. If you want to dig into the the details about how components is implemented, you should trace back to its c or c++ source code.
Here is a link to the source code for components
https://github.com/igraph/igraph/blob/f9b6ace881c3c0ba46956f6665043e43b95fa196/src/components.c
However, it seems the algorithm applied is not mentioned in the source code. I guess you can reach the author by email and ask for help.
I'm trying to write a program to find the shortest path in a 3D maze using recursion.
I am able to write the code that finds a random path through the maze but I'm wondering how I can modify my code in order to find the shortest path.
Please note that I want to keep the recursive approach.
Can someone suggest a solution?
Here is a sample 2D maze:
s
XXXX
XX X
XXX
Xe X
One starts from s going to e. X is an obstacle and is the route.
It depends on the algorithm you are implementing. If you want a recursive approach then finding a random path is a good start point (although if the problem is too complex then a bad choice could have huge effects on number of attempts needed for convergence). Afterwards you need to modify the path and for example check whether the new path is shorter than the pervious one; if yes then you continue modifying your parameters in the same direction. Otherwise you have to change your direction.
Exit criterium for the algorithm/ program is normally the difference between the found solution and the ideal solution. So if you know the length of the ideal path (the optimal solution, you need not know the path itself but only its length) in advance then you can define an error margin of 10^-9 for example and once the difference between both solutions is less than this margin your algorithm exits.
In conclusion, this question is a mathematical optimization problem. Optimization is a field which has well-established literature eventhough it is a little bit complex. However if I were you I would search for shortest path algorithms and implement one which is best suited to my application (3D Maze)
I read that with frama-c, we can generate a PDG
which free tools can I use to generate the program dependence graph for c codes
My question is: there is a way for it to generate a SDG (It is a set of PDG, it aims to modelize interprocedural dependences)?.
Anybody could help me or could give me tips about which tools could generate the SDG.
Thank you
I'm not completely sure that it answers your question, but Frama-C's PDG plugin does have inter-procedural information, in the form of nodes for parameters and implicit inputs (globals that are read by the callee), as well as for the returned value and output locations (globals that are written). It uses results of the From plug-in to compute dependencies.
If I understand correctly PDG's API in Db.Pdg, you should be able to obtain all nodes corresponding to a given call with the Db.Pdg.find_simple_stmt_nodes function.
I am recursively building a graph in java using the graphstream library.. however this graph is so huge so that the recursion is very deep and this ends in stackoverflow. Believe me, even an iteration wouldn't solve my problem.. I will just get a runtime error down the road.
My goal is to use a search algorithm such as Disjktra or A* or whatsoever on the graph in the end.
As I dont have the whole graph, I have been looking in the literature for things such as a shortest path algorithm in a partial maps; use of heuristics I couldn't find much.
I would appreciate it if someone could give me some hints (papers, ideas; an implementation would be a jackpot!!!! :-D) I have looked at algorithms such as PHA* or some others..
I know this post is very old... But I solved it back then using a 1990 Algorithm, from Korf, R. E. (1990) "Real-time heuristic search" Can be found here: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.137.1955&rep=rep1&type=pdf
Since i am new to graph, i am not getting algorithm that can can clearly explain how to find articulation point in graph. Please anyone explain? thanx in advance
A simple algorithm:
For each Node N so:
1. Take it away
2. Count the number of connected components. Either by dfs or bfs.
If that's still one, continue with the loop. If it is two, you have found an articulation point. Mark and continue with the loop.
This will run in quadratic time. Not sure whether there is a better algorithm.
Edit: i found some java source code on this site: http://algs4.cs.princeton.edu/41undirected/Biconnected.java.html
Refer to this explanation. I hope you would find it useful.
http://www.geeksforgeeks.org/articulation-points-or-cut-vertices-in-a-graph/