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

An implementation of the Hamiltonian path problem using the Backfish backtracking library.

The Hamiltonian path problem involves finding a path in an undirected or directed graph that visits each vertex exactly once.

Summary

Functions

Returns the initial state of the Hamiltonian path 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 Hamiltonian path 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 :start_node, which is the starting node for the path.

Returns

  • A map representing the initial state, including the graph, the initial path with the starting node, and a set of visited nodes.

Checks if the given state is a goal state.

Parameters

  • state: The current state of the problem, which includes the graph, the path, and the set of visited nodes.

Returns

  • true if the number of visited nodes equals the number of nodes in the graph, false otherwise.

Generates the next possible states from the given state.

Parameters

  • state: The current state of the problem, which includes the graph, the path, and the set of visited nodes.

Returns

  • A list of the next possible states, each including a new path with an additional node visited.