# Using LightGraphs to find shortest path for eikonal solution

**URL:** <https://discourse.julialang.org/t/using-lightgraphs-to-find-shortest-path-for-eikonal-solution/69324>\
**Category:** General Usage\
**Created:** [October 6, 2021, 6:39pm UTC](https://discourse.julialang.org/t/using-lightgraphs-to-find-shortest-path-for-eikonal-solution/69324 "2021-10-06T18:39:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![apattyn](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@apattyn](https://discourse.julialang.org/u/apattyn)\
**Post date:** [October 6, 2021, 6:39pm UTC](https://discourse.julialang.org/t/using-lightgraphs-to-find-shortest-path-for-eikonal-solution/69324/1 "2021-10-06T18:39:49Z")

</div>

I was using FastMarching.jl to solve the eikonal equation for a given speed image, however the built-in shortestpath(…) function doesn’t give the correct solution - e.g. in a homogeneous speed image the shortest path b/w two points is a straight line, but it gives a bent line.

![eikonal](https://global.discourse-cdn.com/julialang/original/3X/4/2/425ec7d35d6713b3237f2dde80353ad8ab54d20d.png)

Therefore, I was hoping to use the existing algorithms from LightGraphs.jl to find the shortest path. But from what I can see the inputs have to be graph objects. Is there a way to convert the matrix solution I have from FastMarching.jl to a graph object that LightGraphs.jl can understand?

In particular I was wanting to use dijkstra\_shortest\_paths(…) from LightGraphs.jl

---

<div class="post-metadata">

**Author:** ![apattyn](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@apattyn](https://discourse.julialang.org/u/apattyn)\
**Post date:** [October 8, 2021, 7:18pm UTC](https://discourse.julialang.org/t/using-lightgraphs-to-find-shortest-path-for-eikonal-solution/69324/2 "2021-10-08T19:18:19Z")

</div>

Thinking about this a bit more, instead of trying to convert this to a graph object to get it working with LightGraphs.jl, I think I can just use a gradient descent method to find the fastest path. Since I can treat the fastest path problem as a minimization problem, where the gradient of the eikonal will point me in the direction of steepest descent, such that I can just follow the gradient down to the global minimum.
