Skip to content

Commit 3dae324

Browse files
Merge pull request #6 from devonhollowood/interface-update
Interface update
2 parents 4130ff2 + 1656e14 commit 3dae324

File tree

5 files changed

+303
-171
lines changed

5 files changed

+303
-171
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [0.2.0] - 2017-05-13
8+
### Changed
9+
- BREAKING CHANGE: Simplified return type of `dijkstra` and `aStar`.
10+
- This should make these functions more ergonomic.
11+
- Introduced new `incrementalCosts` function to compensate.
12+
- BREAKING CHANGE: Replaced searches' `prunes` arguments with `pruning` combinator.
13+
- BREAKING CHANGE: Split searches' `next` arguments into multiple arguments for `dijkstra` and `aStar`.
14+
- This should make these functions more ergonomic.
15+
- `next` arguments now only require a way of generating `Foldable`s, instead of lists specifically.
16+
17+
## 0.1.0 - 2017-03-07
18+
19+
- Initial release
20+
21+
[0.2.0]: https://github.com/devonhollowood/search-algorithms/compare/v0.1.0...v0.2.0

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@ Haskell library containing common graph search algorithms
33

44
[![Build Status](https://travis-ci.org/devonhollowood/search-algorithms.svg?branch=master)](https://travis-ci.org/devonhollowood/search-algorithms)
55

6-
Lots of problems can be modeled as graphs, but oftentimes one doesn't want to use an explicit graph structure to represent the problem. Maybe the graph would be too big (or is infinite), maybe making an explicit graph is unwieldy for the problem at hand, or maybe one just wants to generalize over graph implementations. That's where this library comes in: this is a collection of generalized search algorithms, so that one doesn't have to make the graphs explicit. In general, this means that one provides each search function with a function to generate neighboring states, a list of predicates which tell whether a "dead end" has been reached, a predicate which tells when the search is complete, and an initial state to start from. The result is a path from the initial state to a "solved" state, or `Nothing` if no such path is possible.
6+
Lots of problems can be modeled as graphs, but oftentimes one doesn't want to use an explicit graph structure to represent the problem. Maybe the graph would be too big (or is infinite), maybe making an explicit graph is unwieldy for the problem at hand, or maybe one just wants to generalize over graph implementations. That's where this library comes in: this is a collection of generalized search algorithms, so that one doesn't have to make the graphs explicit. In general, this means that one provides each search function with a function to generate neighboring states, possibly some functions to generate additional information for the search, a predicate which tells when the search is complete, and an initial state to start from. The result is a path from the initial state to a "solved" state, or `Nothing` if no such path is possible.
77

88
## Documentation
99
Documentation is hosted on [Hackage](http://hackage.haskell.org/package/search-algorithms).
1010

11+
## Acknowledgements
12+
This library shares a similar functionality with the [astar](http://hackage.haskell.org/package/astar) library (which I was unaware of when I released the first version of this library). `astar`'s interface has since influenced the development of this library's interface, and this library owes a debt of gratitude to `astar` for that reason.
13+
14+
1115
## Examples
1216
### Change-making problem
1317
```haskell
1418
import Algorithm.Search (bfs)
1519

16-
countChange target = bfs add_one_coin [(> target)] (== target) 0
20+
countChange target = bfs (add_one_coin `pruning` (> target)) (== target) 0
1721
where
1822
add_one_coin amt = map (+ amt) coins
1923
coins = [1, 5, 10, 25]
@@ -36,7 +40,7 @@ graph = Map.fromList [
3640
]
3741

3842
-- Run dfs on the graph:
39-
-- >>> dfs (graph Map.!) [] (== 4) 1
43+
-- >>> dfs (graph Map.!) (== 4) 1
4044
-- Just [3,4]
4145
```
4246

@@ -55,14 +59,14 @@ taxicabDistance (x1, y1) (x2, y2) = abs (x2 - x1) + abs (y2 - y1)
5559

5660
findPath :: (Int, Int) -> (Int, Int) -> Maybe (Int, [(Int, (Int, Int))])
5761
findPath start end =
58-
let next =
59-
map (\pt -> (1, taxicabDistance pt end, pt))
60-
. taxicabNeighbors
61-
in aStar next [isWall] (== end) start
62+
let next = taxicabNeighbors
63+
cost = taxicabDistance
64+
remaining = (taxicabDistance end)
65+
in aStar (next `pruning` isWall) cost remaining (== end) start
6266

6367
-- findPath p1 p2 finds a path between p1 and p2, avoiding the wall
6468
-- >>> findPath (0, 0) (2, 0)
65-
-- Just (6,[(1,(0,1)),(1,(0,2)),(1,(1,2)),(1,(2,2)),(1,(2,1)),(1,(2,0))])
69+
-- Just (6,[(0,1),(0,2),(1,2),(2,2),(2,1),(2,0)])
6670
--
6771
-- This correctly goes up and around the wall
6872
```

search-algorithms.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ library
1919
hs-source-dirs: src
2020
exposed-modules: Algorithm.Search
2121
build-depends: base >= 4.7 && < 5
22-
, containers >= 0.5
22+
, containers >= 0.5 && < 0.6
2323
ghc-options: -Wall
2424
default-language: Haskell2010
2525

0 commit comments

Comments
 (0)