Skip to content

Commit 118b72d

Browse files
committed
Switch to High mode only when needed.
refs #5. on task #19, this reduced energy from 35617050588 to 3564378588 (10x approx.).
1 parent 9488d6d commit 118b72d

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Algorithms.hs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Control.Monad.State
66
import Data.Word
77
import Data.Binary (decodeFile)
88
import Text.Printf
9+
import qualified Data.Array.BitArray as BA
10+
import qualified Data.Set as S
911

1012
import Trace
1113
import Sim
@@ -44,9 +46,30 @@ fill bid dir p@(x,y,z) = do
4446
(neighbour, diff) <- findFreeNeighbour p
4547
let diff' = negateNear diff
4648
move bid neighbour
49+
grounded <- willBeGrounded p
50+
unless grounded $
51+
setHarmonics bid High
4752
issueFill bid diff'
53+
setHarmonics bid Low
4854
step
4955

56+
-- This would be too slow
57+
-- isGrounded :: P3 -> Generator Bool
58+
-- isGrounded p = do
59+
-- matrix <- gets gsFilled
60+
-- return $ go matrix S.empty p
61+
-- where
62+
-- go _ _ (_,0,_) = True
63+
-- go m visited p@(x,y,z) =
64+
-- case m BA.!? p of
65+
-- Nothing -> return False
66+
-- Just False -> return False
67+
-- Just True ->
68+
-- let neighbours = [(x+1, y, z), (x, y+1, z), (x, y, z+1),
69+
-- (x-1, y, z), (x, y-1, z), (x, y, z-1)]
70+
-- nonVisited = [neighbour | neighbour `S.notMember` visited]
71+
-- in or [go m (S.insert neighbour visited) neighbour | neighbour <- nonVisited]
72+
5073
makeLine :: Direction -> Resolution -> Word8 -> Word8 -> [P3]
5174
makeLine dir r y z =
5275
case dir of
@@ -98,10 +121,11 @@ dumbHighSolver modelPath tracePath = do
98121
model <- decodeFile modelPath
99122
let trace = makeTrace model $ do
100123
let bid = 0
101-
issue bid Flip
124+
-- issueFlip bid
102125
dumbFill bid
103126
move bid (0,0,0)
104-
issue bid Flip
127+
-- issueFlip bid
105128
issue bid Halt
129+
print trace
106130
writeTrace tracePath trace
107131

0 commit comments

Comments
 (0)