Commit 3f632f2a authored by Thorsten Wißmann's avatar Thorsten Wißmann 🎸
Browse files

Replace weight in powerset by (Bool,Int)

We don't need to know the count of edges that go outside of the block of
interest. It only matters whether there is one, so that we can correctly
return H3 in update.
parent 55a0cf55
Pipeline #17412 passed with stage
in 15 minutes and 48 seconds
......@@ -39,7 +39,7 @@ powerset = FunctorDescription
prefix ((L.symbol "P" <|> L.symbol "Ƥ") >> pure Powerset)
}
data PowerWeight = PowerWeight {-# UNPACK #-} !Int {-# UNPACK #-} !Int
data PowerWeight = PowerWeight {-# UNPACK #-} !Bool {-# UNPACK #-} !Int
deriving (Show,Eq)
newtype PowerH3 = PowerH3 Word8
......@@ -53,7 +53,7 @@ mkPowerH3 !a !b !c = PowerH3 $ set 0 a .|. set 1 b .|. set 2 c
-- | No edge labels
type instance Label Powerset = ()
-- | Tuple of (|edgesToC\S|, |edgesToS|)
-- | Tuple of (Edges to X\C, |edgesToC|)
type instance Weight Powerset = PowerWeight
-- | Does this state have at least one successor?
type instance H1 Powerset = Bool
......@@ -77,7 +77,7 @@ instance ParseMorphism Powerset where
instance RefinementInterface Powerset where
init :: H1 Powerset -> [Label Powerset] -> Weight Powerset
init _ = PowerWeight 0 . length
init _ = PowerWeight False . length
update :: [Label Powerset] -> Weight Powerset
-> (Weight Powerset, H3 Powerset, Weight Powerset)
......@@ -85,8 +85,8 @@ instance RefinementInterface Powerset where
let
toS = length labels
toCwithoutS = toC - toS
!weightToS = PowerWeight (toRest + toCwithoutS) toS
!h3 = mkPowerH3 (toRest > 0) (toCwithoutS > 0) (toS > 0)
!weightToCwithoutS = PowerWeight (toRest + toS) toCwithoutS
!weightToS = PowerWeight (toRest || toCwithoutS > 0) toS
!h3 = mkPowerH3 toRest (toCwithoutS > 0) (toS > 0)
!weightToCwithoutS = PowerWeight (toRest || toS > 0) toCwithoutS
in
(weightToS, h3, weightToCwithoutS)
......@@ -69,7 +69,7 @@ lastWSpec = describe "returned lastW vector" $ do
it "works with some edges" $
getLastW [True, True] [(0, 1), (0, 0), (1, 0)]
`shouldBe` [PowerWeight 0 2, PowerWeight 0 2, PowerWeight 0 1]
`shouldBe` [PowerWeight False 2, PowerWeight False 2, PowerWeight False 1]
enc :: [h1] -> [(State, label, State)] -> Encoding label h1
......
......@@ -127,10 +127,10 @@ updateBlockSpec = describe "updateBlock" $ do
lw <- view (_1 . lastWL) >>= lift . V.freeze
lift (lw & V.toList & mapM readSTRef)
in res
`shouldBe` [ PowerWeight 2 1
, PowerWeight 1 2
, PowerWeight 1 2
, PowerWeight 0 1
`shouldBe` [ PowerWeight True 1
, PowerWeight True 2
, PowerWeight True 2
, PowerWeight False 1
]
-- The idea here is that the edges from state 0 to block 1 cancel each other
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment