advent2021-0.1.0.0: Advent of Code 2021 Solutions
Copyright(c) Eric Mertens 2019-2021
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Advent.Search

Description

These implementations provide a lazily-generated list of visited states with the order defined by the search strategy.

Synopsis

Documentation

dfs :: Ord a => (a -> [a]) -> a -> [a] Source #

Shortcut for dfsOn id

dfsOn Source #

Arguments

:: Ord r 
=> (a -> r)

state characterization

-> (a -> [a])

successors function

-> a

initial state

-> [a]

visited states in depth-first order

Depth-first search.

Generates the list of unique visited states from a given starting state. States are unique up to the characterizing function.

bfs :: Ord a => (a -> [a]) -> a -> [a] Source #

Shortcut for bfsOn id

bfsOn Source #

Arguments

:: Ord r 
=> (a -> r)

representative function

-> (a -> [a])

successor state generator

-> a

initial state

-> [a]

reachable states

Enumerate the reachable states in breadth-first order given a successor state function and initial state.

States are compared for equality using the representative function. If the representatives are equal the state is considered already visited.

bfsOnN Source #

Arguments

:: Ord r 
=> (a -> r)

representative function

-> (a -> [a])

successor state generator

-> [a]

initial states

-> [a]

reachable states

Generalization of bfsOn allowing multiple initial states to be considered.

bfsOnInt :: (a -> Int) -> (a -> [a]) -> a -> [a] Source #

astar :: Ord a => (a -> [AStep a]) -> a -> [(a, Int)] Source #

Shortcut for astarOn id

astarOn Source #

Arguments

:: Ord b 
=> (a -> b)

state characterization

-> (a -> [AStep a])

step function (new state, step cost, distance heuristic)

-> a

starting state

-> [(a, Int)]

list of states visited

A* graph search producing a list of reached states and the minimum cost of reaching that state.

Returned states will be unique up to the characterization function. This allows extra information of a node to be ignored for the purposes of the search. For example, a node might remember the path used to reach it while for the search the particular path taken might not matter.

data WithCost a Source #

Constructors

WC !Int a 

data AStep a Source #

A step in the A* graph search annotated with its cost and an estimate of the distance remaining to the goal. The estimate must be an underapproximation to ensure the search finds the optimal solution

Constructors

AStep 

Fields

Instances

Instances details
Show a => Show (AStep a) Source # 
Instance details

Defined in Advent.Search

Methods

showsPrec :: Int -> AStep a -> ShowS #

show :: AStep a -> String #

showList :: [AStep a] -> ShowS #