advent-0.1.0.0: Advent of Code common library
Copyright(c) Eric Mertens 2018-2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe-Inferred
LanguageHaskell2010

Advent.MaxClique

Description

Implementation of https://en.wikipedia.org/wiki/Bron–Kerbosch_algorithm

The Bron–Kerbosch algorithm is an enumeration algorithm for finding all maximal cliques in an undirected graph.

A clique is a subset of verticies in a graph such that all the verticies are connected by an edge.

A maximal clique is a clique such that no more verticies could be added to it while preserving the clique property.

This example shows the expected output on a simple graph. The example uses an inefficient graph input representation to keep the example simple.

    ┌─┐   ┌─┐
 ┌──│4│───│5│──┐
 │  └─┘   └─┘  │
┌─┐  │     │  ┌─┐
│6│  │     │  │1│
└─┘  │     │  └─┘
    ┌─┐   ┌─┐  │
    │3│───│2│──┘
    └─┘   └─┘
>>> let adjList = [(1,2),(1,5),(2,3),(2,5),(3,4),(4,5),(4,6)]
>>> maxCliques (\x y -> (min x y, max x y) `elem` adjList) [1..6]
[[1,2,5],[2,3],[3,4],[4,5],[4,6]]
Synopsis

Documentation

maxCliques Source #

Arguments

:: (a -> a -> Bool)

test for edge between nodes

-> [a]

all nodes

-> [[a]]

maximal cliques

Find the maximal cliques of a graph.

Self-edges are allowed and are filtered out.

maxCliquesInt Source #

Arguments

:: (Int -> IntSet)

node to adjacent nodes

-> IntSet

all nodes

-> [IntSet]

maximal cliques

Bron-Kerbosh algorithm on graphs labeled with integers. The graph should have no self-edges.