Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Returns the cost of a node according to the SearchType currently used
- getCost :: SearchType -> Distance -> Int -> Grid -> [Grid] -> Int
- getCost st d l goal neighbors = let dist = calcDistance d goal (head neighbors) in case st of
- Astar -> dist + l -- A* : h cost + g cost
- Uniform -> l -- Uniform : g cost only
- Greedy -> dist -- Greedy : h cost only
- -- Returns a PQueue containing the next nodes (value + cost)
- getNextNodes :: Grid -> Distance -> SearchType -> Int -> [Grid] -> PQ.MinPQueue Int [Grid]
- getNextNodes goal d st l xss = PQ.fromList $ zip costs neighbors where
- costs = parMap rseq (getCost st d l goal) neighbors
- neighbors = parMap rpar (:xss) (getNeighbors $ head xss)
- -- Runs the search using a given SearchType. The SearchType will be used in nodes cost computation
- -- goal : stage to reach ; xss : path from begining to current node ; os : open set ; cs : close set ; nn : nextNodes function ; n : time complexity ; m : space complexity ; l : xss length
- runSearch :: Grid -> [Grid] -> PQ.MinPQueue Int [Grid] -> S.Set Grid -> NextNodesFunc -> Int -> Int -> Int -> IO ()
- runSearch goal xss os cs nn n m l
- | head xss == goal = putStrLn ("Solved with :\n- Time complexity : " ++ show n ++ "\n- Space complexity : " ++ show m)
- | suc /= PQ.empty = runSearch goal ((minim suc):xss) (PQ.union os $ PQ.deleteMin suc) cs' nn (n+1) size (l+1)
- | suc == PQ.empty && os /= PQ.empty = runSearch goal (tail xss) os cs' nn (n+1) size (l-1)
- | otherwise = putErr NotSolvable where
- suc = PQ.filter (\x -> S.notMember (head x) cs) $ nn l xss
- cs' = S.insert (head xss) cs
- minim x = head . snd $ PQ.findMin x
- size = if PQ.size os > m then PQ.size os else m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement