diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Numeric/Chain.hs | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/packages/base/src/Numeric/Chain.hs b/packages/base/src/Numeric/Chain.hs index c6160e9..4c497f0 100644 --- a/packages/base/src/Numeric/Chain.hs +++ b/packages/base/src/Numeric/Chain.hs | |||
@@ -2,7 +2,7 @@ | |||
2 | -- | | 2 | -- | |
3 | -- Module : Numeric.Chain | 3 | -- Module : Numeric.Chain |
4 | -- Copyright : (c) Vivian McPhail 2010 | 4 | -- Copyright : (c) Vivian McPhail 2010 |
5 | -- License : GPL-style | 5 | -- License : BSD3 |
6 | -- | 6 | -- |
7 | -- Maintainer : Vivian McPhail <haskell.vivian.mcphail <at> gmail.com> | 7 | -- Maintainer : Vivian McPhail <haskell.vivian.mcphail <at> gmail.com> |
8 | -- Stability : provisional | 8 | -- Stability : provisional |
@@ -98,21 +98,22 @@ minimum_cost :: (Sizes,Cost,Indexes) -> (Int,Int) -> (Sizes,Cost,Indexes) | |||
98 | minimum_cost sci fu = foldl (smaller_cost fu) sci (fulcrum_order fu) | 98 | minimum_cost sci fu = foldl (smaller_cost fu) sci (fulcrum_order fu) |
99 | 99 | ||
100 | smaller_cost :: (Int,Int) -> (Sizes,Cost,Indexes) -> ((Int,Int),(Int,Int)) -> (Sizes,Cost,Indexes) | 100 | smaller_cost :: (Int,Int) -> (Sizes,Cost,Indexes) -> ((Int,Int),(Int,Int)) -> (Sizes,Cost,Indexes) |
101 | smaller_cost (r,c) (mz,cost,ixes) ix@((lr,lc),(rr,rc)) = let op_cost = fromJust ((cost A.! lr) A.! lc) | 101 | smaller_cost (r,c) (mz,cost,ixes) ix@((lr,lc),(rr,rc)) = |
102 | + fromJust ((cost A.! rr) A.! rc) | 102 | let op_cost = fromJust ((cost A.! lr) A.! lc) |
103 | + fst (mz A.! (lr-lc+1)) | 103 | + fromJust ((cost A.! rr) A.! rc) |
104 | * snd (mz A.! lc) | 104 | + fst (mz A.! (lr-lc+1)) |
105 | * snd (mz A.! rr) | 105 | * snd (mz A.! lc) |
106 | cost' = (cost A.! r) A.! c | 106 | * snd (mz A.! rr) |
107 | in case cost' of | 107 | cost' = (cost A.! r) A.! c |
108 | Nothing -> let cost'' = update cost (r,c) (Just op_cost) | 108 | in case cost' of |
109 | ixes'' = update ixes (r,c) (Just ix) | 109 | Nothing -> let cost'' = update cost (r,c) (Just op_cost) |
110 | in (mz,cost'',ixes'') | 110 | ixes'' = update ixes (r,c) (Just ix) |
111 | Just ct -> if op_cost < ct then | 111 | in (mz,cost'',ixes'') |
112 | let cost'' = update cost (r,c) (Just op_cost) | 112 | Just ct -> if op_cost < ct then |
113 | ixes'' = update ixes (r,c) (Just ix) | 113 | let cost'' = update cost (r,c) (Just op_cost) |
114 | in (mz,cost'',ixes'') | 114 | ixes'' = update ixes (r,c) (Just ix) |
115 | else (mz,cost,ixes) | 115 | in (mz,cost'',ixes'') |
116 | else (mz,cost,ixes) | ||
116 | 117 | ||
117 | 118 | ||
118 | fulcrum_order (r,c) = let fs' = zip (repeat r) [1..(c-1)] | 119 | fulcrum_order (r,c) = let fs' = zip (repeat r) [1..(c-1)] |