View Source Backfish.Examples.GraphColoring (Backfish v0.1.0)

An implementation of the graph coloring problem using the Backfish backtracking library.

The graph coloring problem involves assigning colors to the vertices of a graph such that no two adjacent vertices share the same color. The objective is to use the minimum number of colors.

Summary

Functions

Returns the initial state of the graph coloring problem.

Checks if the given state is a goal state.

Generates the next possible states from the given state.

Functions

Returns the initial state of the graph coloring problem.

Parameters

  • args: A keyword list of arguments. Expects :graph, which is a map representing the graph where keys are nodes and values are lists of adjacent nodes, and :colors, which is the number of colors available (default is 3).

Returns

  • A map representing the initial state, including the graph, the number of colors, and an empty color assignment.

Checks if the given state is a goal state.

Parameters

  • state: The current state of the problem, which includes the graph and the color assignment.

Returns

  • true if all nodes in the graph have been assigned a color, false otherwise.

Generates the next possible states from the given state.

Parameters

  • state: The current state of the problem, which includes the graph, the number of colors, and the color assignment.

Returns

  • A list of the next possible states, each including a new color assignment with one additional node colored.