diff options
Diffstat (limited to 'AufgabeFFP4.hs')
| -rw-r--r-- | AufgabeFFP4.hs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/AufgabeFFP4.hs b/AufgabeFFP4.hs index 8e7cbf1..1521a5d 100644 --- a/AufgabeFFP4.hs +++ b/AufgabeFFP4.hs | |||
| @@ -2,6 +2,7 @@ module AufgabeFFP4 | |||
| 2 | where | 2 | where |
| 3 | 3 | ||
| 4 | import List | 4 | import List |
| 5 | import Data.Array | ||
| 5 | 6 | ||
| 6 | type Weight = Int -- Gewicht | 7 | type Weight = Int -- Gewicht |
| 7 | type Value = Int -- Wert | 8 | type Value = Int -- Wert |
| @@ -91,7 +92,27 @@ knapsack objects limit = (psol, v) | |||
| 91 | 92 | ||
| 92 | ------------------------------------------------------------------------------- | 93 | ------------------------------------------------------------------------------- |
| 93 | 94 | ||
| 94 | --binomDyn :: (Integer, Integer) -> Integer | 95 | -- see lecture slide #207 ff. |
| 95 | --binomDyn (m, n) = ... | 96 | newtype Table a b = Tbl (Array b a) |
| 96 | -- where ... dynamic compB... bndsB... | 97 | deriving Show |
| 98 | |||
| 99 | newTable :: (Ix b) => [(b, a)] -> Table a b | ||
| 100 | newTable l = Tbl (array (lo, hi) l) | ||
| 101 | where | ||
| 102 | indices = map fst l | ||
| 103 | lo = minimum indices | ||
| 104 | hi = maximum indices | ||
| 105 | |||
| 106 | findTable :: (Ix b) => Table a b -> b -> a | ||
| 107 | findTable (Tbl a) i = a ! i | ||
| 108 | |||
| 109 | updTable :: (Ix b) => (b, a) -> Table a b -> Table a b | ||
| 110 | updTable p@(i, x) (Tbl a) = Tbl (a // [p]) | ||
| 111 | |||
| 112 | dynamic :: (Ix coord) => (Table entry coord -> coord -> entry) -> (coord, coord) -> (Table entry coord) | ||
| 113 | dynamic compute bnds = t | ||
| 114 | where | ||
| 115 | t = newTable (map (\coord -> (coord, compute t coord)) (range bnds)) | ||
| 116 | |||
| 117 | ------------------------------------------------------------------------------- | ||
| 97 | 118 | ||
