Skip to content

DFS Algorithm(s) #5

Open
Open

Description

@WalternativE

Background

I'm currently looking into possible implementations for the DFS. I'm basing my research on the FGL paper, the original FGL DFS implementation (https://github.com/haskell/fgl/blob/master/Data/Graph/Inductive/Query/DFS.hs) as well as this blog post (http://jelv.is/blog/Generating-Mazes-with-Inductive-Graphs/). The Haskell implementation looks interesting as it makes heavy usage of composability and higher order functions to go from very general implementations to very granular ones (dfs, dff, etc). It's a bit complex though.

Question

Should we go in the direction of the Haskell implementation? They are well described in the paper (and well commented in the source code). Do you have other plans? Where would you place the functions - a lot of them work on general graphs - others are rather specific to undirected/directed graphs (pretty much everything with the u or r prefix). What module/submodule/namespace order would you suggest?

First attempt

I played around with the examples in the aformentioned blog post and translated the given DFS example to F# (still - I think a better way would be to stick to the FGL implementation). What do you think?

let dfs (nodes : 'Vertex list) (graph : Graph<'Vertex, 'Label, 'Edge>) : 'Vertex list =
    let rec dfs (nodes : 'Vertex list) (graph : Graph<'Vertex, 'Label, 'Edge>) : 'Vertex list =
        match nodes, graph with
        | ([], _) -> []
        | (_, g) when Graph.isEmpty g -> []
        | (n::ns, g) ->
            match Graph.tryDecompose n g with
            | (Some c, g') ->
                let neighbours = Undirected.Vertices.neighbours c
                n::(dfs (neighbours @ ns) g')
                // n::(dfs (Undirected.Vertices.neighbours c)::ns g')
            | None, _ -> dfs ns g

    dfs nodes graph

Activity

  1. added this to the Backlog milestone on Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions