local-search-0.0.2: Control/Search/Local/Navigator.hs
-----------------------------------------------------------------------------
-- |
-- Module : Control.Search.Local.Navigator
-- Copyright : (c) Richard Senington & David Duke 2010
-- License : GPL-style
--
-- Maintainer : Richard Senington <sc06r2s@leeds.ac.uk>
-- Stability : provisional
-- Portability : portable
--
-- The two ways to navigate a tree. The paper reduced all the different local search strategies to transformations
-- composed with a first choice system, so that is the navigator that is expected to be used. However we also
-- provide a manual inspection navigator, that allows for human interaction, by typing the number of the node
-- you wish to move to.
-----------------------------------------------------------------------------
module Control.Search.Local.Navigator (
firstChoice,
manualNavigator
)where
import Control.Search.Local.Tree
import Control.Search.Local.Transformation
import Control.Search.Local.Neighbourhood
firstChoice :: LSTree a->[a]
firstChoice t | (null.treeNodeChildren) t = [treeNodeName t]
| otherwise = treeNodeName t : (firstChoice (head (treeNodeChildren t)))
-- | Types left out of the next two parts because of compilation problems with type inference if included.
manualNavigator t =
do displayLSSpace t
putStr ": "
x<-getLine
if x=="q" then return ()
else do let i = (read x)::Int
manualNavigator (treeNodeChildren t !! i)
displayLSSpace t =
do let nme = treeNodeName t
putStrLn $ "Current Location : "++(show nme)
putStrLn $ " Current Price : " -- ++(show $ priceSolution nme)
putStrLn $ " Neighbourhood"
mapM_ putStrLn $ map (\(x,y)->" "++(show x)++" "++(show.treeNodeName $ y)++" "++(show.priceSolution.treeNodeName $ y)) (zip [0..] $ treeNodeChildren t)