Variious implementations
authorNeil Smith <neil.git@njae.me.uk>
Wed, 14 Dec 2016 21:57:46 +0000 (21:57 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Wed, 14 Dec 2016 21:57:46 +0000 (21:57 +0000)
.gitignore
README.md
advent11a.prof.old [deleted file]
advent11h.hs [new file with mode: 0644]
advent11p.hs
advent11p.prof.old [new file with mode: 0644]

index 3200a6ee4064084ec36c96dafdfa06ecb06727d8..b1c703b3534ca3f83112110dfda06404b7daa38e 100644 (file)
@@ -36,3 +36,5 @@ cabal.project.local
 # Logs
 *.log
 
+# KDE
+.directory
index a4e1d71cbfeebd5a53a84a186e9f79c7e0ea12b6..5663158d2c8e117d5d580f44233e16e1c86243ec 100644 (file)
--- a/README.md
+++ b/README.md
@@ -13,13 +13,13 @@ $ sudo aptitude install haskell-platform
 ```
 ).
 
-I'm also using some extra libraries (install with 
+I'm also using some extra libraries. Before installing, run `cabal update` then set `library-profiling: True` in `~/.cabal/config` . Then install the packages with  
 ```
 $ cabal install MissingH
-$ cabal install parsec-number
+$ cabal install parsec-numbers
 $ cabal install cryptonite
+$ cabal install pqueue
 ```
-)
 
 Compile the code with
 ```
@@ -31,6 +31,14 @@ then run it as
 advent01
 ```
 
+If you're profiling, compile and run with 
+```
+ghc -O2 --make advent01.hs -prof -auto-all -caf-all -fforce-recomp
+time ./advent01 +RTS -p -hy
+```
+
+and create the profile picture with `h2ps advent01.hp` . 
+
 Build this readme file wth
 ```
 pandoc -s README.md > README.html
diff --git a/advent11a.prof.old b/advent11a.prof.old
deleted file mode 100644 (file)
index 22a9fae..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-       Tue Dec 13 23:13 2016 Time and Allocation Profiling Report  (Final)
-
-          advent11a +RTS -p -hy -RTS
-
-       total time  =       82.25 secs   (82252 ticks @ 1000 us, 1 processor)
-       total alloc = 85,148,814,152 bytes  (excludes profiling overheads)
-
-COST CENTRE           MODULE  %time %alloc
-
-aStar.newAgenda       Main     45.0   93.7
-candidates.nonloops.\ Main     27.8    0.2
-aStar                 Main     14.1    0.0
-==                    Main      4.7    0.0
-canonical             Main      3.8    4.2
-cost                  Main      1.8    0.0
-
-
-                                                                               individual     inherited
-COST CENTRE                          MODULE                  no.     entries  %time %alloc   %time %alloc
-
-MAIN                                 MAIN                     88           0    0.0    0.0   100.0  100.0
- part1                               Main                    178           0    0.0    0.0     0.0    0.0
- CAF:main1                           Main                    172           0    0.0    0.0     0.0    0.0
-  part1                              Main                    177           1    0.0    0.0     0.0    0.0
-  main                               Main                    176           1    0.0    0.0     0.0    0.0
- CAF:main2                           Main                    171           0    0.0    0.0     0.0    0.0
-  part1                              Main                    179           0    0.0    0.0     0.0    0.0
- CAF:main3                           Main                    170           0    0.0    0.0     0.0    0.0
-  part1                              Main                    180           0    0.0    0.0     0.0    0.0
- CAF:main4                           Main                    169           0    0.0    0.0     0.0    0.0
-  part1                              Main                    181           0    0.0    0.0     0.0    0.0
-   trail                             Main                    182           1    0.0    0.0     0.0    0.0
- CAF:main5                           Main                    168           0    0.0    0.0   100.0  100.0
-  part1                              Main                    183           0    0.0    0.0   100.0  100.0
-   aStar                             Main                    185       86615   14.1    0.0   100.0  100.0
-    ==                               Main                    249   472091345    1.4    0.0     1.4    0.0
-    aStar.creached                   Main                    247       86614    0.0    0.0     1.6    1.5
-     canonical                       Main                    248       86614    1.1    1.3     1.6    1.5
-      canonical.pairs                Main                    277       86614    0.0    0.1     0.4    0.1
-       canonical.pairs.\             Main                    279      433070    0.0    0.0     0.3    0.0
-        canonical.floorOf            Main                    280      866140    0.0    0.0     0.3    0.0
-         canonical.floorOf.\         Main                    283     1057262    0.0    0.0     0.1    0.0
-          ==                         Main                    284     2667679    0.1    0.0     0.1    0.0
-         canonical.floorOf.\         Main                    281     1063226    0.0    0.0     0.1    0.0
-          ==                         Main                    282     2096091    0.1    0.0     0.1    0.0
-      canonical.names                Main                    275       86614    0.2    0.1     0.2    0.1
-       canonical.names.\             Main                    278      433070    0.0    0.0     0.0    0.0
-       isGenerator                   Main                    276      866140    0.0    0.0     0.0    0.0
-    aStar.newAgenda                  Main                    191       25950   45.0   93.7    82.8   98.4
-     cost                            Main                    240   255331378    1.8    0.0     1.8    0.0
-     candidates                      Main                    192       25950    0.0    0.0    36.1    4.7
-      candidates.newCandidates       Main                    239       25950    0.0    0.0     0.6    0.6
-       candidates.newCandidates.\    Main                    241       86840    0.0    0.0     0.6    0.6
-        candidates.makeAgendum       Main                    242       86840    0.0    0.0     0.6    0.6
-         canonical                   Main                    251       25949    0.3    0.4     0.5    0.5
-          canonical.pairs            Main                    267       25949    0.0    0.0     0.1    0.0
-           canonical.pairs.\         Main                    269      129745    0.0    0.0     0.1    0.0
-            canonical.floorOf        Main                    270      259490    0.0    0.0     0.1    0.0
-             canonical.floorOf.\     Main                    273      324798    0.0    0.0     0.0    0.0
-              ==                     Main                    274      803862    0.0    0.0     0.0    0.0
-             canonical.floorOf.\     Main                    271      324013    0.0    0.0     0.0    0.0
-              ==                     Main                    272      623333    0.0    0.0     0.0    0.0
-          canonical.names            Main                    265       25949    0.0    0.0     0.0    0.0
-           canonical.names.\         Main                    268      129745    0.0    0.0     0.0    0.0
-           isGenerator               Main                    266      259490    0.0    0.0     0.0    0.0
-         estimateCost                Main                    243       86840    0.1    0.1     0.1    0.1
-          estimateCost.\             Main                    245      347360    0.0    0.0     0.0    0.0
-      candidates.previous            Main                    237       25950    0.0    0.0     0.0    0.0
-       trail                         Main                    238       25950    0.0    0.0     0.0    0.0
-      candidates.nonloops            Main                    235       25950    0.0    0.0    34.4    3.3
-       candidates.nonloops.\         Main                    236      174032   27.8    0.2    34.4    3.3
-        ==                           Main                    252  1106692284    3.2    0.0     3.2    0.0
-        canonical                    Main                    250      174008    2.4    2.6     3.4    3.1
-         canonical.pairs             Main                    256      174002    0.1    0.2     0.7    0.3
-          canonical.pairs.\          Main                    258      870010    0.0    0.0     0.6    0.1
-           canonical.floorOf         Main                    259     1740020    0.1    0.1     0.6    0.1
-            canonical.floorOf.\      Main                    262     2174210    0.1    0.0     0.3    0.0
-             ==                      Main                    263     5379816    0.2    0.0     0.2    0.0
-            canonical.floorOf.\      Main                    260     2174106    0.1    0.0     0.2    0.0
-             ==                      Main                    261     4190294    0.1    0.0     0.1    0.0
-         canonical.names             Main                    254      174002    0.3    0.3     0.3    0.3
-          canonical.names.\          Main                    257      870010    0.0    0.0     0.0    0.0
-          isGenerator                Main                    255     1740020    0.0    0.0     0.0    0.0
-      candidates.candidate           Main                    197       25950    0.0    0.0     0.0    0.0
-       current                       Main                    198       25950    0.0    0.0     0.0    0.0
-      candidates.succs               Main                    193       25950    0.0    0.0     1.0    0.9
-       successors                    Main                    196       25950    0.1    0.1     0.7    0.7
-        updateBuilding               Main                    216      301256    0.0    0.0     0.6    0.5
-         updateBuilding.newFloors    Main                    219      301256    0.1    0.1     0.6    0.5
-          updateBuilding.updateFloor Main                    227      823352    0.4    0.4     0.5    0.4
-           ==                        Main                    246      691667    0.1    0.0     0.1    0.0
-           compare                   Main                    230     1533156    0.1    0.0     0.1    0.0
-        successors.floor             Main                    208       25950    0.0    0.0     0.0    0.0
-        successors.items             Main                    200       25950    0.1    0.1     0.1    0.1
-         successors.items.\          Main                    207      451438    0.0    0.0     0.0    0.0
-        successors.nextFloors        Main                    199       25950    0.0    0.0     0.0    0.0
-       legalSuccessors               Main                    195           0    0.0    0.0     0.3    0.2
-        isLegal                      Main                    217      301256    0.1    0.0     0.2    0.2
-         isLegal.safePair            Main                    234     1450573    0.0    0.0     0.0    0.0
-         isLegal.pairs               Main                    232      263463    0.1    0.2     0.1    0.2
-          isGenerator                Main                    233      564782    0.0    0.0     0.0    0.0
-         isGenerator                 Main                    231      345690    0.0    0.0     0.0    0.0
-         isLegal.floor               Main                    218      301256    0.0    0.0     0.0    0.0
-    aStar.reached                    Main                    187       86615    0.0    0.0     0.0    0.0
-     current                         Main                    188       86615    0.0    0.0     0.0    0.0
-    isGoal                           Main                    186       86615    0.0    0.0     0.0    0.0
-     isGoal.height                   Main                    190       86615    0.0    0.0     0.0    0.0
-   initAgenda                        Main                    184           1    0.0    0.0     0.0    0.0
- CAF:lvl26_r8dc                      Main                    165           0    0.0    0.0     0.0    0.0
-  canonical                          Main                    253           0    0.0    0.0     0.0    0.0
- CAF:building1                       Main                    156           0    0.0    0.0     0.0    0.0
-  building1                          Main                    189           1    0.0    0.0     0.0    0.0
- CAF:main11                          Main                    155           0    0.0    0.0     0.0    0.0
-  building1                          Main                    228           0    0.0    0.0     0.0    0.0
-   compare                           Main                    229           1    0.0    0.0     0.0    0.0
- CAF:main18                          Main                    154           0    0.0    0.0     0.0    0.0
-  building1                          Main                    209           0    0.0    0.0     0.0    0.0
-   compare                           Main                    210          18    0.0    0.0     0.0    0.0
- CAF:legalSuccessors_rNg             Main                    153           0    0.0    0.0     0.0    0.0
-  legalSuccessors                    Main                    194           1    0.0    0.0     0.0    0.0
- CAF:$fOrdBuilding1                  Main                    149           0    0.0    0.0     0.0    0.0
-  estimateCost                       Main                    244           0    0.0    0.0     0.0    0.0
- CAF:main35                          Main                    147           0    0.0    0.0     0.0    0.0
-  building1                          Main                    212           0    0.0    0.0     0.0    0.0
- CAF:main31                          Main                    146           0    0.0    0.0     0.0    0.0
-  building1                          Main                    214           0    0.0    0.0     0.0    0.0
- CAF:main28                          Main                    145           0    0.0    0.0     0.0    0.0
-  building1                          Main                    215           0    0.0    0.0     0.0    0.0
- CAF:main17                          Main                    144           0    0.0    0.0     0.0    0.0
-  building1                          Main                    211           0    0.0    0.0     0.0    0.0
- CAF:main15                          Main                    143           0    0.0    0.0     0.0    0.0
-  building1                          Main                    213           0    0.0    0.0     0.0    0.0
- CAF:lvl2_r8cu                       Main                    137           0    0.0    0.0     0.0    0.0
-  aStar                              Main                    220           0    0.0    0.0     0.0    0.0
-   aStar.newAgenda                   Main                    221           0    0.0    0.0     0.0    0.0
-    candidates                       Main                    222           0    0.0    0.0     0.0    0.0
-     candidates.succs                Main                    223           0    0.0    0.0     0.0    0.0
-      successors                     Main                    224           0    0.0    0.0     0.0    0.0
-       updateBuilding                Main                    225           0    0.0    0.0     0.0    0.0
-        updateBuilding.newFloors     Main                    226           0    0.0    0.0     0.0    0.0
- CAF                                 GHC.IO.Handle.FD        133           0    0.0    0.0     0.0    0.0
- CAF                                 Text.Read.Lex           125           0    0.0    0.0     0.0    0.0
- CAF                                 GHC.Conc.Signal         124           0    0.0    0.0     0.0    0.0
- CAF                                 GHC.IO.Encoding         122           0    0.0    0.0     0.0    0.0
- CAF                                 GHC.IO.Handle.Text      121           0    0.0    0.0     0.0    0.0
- CAF                                 GHC.IO.Encoding.Iconv   102           0    0.0    0.0     0.0    0.0
diff --git a/advent11h.hs b/advent11h.hs
new file mode 100644 (file)
index 0000000..860c765
--- /dev/null
@@ -0,0 +1,164 @@
+import Data.List (subsequences, (\\), sort, sortOn, nub, findIndices)
+import Data.Ord (comparing)
+import Data.Char (isDigit)
+
+data Item = Generator String | Microchip String deriving (Show, Eq)
+type Floor = [Item]
+data Building = Building Int [Floor] deriving (Show, Eq)
+-- data CBuilding = CBuilding Int [(Int, Int)] deriving (Show, Eq)
+data CBuilding = CBuilding Int Integer deriving (Show, Eq)
+data Agendum = Agendum {current :: Building, trail :: [CBuilding], cost :: Int}
+
+instance Ord Item where
+    compare (Generator a) (Generator b) = compare a b
+    compare (Microchip a) (Microchip b) = compare a b
+    compare (Generator _) (Microchip _) = LT
+    compare (Microchip _) (Generator _) = GT
+
+instance Ord Building where
+    compare b1 b2 = comparing estimateCost b1 b2
+
+building1 = Building 0 [
+    (sort [Generator "polonium", Generator "thulium", 
+     Microchip "thulium", Generator "promethium", Generator "ruthenium",
+     Microchip "ruthenium", Generator "cobalt", Microchip "cobalt"]),
+    (sort [Microchip "polonium", Microchip "promethium"]),
+    [],
+    []
+    ]
+
+building0 = Building 0 [
+    (sort [Generator "polonium", Generator "thulium", 
+     Microchip "thulium", Generator "promethium"]),
+    (sort [Microchip "polonium", Microchip "promethium"]),
+    [],
+    []
+    ]
+
+building2 = Building 0 [
+    (sort [Generator "polonium", Generator "thulium", 
+     Microchip "thulium", Generator "promethium", Generator "ruthenium",
+     Microchip "ruthenium", Generator "cobalt", Microchip "cobalt",
+     Generator "elerium", Microchip "elerium",
+     Generator "dilithium", Microchip "dilithium"]),
+    (sort [Microchip "polonium", Microchip "promethium"]),
+    [],
+    []
+    ]
+
+
+buildingTest = Building 0 [
+    sort([Microchip "hydrogen", Microchip "lithium"]),
+    [Generator "hydrogen"],
+    [Generator "lithium"],
+    []]
+
+canonical :: Building -> CBuilding
+-- canonical (Building f floors) = CBuilding f (sort pairs)
+canonical (Building f floors) = CBuilding f (read $ filter (isDigit) $ show $ sort pairs)
+    where names = nub $ map (\(Generator n) -> n) $ filter (isGenerator) $ concat floors
+          floorOf (Generator g) = head (findIndices 
+                                                (\fl -> (Generator g) `elem` fl) 
+                                                floors)
+          floorOf (Microchip g) = head (findIndices 
+                                                (\fl -> (Microchip g) `elem` fl) 
+                                                floors)
+          pairs = foldl (\ps n -> (floorOf (Generator n), floorOf (Microchip n)):ps) [] names
+
+
+
+main :: IO ()
+main = do 
+    part1 
+    part2 
+
+
+part1 :: IO ()
+part1 = print $ length $ trail $ hillClimb (initAgenda building1) []
+-- part1 = print $ length $ trail $
+--             aStar [Agendum {current = building1, trail=[], cost = estimateCost building1}] []
+
+-- part2 :: IO ()
+-- part2 = print $ length $ init $ extractJust $ aStar [[building2]] []
+
+part2 :: IO ()
+part2 = print $ length $ trail $ hillClimb (initAgenda building2) []
+
+initAgenda :: Building -> [Agendum]
+initAgenda b = [Agendum {current = b, trail=[], cost = estimateCost b}]
+
+hillClimb :: [Agendum] -> [CBuilding] -> Agendum
+hillClimb [] _ = Agendum {current=buildingTest, trail=[], cost=0}
+hillClimb (currentAgendum:agenda) closed = 
+    if isGoal reached then currentAgendum
+    else if creached `elem` closed 
+        then hillClimb agenda closed
+        else hillClimb newAgenda (creached:closed) 
+    where 
+        reached = current currentAgendum
+        creached = canonical reached
+        newAgenda = 
+            -- sortBy (\t1 t2 -> (cost t1) `compare` (cost t2)) $ 
+            sortOn (cost) $ 
+            agenda ++ (candidates currentAgendum closed)
+
+
+candidates :: Agendum -> [CBuilding] -> [Agendum]
+candidates agendum closed = newCandidates
+    where
+        candidate = current agendum
+        previous = trail agendum
+        succs = legalSuccessors $ successors candidate
+        -- nonloops = (succs \\ previous) \\ closed
+        excludable = previous ++ closed
+        nonloops = filter (\s -> not $ (canonical s) `elem` excludable) succs
+        newCandidates = map (\n -> makeAgendum n) nonloops
+        makeAgendum new = Agendum {current = new, 
+                                    trail = (canonical candidate):previous, 
+                                    cost = estimateCost new}
+
+isGoal :: Building -> Bool
+isGoal (Building f floors) =
+    f+1 == height && (all (null) $ take f floors)
+    where height = length floors
+
+isLegal :: Building -> Bool
+isLegal (Building f floors) = 
+    null floor 
+    ||
+    not (any (isGenerator) floor)
+    ||
+    any (safePair) pairs
+    where floor = floors!!f
+          pairs = [(i, j) | i <- floor, j <- floor, isGenerator i]
+          safePair (Generator e, Microchip f) = e == f
+          safePair (Generator _, Generator _) = False
+
+isGenerator :: Item -> Bool
+isGenerator (Generator _) = True
+isGenerator (Microchip _) = False
+
+successors :: Building -> [Building]
+successors (Building f floors) = [updateBuilding f floors nf is | nf <- nextFloors, is <- items]
+    where 
+        floor = floors!!f
+        items = filter (\is -> length is == 1 || length is == 2) $ subsequences floor
+        nextFloors = if f == 0 then [1]
+                     else if f+1 == length floors then [f-1]
+                     else [f+1, f-1]
+
+legalSuccessors :: [Building] -> [Building]
+legalSuccessors = filter (isLegal)
+
+updateBuilding :: Int -> [Floor] -> Int -> [Item] -> Building
+updateBuilding oldF oldFloors newF items = Building newF newFloors
+    where newFloors = map (updateFloor) $ zip [0..] oldFloors
+          updateFloor (f, fl) 
+            | f == oldF = sort $ fl \\ items
+            | f == newF = sort $ items ++ fl
+            | otherwise = fl
+
+estimateCost :: Building -> Int
+estimateCost (Building _ floors) = 
+    sum $ map (\(c, f) -> c * length f) $ zip [0..] $ reverse floors
+
index 5a62ab109d88dd13f090067c5abaa88876cd88e2..6e4e47d83d8ca97c9641f7a458a84239baa0bb0d 100644 (file)
@@ -1,6 +1,8 @@
 import Data.List (subsequences, (\\), sort, sortOn, nub, findIndices)
 import Data.Ord (comparing)
 import Data.Char (isDigit)
+import Data.Maybe (fromMaybe)
+import qualified Data.PQueue.Prio.Min as P
 
 data Item = Generator String | Microchip String deriving (Show, Eq)
 type Floor = [Item]
@@ -8,6 +10,7 @@ data Building = Building Int [Floor] deriving (Show, Eq)
 -- data CBuilding = CBuilding Int [(Int, Int)] deriving (Show, Eq)
 data CBuilding = CBuilding Int Integer deriving (Show, Eq)
 data Agendum = Agendum {current :: Building, trail :: [CBuilding], cost :: Int}
+type Agenda = P.MinPQueue Int Agendum
 
 instance Ord Item where
     compare (Generator a) (Generator b) = compare a b
@@ -54,7 +57,6 @@ buildingTest = Building 0 [
     []]
 
 canonical :: Building -> CBuilding
--- canonical (Building f floors) = CBuilding f (sort pairs)
 canonical (Building f floors) = CBuilding f (read $ filter (isDigit) $ show $ sort pairs)
     where names = nub $ map (\(Generator n) -> n) $ filter (isGenerator) $ concat floors
           floorOf (Generator g) = head (findIndices 
@@ -66,45 +68,39 @@ canonical (Building f floors) = CBuilding f (read $ filter (isDigit) $ show $ so
           pairs = foldl (\ps n -> (floorOf (Generator n), floorOf (Microchip n)):ps) [] names
 
 
-
 main :: IO ()
 main = do 
     part1 
     part2 
 
-
 part1 :: IO ()
-part1 = print $ length $ trail $ aStar (initAgenda building1) []
--- part1 = print $ length $ trail $
---             aStar [Agendum {current = building1, trail=[], cost = estimateCost building1}] []
-
--- part2 :: IO ()
--- part2 = print $ length $ init $ extractJust $ aStar [[building2]] []
+part1 = print $ length $ trail $ fromMaybe (snd $ P.findMin $ initAgenda buildingTest) $ aStar (initAgenda building1) []
 
 part2 :: IO ()
-part2 = print $ length $ trail $aStar (initAgenda building2) []
-
-initAgenda :: Building -> [Agendum]
-initAgenda b = [Agendum {current = b, trail=[], cost = estimateCost b}]
-
-
-aStar :: [Agendum] -> [CBuilding] -> Agendum
-aStar [] _ = Agendum {current=buildingTest, trail=[], cost=0}
-aStar (currentAgendum:agenda) closed = 
-    if isGoal reached then currentAgendum
-    else if creached `elem` closed 
-        then aStar agenda closed
-        else aStar newAgenda (creached:closed) 
-    where 
-        reached = current currentAgendum
-        creached = canonical reached
-        newAgenda = 
-            -- sortBy (\t1 t2 -> (cost t1) `compare` (cost t2)) $ 
-            sortOn (cost) $ 
-            agenda ++ (candidates currentAgendum closed)
-
-
-candidates :: Agendum -> [CBuilding] -> [Agendum]
+part2 = print $ length $ trail $ fromMaybe (snd $ P.findMin $ initAgenda buildingTest) $ aStar (initAgenda building2) []
+
+initAgenda :: Building -> Agenda
+initAgenda b = P.singleton (estimateCost b) Agendum {current = b, trail=[], cost = estimateCost b}
+
+
+aStar :: Agenda -> [CBuilding] -> Maybe Agendum
+-- aStar [] _ = Agendum {current=buildingTest, trail=[], cost=0}
+aStar agenda closed 
+    | P.null agenda = Nothing
+    | otherwise = 
+        if isGoal reached then Just currentAgendum
+        else if creached `elem` closed 
+            then aStar (P.deleteMin agenda) closed
+            else aStar newAgenda (creached:closed) 
+        where 
+            (_, currentAgendum) = P.findMin agenda
+            reached = current currentAgendum
+            creached = canonical reached
+            newAgenda = P.union (P.deleteMin agenda) 
+                                (P.fromList $ candidates currentAgendum closed)
+
+
+candidates :: Agendum -> [CBuilding] -> [(Int, Agendum)]
 candidates agendum closed = newCandidates
     where
         candidate = current agendum
@@ -113,7 +109,7 @@ candidates agendum closed = newCandidates
         -- nonloops = (succs \\ previous) \\ closed
         excludable = previous ++ closed
         nonloops = filter (\s -> not $ (canonical s) `elem` excludable) succs
-        newCandidates = map (\n -> makeAgendum n) nonloops
+        newCandidates = map (\a -> (cost a, a)) $ map (\n -> makeAgendum n) nonloops
         makeAgendum new = Agendum {current = new, 
                                     trail = (canonical candidate):previous, 
                                     cost = estimateCost new + length previous + 1}
diff --git a/advent11p.prof.old b/advent11p.prof.old
new file mode 100644 (file)
index 0000000..c7a4e78
--- /dev/null
@@ -0,0 +1,163 @@
+       Wed Dec 14 20:57 2016 Time and Allocation Profiling Report  (Final)
+
+          advent11p +RTS -p -hy -RTS
+
+       total time  =       40.75 secs   (40754 ticks @ 1000 us, 1 processor)
+       total alloc = 5,362,606,072 bytes  (excludes profiling overheads)
+
+COST CENTRE                MODULE  %time %alloc
+
+candidates.nonloops.\      Main     54.4    0.2
+aStar                      Main     24.2    1.6
+==                         Main      8.4    0.0
+canonical                  Main      7.1   67.1
+==                         Main      1.2    0.0
+canonical.names            Main      1.1    6.9
+updateBuilding.updateFloor Main      0.7    6.2
+canonical.floorOf          Main      0.4    2.6
+aStar.newAgenda            Main      0.2    1.1
+canonical.pairs            Main      0.2    4.1
+isLegal.pairs              Main      0.2    2.9
+updateBuilding.newFloors   Main      0.1    1.8
+successors.items           Main      0.1    1.0
+estimateCost               Main      0.1    1.5
+successors                 Main      0.1    1.1
+
+
+                                                                               individual     inherited
+COST CENTRE                          MODULE                  no.     entries  %time %alloc   %time %alloc
+
+MAIN                                 MAIN                     96           0    0.0    0.0   100.0  100.0
+ part1                               Main                    194           0    0.0    0.0     0.0    0.0
+ CAF:main1                           Main                    188           0    0.0    0.0     0.0    0.0
+  part1                              Main                    193           1    0.0    0.0     0.0    0.0
+  main                               Main                    192           1    0.0    0.0     0.0    0.0
+ CAF:main2                           Main                    187           0    0.0    0.0     0.0    0.0
+  part1                              Main                    195           0    0.0    0.0     0.0    0.0
+ CAF:main3                           Main                    186           0    0.0    0.0     0.0    0.0
+  part1                              Main                    196           0    0.0    0.0     0.0    0.0
+ CAF:main4                           Main                    185           0    0.0    0.0     0.0    0.0
+  part1                              Main                    197           0    0.0    0.0     0.0    0.0
+   trail                             Main                    198           1    0.0    0.0     0.0    0.0
+ CAF:main5                           Main                    184           0    0.0    0.0     0.0    0.0
+  part1                              Main                    199           0    0.0    0.0     0.0    0.0
+ CAF:main6                           Main                    183           0    0.0    0.0   100.0  100.0
+  part1                              Main                    200           0    0.0    0.0   100.0  100.0
+   aStar                             Main                    201       86895   24.2    1.6   100.0  100.0
+    ==                               Main                    271   493018146    2.7    0.0     2.7    0.0
+    aStar.creached                   Main                    269       86894    0.0    0.1     3.2   24.5
+     canonical                       Main                    270       86894    2.1   20.3     3.2   24.4
+      canonical.pairs                Main                    299       86894    0.0    1.2     0.7    2.0
+       canonical.pairs.\             Main                    301      434470    0.0    0.0     0.6    0.8
+        canonical.floorOf            Main                    302      868940    0.1    0.8     0.6    0.8
+         canonical.floorOf.\         Main                    305     1060568    0.1    0.0     0.2    0.0
+          ==                         Main                    306     2672761    0.1    0.0     0.1    0.0
+         canonical.floorOf.\         Main                    303     1068473    0.1    0.0     0.3    0.0
+          ==                         Main                    304     2106409    0.2    0.0     0.2    0.0
+      canonical.names                Main                    297       86894    0.4    2.1     0.4    2.1
+       canonical.names.\             Main                    300      434470    0.0    0.0     0.0    0.0
+       isGenerator                   Main                    298      868940    0.0    0.0     0.0    0.0
+    aStar.newAgenda                  Main                    211       25877    0.2    1.1    69.9   73.9
+     candidates                      Main                    212       25877    0.0    0.0    69.7   72.7
+      candidates.newCandidates       Main                    260       25877    0.1    0.3     1.1    9.5
+       candidates.newCandidates.\    Main                    263       87266    0.0    0.2     1.1    9.1
+        candidates.makeAgendum       Main                    264       87266    0.0    0.0     1.0    9.0
+         canonical                   Main                    273       25876    0.5    6.1     0.8    7.3
+          canonical.pairs            Main                    289       25876    0.0    0.4     0.2    0.6
+           canonical.pairs.\         Main                    291      129380    0.0    0.0     0.2    0.2
+            canonical.floorOf        Main                    292      258760    0.0    0.2     0.2    0.2
+             canonical.floorOf.\     Main                    295      326405    0.0    0.0     0.1    0.0
+              ==                     Main                    296      809925    0.1    0.0     0.1    0.0
+             canonical.floorOf.\     Main                    293      320020    0.0    0.0     0.1    0.0
+              ==                     Main                    294      613255    0.0    0.0     0.0    0.0
+          canonical.names            Main                    287       25876    0.1    0.6     0.1    0.6
+           canonical.names.\         Main                    290      129380    0.0    0.0     0.0    0.0
+           isGenerator               Main                    288      258760    0.0    0.0     0.0    0.0
+         estimateCost                Main                    265       87266    0.1    1.5     0.2    1.6
+          estimateCost.\             Main                    267      349064    0.0    0.1     0.0    0.1
+       candidates.newCandidates.\    Main                    261       87266    0.0    0.0     0.0    0.0
+        cost                         Main                    262       87266    0.0    0.0     0.0    0.0
+      candidates.previous            Main                    258       25877    0.0    0.0     0.0    0.0
+       trail                         Main                    259       25877    0.0    0.0     0.0    0.0
+      candidates.excludable          Main                    257       25877    0.0    0.5     0.0    0.5
+      candidates.nonloops            Main                    255       25877    0.0    0.1    66.7   49.2
+       candidates.nonloops.\         Main                    256      173908   54.4    0.2    66.7   49.1
+        ==                           Main                    274  1116186639    5.8    0.0     5.8    0.0
+        canonical                    Main                    272      173884    4.5   40.7     6.5   48.9
+         canonical.pairs             Main                    278      173878    0.1    2.5     1.4    4.0
+          canonical.pairs.\          Main                    280      869390    0.0    0.0     1.3    1.6
+           canonical.floorOf         Main                    281     1738780    0.2    1.6     1.3    1.6
+            canonical.floorOf.\      Main                    284     2172320    0.2    0.0     0.6    0.0
+             ==                      Main                    285     5376137    0.4    0.0     0.4    0.0
+            canonical.floorOf.\      Main                    282     2172039    0.2    0.0     0.5    0.0
+             ==                      Main                    283     4187153    0.3    0.0     0.3    0.0
+         canonical.names             Main                    276      173878    0.6    4.2     0.6    4.2
+          canonical.names.\          Main                    279      869390    0.0    0.0     0.0    0.0
+          isGenerator                Main                    277     1738780    0.0    0.0     0.0    0.0
+      candidates.candidate           Main                    217       25877    0.0    0.0     0.0    0.0
+       current                       Main                    218       25877    0.0    0.0     0.0    0.0
+      candidates.succs               Main                    213       25877    0.0    0.0     1.8   13.5
+       successors                    Main                    216       25877    0.1    1.1     1.3   10.5
+        updateBuilding               Main                    236      301056    0.0    0.3     1.1    8.3
+         updateBuilding.newFloors    Main                    239      301056    0.1    1.8     1.0    8.0
+          updateBuilding.updateFloor Main                    247      822780    0.7    6.2     0.9    6.2
+           ==                        Main                    268      689856    0.1    0.0     0.1    0.0
+           compare                   Main                    250     1522445    0.1    0.0     0.1    0.0
+        successors.floor             Main                    228       25877    0.0    0.0     0.0    0.0
+        successors.items             Main                    220       25877    0.1    1.0     0.1    1.0
+         successors.items.\          Main                    227      451178    0.0    0.0     0.0    0.0
+        successors.nextFloors        Main                    219       25877    0.0    0.0     0.0    0.0
+       legalSuccessors               Main                    215           0    0.1    0.2     0.5    3.0
+        isLegal                      Main                    237      301056    0.2    0.0     0.4    2.9
+         isLegal.safePair            Main                    254     1442600    0.1    0.0     0.1    0.0
+         isLegal.pairs               Main                    252      263333    0.2    2.9     0.2    2.9
+          isGenerator                Main                    253      563756    0.0    0.0     0.0    0.0
+         isGenerator                 Main                    251      345446    0.0    0.0     0.0    0.0
+         isLegal.floor               Main                    238      301056    0.0    0.0     0.0    0.0
+    aStar.reached                    Main                    208       86895    0.0    0.0     0.0    0.0
+     current                         Main                    209       86895    0.0    0.0     0.0    0.0
+    isGoal                           Main                    207       86895    0.0    0.0     0.0    0.0
+     isGoal.height                   Main                    210       86895    0.0    0.0     0.0    0.0
+    aStar.currentAgendum             Main                    205       86895    0.0    0.0     0.0    0.0
+    aStar.(...)                      Main                    204       86895    0.0    0.0     0.0    0.0
+ CAF:lvl21_r8pa                      Main                    180           0    0.0    0.0     0.0    0.0
+  canonical                          Main                    275           0    0.0    0.0     0.0    0.0
+ CAF:main7                           Main                    169           0    0.0    0.0     0.0    0.0
+  part1                              Main                    202           0    0.0    0.0     0.0    0.0
+   initAgenda                        Main                    203           1    0.0    0.0     0.0    0.0
+ CAF:building1                       Main                    168           0    0.0    0.0     0.0    0.0
+  building1                          Main                    206           1    0.0    0.0     0.0    0.0
+ CAF:main12                          Main                    167           0    0.0    0.0     0.0    0.0
+  building1                          Main                    248           0    0.0    0.0     0.0    0.0
+   compare                           Main                    249           1    0.0    0.0     0.0    0.0
+ CAF:main19                          Main                    166           0    0.0    0.0     0.0    0.0
+  building1                          Main                    229           0    0.0    0.0     0.0    0.0
+   compare                           Main                    230          18    0.0    0.0     0.0    0.0
+ CAF:legalSuccessors_rSP             Main                    165           0    0.0    0.0     0.0    0.0
+  legalSuccessors                    Main                    214           1    0.0    0.0     0.0    0.0
+ CAF:$fOrdBuilding1                  Main                    161           0    0.0    0.0     0.0    0.0
+  estimateCost                       Main                    266           0    0.0    0.0     0.0    0.0
+ CAF:main36                          Main                    159           0    0.0    0.0     0.0    0.0
+  building1                          Main                    232           0    0.0    0.0     0.0    0.0
+ CAF:main32                          Main                    158           0    0.0    0.0     0.0    0.0
+  building1                          Main                    234           0    0.0    0.0     0.0    0.0
+ CAF:main29                          Main                    157           0    0.0    0.0     0.0    0.0
+  building1                          Main                    235           0    0.0    0.0     0.0    0.0
+ CAF:main18                          Main                    156           0    0.0    0.0     0.0    0.0
+  building1                          Main                    231           0    0.0    0.0     0.0    0.0
+ CAF:main16                          Main                    155           0    0.0    0.0     0.0    0.0
+  building1                          Main                    233           0    0.0    0.0     0.0    0.0
+ CAF:lvl3_r8oI                       Main                    149           0    0.0    0.0     0.0    0.0
+  aStar                              Main                    240           0    0.0    0.0     0.0    0.0
+   aStar.newAgenda                   Main                    241           0    0.0    0.0     0.0    0.0
+    candidates                       Main                    242           0    0.0    0.0     0.0    0.0
+     candidates.succs                Main                    243           0    0.0    0.0     0.0    0.0
+      successors                     Main                    244           0    0.0    0.0     0.0    0.0
+       updateBuilding                Main                    245           0    0.0    0.0     0.0    0.0
+        updateBuilding.newFloors     Main                    246           0    0.0    0.0     0.0    0.0
+ CAF                                 GHC.IO.Handle.FD        143           0    0.0    0.0     0.0    0.0
+ CAF                                 Text.Read.Lex           131           0    0.0    0.0     0.0    0.0
+ CAF                                 GHC.Conc.Signal         130           0    0.0    0.0     0.0    0.0
+ CAF                                 GHC.IO.Encoding         128           0    0.0    0.0     0.0    0.0
+ CAF                                 GHC.IO.Handle.Text      127           0    0.0    0.0     0.0    0.0
+ CAF                                 GHC.IO.Encoding.Iconv   110           0    0.0    0.0     0.0    0.0