Safe Haskell | Safe-Inferred |
---|
A collection of common strategies, built out of the combinators in the other libraries. For examples of their use, see Control.Search.Local.Example.
- iterativeImprover :: Ord s => ExpandT s -> ContraT s -> StreamT s
- firstFoundii :: Ord s => ExpandT s -> StreamT s
- maximalii :: Ord s => ExpandT s -> StreamT s
- minimalii :: Ord s => ExpandT s -> StreamT s
- stochasticii :: Ord s => ([s] -> r -> s) -> [r] -> ExpandT s -> StreamT s
- tabu :: Ord s => ExpandT s -> ExpandT s -> ContraT s -> StreamT s
- standardTabu :: Ord s => Int -> ExpandT s -> ContraT s -> StreamT s
- sa :: (Floating v, Ord v) => (s -> v) -> StreamT s -> [v] -> [v] -> StreamT s
- ga :: ExpandT s -> ContraT s -> StreamT s -> StreamT s
- gaConfig :: Ord s => [Float] -> Int -> [Float] -> [Bool] -> ContraT s -> StreamT s -> StreamT s
Iterative Improvers
iterativeImprover :: Ord s => ExpandT s -> ContraT s -> StreamT sSource
The generic skeleton of iterative improvers. The first parameters is a neighbourhood stream expander, the second is a stream contractor which makes choices from neighbourhoods. All neighbourhoods will be filtered so that the elements can only improve upon the previous solution.
Since the parameters are stream transformers, simple functions must be lifted before they can be used
as parameters. For example a deterministic neighbourhood function df
should be lifted with map
and
to choose the first element from each improving neighbourhood you would use map head
, giving
iterativeImprover (map df) (map head).
This skeleton provides a standard infinite stream of solutions, rather than terminating when a local minima is reached. This provides better safety for composition than the versions suggested in the paper. When the filter results in an empty list, the seed value is wrapped up as a list and returned in its place.
firstFoundii :: Ord s => ExpandT s -> StreamT sSource
First found iterative improvement strategy. Fixes the choice function to map head
.
maximalii :: Ord s => ExpandT s -> StreamT sSource
Maximal iterative improvement strategy. Since we seek the lowest possible value of solutions this
translates to fixing the choice function to map minimum
.
minimalii :: Ord s => ExpandT s -> StreamT sSource
Minimal iterative improvement strategy. Fixes the choice function to map maximum
.
stochasticii :: Ord s => ([s] -> r -> s) -> [r] -> ExpandT s -> StreamT sSource
Stochastic iterative improvement strategy. The choice function is required to make a random choice from the neighbourhood at each step. In order to keep this as general as possible we require a choice function, and a stream of values, expected to be random numbers. The choice function takes one of these random values, and a neighbourhood and returns a single value.
This choice function and stream of random values are then used to create a stochastic decision stream contractor, and the strategy created.
TABU Search
tabu :: Ord s => ExpandT s -> ExpandT s -> ContraT s -> StreamT sSource
A general skeleton for TABU search. The three parameters are
- a stream transformer to create the stream of TABU lists (typically provided by
window
) - a stream transformer to create the stream of neighbourhoods, in the same manner as seen in iterative improver
- a choice transformer to choose a single element from a pruned neighbourhood.
standardTabu :: Ord s => Int -> ExpandT s -> ContraT s -> StreamT sSource
Commonly TABU search does not take a function which makes a TABU list, but rather a size of
TABU list. We provide this less flexible form here, where the first parameter changes from
to being the window size. Implemented in terms of tabu
.
Simulated Annealing
sa :: (Floating v, Ord v) => (s -> v) -> StreamT s -> [v] -> [v] -> StreamT sSource
Simulated Annealing skeleton. This requires a significant number of parameters due to the various stochastic components, temperatures and the need for a numerical valuation of solutions qualities. The parameters are;
- a function to get the numerical value of a candidate solution
- a function to provide a perturbation of a solution, with respect to some external factor, such as a random number, which is what the data type r is expected (though not required) to be.
- a stream of values representing the temperature or cooling strategy
- a stream of stochastic values
- a stream of (stochastic) values for the creation of perturbations
Genetic Algorithms
ga :: ExpandT s -> ContraT s -> StreamT s -> StreamT sSource
Genetic Algorithm skeleton. In it's most general form this has three processes, which make up the parameters;
- conversion of the stream of solutions into a stream of populations
- recombination of elements of each population to give new solutions
- mutation of elements of the stream to create variation
It is expected that each of these processes will be created via the composition of a number of other functions.
gaConfig :: Ord s => [Float] -> Int -> [Float] -> [Bool] -> ContraT s -> StreamT s -> StreamT sSource
The standard genetic algorithm configuration. The parameters are;
- the selection distribution
- the population size
- a stream of random values to parametrise the selection routine
- a stream of boolean values to indicate where to apply mutation
- the recombination stream transformer
- the mutation stream transformer