DP 0.1 → 0.1.1
raw patch · 2 files changed
+39/−1 lines, 2 files
Files
- DP.cabal +2/−1
- Data/DP/SolverAPI.hs +37/−0
DP.cabal view
@@ -1,5 +1,5 @@ name: DP-version: 0.1+version: 0.1.1 synopsis: Pragmatic framework for dynamic programming description: This module provides a simple declarative framework for dynamic programming optimization. Users specify a dynamic programming problem as a simple haskell function that looks very similar to @@ -20,6 +20,7 @@ library exposed-modules: Data.DP, Data.DP.Solvers, + Data.DP.SolverAPI, Data.DP.Solvers.BottomUpLazy, Data.DP.Solvers.TopDown, Data.DP.Solvers.BottomUpStrict,
+ Data/DP/SolverAPI.hs view
@@ -0,0 +1,37 @@+{-# LANGUAGE TypeFamilies #-}+module Data.DP.SolverAPI (+ -- * Solvers + solveDP, solveSimpleDP, + -- * Solutions+ DPSolution (..), getSimpleResult, + -- * Custom Solver Creation+ mkSolver) where ++import Data.DP+import Data.DP.Internals as I+import Data.DP.SolverInternal+import Control.Monad.Identity++getSimpleResult :: DPSolution chart ind (Identity r) z -> r +getSimpleResult = runIdentity . getResult ++-- | Apply a solver created with @'mkSolver'@ to a @'DP'@ to compute a @'DPSolution'@. +-- @'solveDP' solver frame dp @ will use @solver@ to compute +-- the result of @dp@. @frame@ is a value defined by solver, usually the final index for top down style solvers+-- and the full ordering for bottom-up solvers. +solveDP :: (SolveDP s) => SolveFn s+solveDP solver dp frame = startSolver return solver dp frame +++-- | Helper function. Identical to @'solveDP'@ but for @'SimpleDP'@. +solveSimpleDP :: (Identity b ~ DCell s, SolveDP s) =>+ s+ -> Frame s+ -> SimpleDP (Ind s) b+ -> DPMonad s (DPSolution (Chart s) (Ind s) (DCell s) (Internal s))+solveSimpleDP a b c = solveDP a b (fromSimple c)++-- | Create a custom solver from one of the interfaces in @'Data.DP.Solvers'@+mkSolver :: strategy monad chart ind cell internal+ -> DPSolver monad strategy chart ind cell internal+mkSolver = DPSolver