-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | grammars for TSP and SHP -- -- Grammars and default implementations for the shortest Hamiltonian path -- and Travelling Salesman problems. @package ShortestPathProblems @version 0.0.0.1 module ShortestPath.SHP.Grammar.MinDist data SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd SigMinDist :: (s_adna -> t_k_0__adnc -> s_adna) -> (s_adna -> s_adna) -> (() -> s_adna) -> (t_s_0__adnd -> s_adna) -> (Stream m_adn9 s_adna -> m_adn9 r_adnb) -> SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd [edge] :: SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd -> (s_adna -> t_k_0__adnc -> s_adna) [fini] :: SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd -> (s_adna -> s_adna) [mpty] :: SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd -> (() -> s_adna) [node] :: SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd -> (t_s_0__adnd -> s_adna) [h] :: SigMinDist m_adn9 s_adna r_adnb t_k_0__adnc t_s_0__adnd -> (Stream m_adn9 s_adna -> m_adn9 r_adnb) gMinDist :: ((~#) * * (Fun (Arg (Stack (TW t1 (i1 -> i1 -> t6 t4))) -> t5)) (t5 -> t5), (~#) * * (Fun (Arg (Stack x) -> t5)) (t2 -> t5), (~#) * * (Fun (Arg ((:!:) (Stack (TW t1 (i1 -> i1 -> t6 t4))) b) -> t5)) (t5 -> t3 -> t5), Apply (Arg (Stack (TW t1 (i1 -> i1 -> t6 t4))) -> t5), Apply (Arg (Stack x) -> t5), Apply (Arg ((:!:) (Stack (TW t1 (i1 -> i1 -> t6 t4))) b) -> t5), Element ((:!:) (Stack (TW t1 (i1 -> i1 -> t6 t4))) b) i1, Element (Stack (TW t1 (i1 -> i1 -> t6 t4))) i, Element (Stack x) i1, MkStream t6 ((:!:) S Epsilon) i1, MkStream t6 ((:!:) (Stack (TW t1 (i1 -> i1 -> t6 t4))) b) i1, MkStream t6 (Stack (TW t1 (i1 -> i1 -> t6 t4))) i, MkStream t6 (Stack x) i1, RuleContext i, RuleContext i1, Build (TW t1 (i1 -> i1 -> t6 t4)), Build x) => SigMinDist t6 t5 t4 t3 t2 -> t1 -> t -> b -> x -> (:.) ((:.) Z (TW t1 (i1 -> i1 -> t6 t4))) (TW t (i -> i -> t6 t4)) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, mL0 ~ mR0, xL0 ~ rL0) => ADP.Fusion.Core.TH.Backtrack.ProductBacktracking (ShortestPath.SHP.Grammar.MinDist.SigMinDist mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.MinDist.SigMinDist mR0 xR0 rR0 t_k_0_0 t_s_0_0) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, GHC.Classes.Ord xL0, GHC.Classes.Ord xR0, mL0 ~ mR0) => ADP.Fusion.Core.TH.Backtrack.ProductCombining (ShortestPath.SHP.Grammar.MinDist.SigMinDist mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.MinDist.SigMinDist mR0 xR0 rR0 t_k_0_0 t_s_0_0) module ShortestPath.SHP.Grammar.EdgeProbIO data SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA SigEdgeProb :: (s_ahfx -> t_k_0__ahfz -> s_ahfx) -> (s_ahfx -> t_k_0__ahfz -> s_ahfx -> s_ahfx) -> (() -> s_ahfx) -> (s_ahfx -> t_s_0__ahfA -> s_ahfx) -> (Stream m_ahfw s_ahfx -> m_ahfw r_ahfy) -> SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA [edge] :: SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA -> (s_ahfx -> t_k_0__ahfz -> s_ahfx) [fini] :: SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA -> (s_ahfx -> t_k_0__ahfz -> s_ahfx -> s_ahfx) [mpty] :: SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA -> (() -> s_ahfx) [node] :: SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA -> (s_ahfx -> t_s_0__ahfA -> s_ahfx) [h] :: SigEdgeProb m_ahfw s_ahfx r_ahfy t_k_0__ahfz t_s_0__ahfA -> (Stream m_ahfw s_ahfx -> m_ahfw r_ahfy) gEdgeProb :: ((~#) * * (Fun (Arg ((:!:) ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) (TW t1 (i -> i -> t7 t5))) -> t6)) (t6 -> t4 -> t6 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) -> t6)) (t6 -> t3 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) -> t6)) (t6 -> t4 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) -> t6)) (t6 -> t3 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b1) -> t6)) (t6 -> t4 -> t6), Apply (Arg ((:!:) ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) (TW t1 (i -> i -> t7 t5))) -> t6), Apply (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) -> t6), Apply (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) -> t6), Apply (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) -> t6), Apply (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b1) -> t6), Element ((:!:) ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) (TW t1 (i -> i -> t7 t5))) i2, Element ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) i1, Element ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) i1, Element ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) i, Element ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b1) i, MkStream t7 ((:!:) S Epsilon) i1, MkStream t7 ((:!:) S Epsilon) i, MkStream t7 ((:!:) ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) (TW t1 (i -> i -> t7 t5))) i2, MkStream t7 ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) i1, MkStream t7 ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b1) i1, MkStream t7 ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) i, MkStream t7 ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b1) i, RuleContext i2, RuleContext i1, RuleContext i, Build (TW t2 (i1 -> i1 -> t7 t5)), Build (TW t1 (i -> i -> t7 t5))) => SigEdgeProb t7 t6 t5 t4 t3 -> t2 -> t1 -> t -> b1 -> b -> (:.) ((:.) ((:.) Z (TW t2 (i1 -> i1 -> t7 t5))) (TW t1 (i -> i -> t7 t5))) (TW t (i2 -> i2 -> t7 t5)) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, mL0 ~ mR0, xL0 ~ rL0) => ADP.Fusion.Core.TH.Backtrack.ProductBacktracking (ShortestPath.SHP.Grammar.EdgeProbIO.SigEdgeProb mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.EdgeProbIO.SigEdgeProb mR0 xR0 rR0 t_k_0_0 t_s_0_0) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, GHC.Classes.Ord xL0, GHC.Classes.Ord xR0, mL0 ~ mR0) => ADP.Fusion.Core.TH.Backtrack.ProductCombining (ShortestPath.SHP.Grammar.EdgeProbIO.SigEdgeProb mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.EdgeProbIO.SigEdgeProb mR0 xR0 rR0 t_k_0_0 t_s_0_0) module ShortestPath.SHP.Grammar.EdgeProb data SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo SigEdgeProb :: (s_ajzl -> t_k_0__ajzn -> s_ajzl) -> (s_ajzl -> t_k_0__ajzn -> s_ajzl -> s_ajzl) -> (() -> s_ajzl) -> (t_s_0__ajzo -> s_ajzl) -> (Stream m_ajzk s_ajzl -> m_ajzk r_ajzm) -> SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo [edge] :: SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo -> (s_ajzl -> t_k_0__ajzn -> s_ajzl) [fini] :: SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo -> (s_ajzl -> t_k_0__ajzn -> s_ajzl -> s_ajzl) [mpty] :: SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo -> (() -> s_ajzl) [node] :: SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo -> (t_s_0__ajzo -> s_ajzl) [h] :: SigEdgeProb m_ajzk s_ajzl r_ajzm t_k_0__ajzn t_s_0__ajzo -> (Stream m_ajzk s_ajzl -> m_ajzk r_ajzm) gEdgeProb :: ((~#) * * (Fun (Arg ((:!:) ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) (TW t2 (i1 -> i1 -> t7 t5))) -> t6)) (t6 -> t4 -> t6 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) -> t6)) (t6 -> t4 -> t6), (~#) * * (Fun (Arg (Stack x) -> t6)) (t3 -> t6), (~#) * * (Fun (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) -> t6)) (t6 -> t4 -> t6), Apply (Arg ((:!:) ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) (TW t2 (i1 -> i1 -> t7 t5))) -> t6), Apply (Arg ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) -> t6), Apply (Arg (Stack x) -> t6), Apply (Arg ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) -> t6), Element ((:!:) ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) (TW t2 (i1 -> i1 -> t7 t5))) i2, Element ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) i1, Element ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) i, Element (Stack x) i1, Element (Stack x) i, MkStream t7 ((:!:) S Epsilon) i1, MkStream t7 ((:!:) S Epsilon) i, MkStream t7 ((:!:) ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) (TW t2 (i1 -> i1 -> t7 t5))) i2, MkStream t7 ((:!:) (Stack (TW t2 (i1 -> i1 -> t7 t5))) b) i1, MkStream t7 ((:!:) (Stack (TW t1 (i -> i -> t7 t5))) b) i, MkStream t7 (Stack x) i1, MkStream t7 (Stack x) i, RuleContext i2, RuleContext i1, RuleContext i, Build (TW t2 (i1 -> i1 -> t7 t5)), Build (TW t1 (i -> i -> t7 t5)), Build x) => SigEdgeProb t7 t6 t5 t4 t3 -> t2 -> t1 -> t -> b -> x -> (:.) ((:.) ((:.) Z (TW t2 (i1 -> i1 -> t7 t5))) (TW t1 (i -> i -> t7 t5))) (TW t (i2 -> i2 -> t7 t5)) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, mL0 ~ mR0, xL0 ~ rL0) => ADP.Fusion.Core.TH.Backtrack.ProductBacktracking (ShortestPath.SHP.Grammar.EdgeProb.SigEdgeProb mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.EdgeProb.SigEdgeProb mR0 xR0 rR0 t_k_0_0 t_s_0_0) instance (GHC.Base.Monad mL0, GHC.Base.Monad mR0, GHC.Classes.Eq xL0, GHC.Classes.Ord xL0, GHC.Classes.Ord xR0, mL0 ~ mR0) => ADP.Fusion.Core.TH.Backtrack.ProductCombining (ShortestPath.SHP.Grammar.EdgeProb.SigEdgeProb mL0 xL0 rL0 t_k_0_0 t_s_0_0) (ShortestPath.SHP.Grammar.EdgeProb.SigEdgeProb mR0 xR0 rR0 t_k_0_0 t_s_0_0) -- | Calculate minimum-distance Hamiltonian Shortest Paths and -- probabilities for starting nodes. -- -- NOTE: We explicitly model starting nodes. For symmetrical distance -- matrices, this reports begin/end probabilities. For asymmetrical -- distance matrices, a second instances with Last instead of -- First boundary should be created to calculate begin/end -- probabilities separately. module ShortestPath.SHP.Edge.MinDist -- | Minimal distance algebra -- -- TODO The two Ints are the indices of the nodes and could be replaced? aMinDist :: Monad m => ScoreMatrix Double -> SigMinDist m Double Double (From :. To) (Int :. To) -- | Maximum edge probability following the probabilities generated from -- the EdgeProb grammar. aMaxEdgeProb :: Monad m => ScoreMatrix (Log Double) -> SigMinDist m (Log Double) (Log Double) (From :. To) (Int :. To) data PathBT BTnode :: !(Int :. To) -> PathBT BTedge :: !(From :. To) -> PathBT -- | This should give the correct order of nodes independent of the -- underlying Set1 First or Set1 Last because the -- (From:.To) system is agnostic over these. aPathBT :: Monad m => ScoreMatrix t -> SigMinDist m [PathBT] [[PathBT]] (From :. To) (Int :. To) -- | This should give the correct order of nodes independent of the -- underlying Set1 First or Set1 Last because the -- (From:.To) system is agnostic over these. aPretty :: Monad m => ScoreMatrix t -> SigMinDist m Text [Text] (From :. To) (Int :. To) -- | Before using aInside the ScoreMatrix needs to be -- scaled appropriately! Due to performance reasons we don't want to do -- this within aInside. aInside :: Monad m => ScoreMatrix (Log Double) -> SigMinDist m (Log Double) (Log Double) (From :. To) (Int :. To) type TS1 x = TwITbl Id Unboxed EmptyOk (BS1 First I) x type U x = TwITbl Id Unboxed EmptyOk (Unit I) x type PF x = TwITbl Id Unboxed EmptyOk (Boundary First I) x type TS1L x = TwITbl Id Unboxed EmptyOk (BS1 Last I) x type UL x = TwITbl Id Unboxed EmptyOk (Unit I) x type PFL x = TwITbl Id Unboxed EmptyOk (Boundary Last I) x type BT1 x b = TwITblBt Unboxed EmptyOk (BS1 First I) x Id Id b type BTU x b = TwITblBt Unboxed EmptyOk (Unit I) x Id Id b type BT1L x b = TwITblBt Unboxed EmptyOk (BS1 Last I) x Id Id b type BTUL x b = TwITblBt Unboxed EmptyOk (Unit I) x Id Id b -- | Run the minimal distance algebra. -- -- This produces one-boundary sets. Meaning that for each boundary we get -- the total distance within the set. forwardMinDist1 :: ScoreMatrix Double -> (Z :. TS1 Double) :. U Double backtrackMinDist1 :: ScoreMatrix Double -> (Z :. TS1 Double) :. U Double -> [Text] pathbtMinDist :: ScoreMatrix Double -> (Z :. TS1 Double) :. U Double -> [[PathBT]] -- | Given the Set1 produced in forwardMinDist1 we can -- now extract the co-optimal paths using the Set1 -> () -- index change. -- -- TODO do we want this one explicitly or make life easy and just extract -- from all forwardMinDist1 paths? runCoOptDist :: ScoreMatrix Double -> (Double, [Text]) -- | Return the minimal distance and provide a list of co-optimal -- backtraces. runMinDist :: ScoreMatrix Double -> (Double, [[PathBT]]) -- | Extract the individual partition scores. boundaryPartFun :: Double -> ScoreMatrix Double -> [(Boundary First I, Log Double)] -- | Run the maximal edge probability grammar. forwardMaxEdgeProbFirst :: ScoreMatrix (Log Double) -> (Z :. TS1 (Log Double)) :. U (Log Double) forwardMaxEdgeProbLast :: ScoreMatrix (Log Double) -> (Z :. TS1L (Log Double)) :. UL (Log Double) pathbtMaxEdgeProbFirst :: ScoreMatrix (Log Double) -> (Z :. TS1 (Log Double)) :. U (Log Double) -> [[PathBT]] pathbtMaxEdgeProbLast :: ScoreMatrix (Log Double) -> (Z :. TS1L (Log Double)) :. UL (Log Double) -> [[PathBT]] -- | Given the Set1 produced in forwardMinDist1 we can -- now extract the co-optimal paths using the Set1 -> () -- index change. -- -- TODO do we want this one explicitly or make life easy and just extract -- from all forwardMinDist1 paths? runMaxEdgeProbFirst :: ScoreMatrix (Log Double) -> (Log Double, [[PathBT]]) runMaxEdgeProbLast :: ScoreMatrix (Log Double) -> (Log Double, [(Boundary Last I, Log Double)], [[PathBT]]) test :: Double -> FilePath -> IO () instance GHC.Show.Show ShortestPath.SHP.Edge.MinDist.PathBT