Search code examples
juliaprojectbellman-ford

Is there a basic implementation of bellman ford's algorithm in julia?


I'm a first year student who's learning Julia as a first programming language. I have a project about bellman ford's algorithm but it seems every code is a bit more advanced than I can currently understand. Is there a basic code like Dfs or Bfs for this that a starter could understand, if u have, do share.


Solution

  • This is implemented in LightGraphs

    using LightGraphs
    g  = erdos_renyi(20, 100, seed=1)
    bf_state = bellman_ford_shortest_paths(g, 1)
    

    And now we can display all paths found in the graph:

    julia> enumerate_paths(bf_state)
    20-element Vector{Vector{Int64}}:
     []
     [1, 4, 2]
     [1, 3]
     [1, 4]
     [1, 5]
     [1, 11, 6]
     [1, 7]
     [1, 3, 8]
     [1, 3, 9]
     [1, 7, 10]
     [1, 11]
     [1, 12]
     [1, 3, 13]
     [1, 3, 14]
     [1, 15]
     [1, 4, 16]
     [1, 17]
     [1, 3, 18]
     [1, 19]
     [1, 5, 20]