bobluppes / graaf

A general-purpose lightweight C++ graph library
https://bobluppes.github.io/graaf/
MIT License
144 stars 38 forks source link

[ALGO] Graph Isomorphism #87

Closed bobluppes closed 11 months ago

bobluppes commented 1 year ago

Graph Isomorphism

In graph theory, an isomorphism between graphs G and H is a structure-preserving bijection between their vertex sets that also preserves adjacency. If such an isomorphism exists, the graphs are considered isomorphic, denoted as G≃HG≃H. Determining graph isomorphism efficiently is a major open question in computer science, known as the Graph Isomorphism problem.

The proposal is to implement the VF2 algorithm. The VF2 algorithm is a backtracking algorithm that provides a generic way to perform both subgraph and graph isomorphism tests. It is designed to be efficient and can handle both directed and undirected graphs. The algorithm is implemented in a way that allows for attributes to be associated with vertices and edges, and for those attributes to be considered as part of the isomorphism test if needed.

See the wikipedia entry for more details.

Syntax

The algorithm should have the following syntax:

/**
 * @brief Checks if two graphs are isomorphic.
 *
 * This function checks whether two given graphs are isomorphic, meaning
 * they are structurally identical up to vertex and edge relabeling.
 * If the graphs are isomorphic, the function returns an optional containing
 * a mapping from the vertices of the first graph to the vertices of the second graph.
 * If the graphs are not isomorphic, the function returns std::nullopt.
 *
 * @tparam V The vertex type of the graphs.
 * @tparam E The edge type of the graphs.
 * @tparam T The graph type of the graphs (directed or undirected).
 * @param lhs The first graph to compare.
 * @param rhs The second graph to compare.
 * @return An optional containing a mapping from the vertices of lhs to those of rhs if isomorphic; otherwise std::nullopt.
 */
template <
    typename V, typename E, graph_type T
>
std::optional<std::unordered_map<vertex_id_t, vertex_id_t>> check_isomorphism(
    const graph<V, E, T>& lhs,
    const graph<V, E, T>& rhs
);

This should live in the graaf::algorithm namespace under include/graaflib/algorithm/graph_isomorphism.h.

Definition of Done

This issue is done when:

sracha4355 commented 1 year ago

Please assign it to me!

github-actions[bot] commented 1 year ago

Stale issue message

github-actions[bot] commented 11 months ago

Stale issue message