Added profiling
[advent-of-code-22.git] / advent19 / Main.hs
index 7fe03159c679cabf2c5a6244cbcb3d8130d52ed0..25f608a6eb6675bb7a6c2f741c3161a70987280f 100644 (file)
@@ -19,6 +19,7 @@ import Data.Maybe
 -- import Data.Ord
 import Control.Monad.Reader
 import Control.Lens hiding ((<|), (|>), (:>), (:<), indices)
+import GHC.Generics (Generic)
 import Control.Parallel.Strategies
 import Control.DeepSeq
 
@@ -27,7 +28,9 @@ import Control.DeepSeq
 -- pattern xs :> x <- (Q.viewr -> xs Q.:> x) where (:>)  = (Q.|>) 
 
 data Resource = Ore | Clay | Obsidian | Geode
-    deriving (Show, Eq, Ord)
+    deriving (Show, Eq, Ord, Generic)
+
+instance NFData Resource 
 
 type Collection = MS.MultiSet Resource
 
@@ -45,7 +48,7 @@ data SingleSearchState = SingleSearchState
 makeLenses ''SingleSearchState
 
 instance NFData SingleSearchState where
-  rnf a = a `seq` ()
+  rnf (SingleSearchState a b) = rnf a `seq` rnf b `seq` ()
 
 data Agendum s = 
     Agendum { _current :: s
@@ -109,7 +112,15 @@ part1 blueprints = sum [n * (MS.occur Geode (r ^. resources)) | (n, r) <- result
     where results = [ (n, _current $ fromJust $ runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) )
                     | (n, blueprint) <- blueprints ] :: [(Int, SingleSearchState)]
           robotLimits bp = M.foldl' MS.maxUnion MS.empty bp
-
+-- part1 blueprints = sum [n * (MS.occur Geode (r ^. resources)) | (n, r) <- pResults]
+--     where -- results = [ (n, _current $ fromJust $ runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) )
+--                     -- | (n, blueprint) <- blueprints ] :: [(Int, SingleSearchState)]
+--           -- pResults = parMap rdeepseq id results
+--           -- pResults = (fmap runABlueprint blueprints) `using` parList rdeepseq
+--           pResults = (fmap runABlueprint blueprints) `using` (parList rdeepseq)
+--           runABlueprint (n, blueprint) = (n, _current $ fromJust $ 
+--                                                 runReader searchSpace (TimedBlueprint blueprint 24 (robotLimits blueprint)) )
+--           robotLimits bp = M.foldl' MS.maxUnion MS.empty bp
 
 part2 :: [(Int, Blueprint)] -> Int
 part2 blueprints = product [MS.occur Geode (r ^. resources) | r <- pResults]