Created
July 31, 2011 13:59
-
-
Save jmora/1116811 to your computer and use it in GitHub Desktop.
Heuristic Backtracking - Backtracking that prioritizes branches depending on some heuristic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module HeuristicBacktrac (backtracking) where | |
import List | |
hbacktracking:: | |
(partialSolution -> partialSolution -> Ordering) -- heuristic, A* like | |
-> (partialSolution -> Bool) -- isFinalSolution? | |
-> (partialSolution -> solution) -- convert | |
-> (partialSolution -> [partialSolution]) -- next | |
-> (partialSolution -> Bool) -- isValid? | |
-> [partialSolution] -- Estado inicial | |
-> Maybe solution | |
hbacktracking _ _ _ _ _ [] = Nothing | |
hbacktracking order isSolution convert next isValid (ps:pss) | |
| isSolution ps = Just (convert ps) | |
| otherwise = (hbacktracking order isSolution convert next isValid) | |
(sortBy order ((filter isValid (next ps)) ++ pss)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have some cool pieces of code, specially in haskell, I wrote as an undergraduate. Whenever I find one of them I like to post them here.
I did not test it before posting it, but I guess it works.