Commit cb83555d authored by Philipp Meyer's avatar Philipp Meyer

Generate log flock of birds protocol with Integer

parent 81374fc7
......@@ -87,7 +87,10 @@ data THState = THVal (Int, Int) | Passivo | Eater deriving (Show, Eq, Ord)
floorLog :: Int -> Int
floorLog = floor . logBase 2 . fromIntegral
g :: Int -> Int
genericFloorLog :: Integer -> Int
genericFloorLog = floor . logBase 2 . fromIntegral
g :: Int -> Int
g n = n - 2^(floorLog n)
maxLevel :: Int -> Int
......@@ -96,16 +99,16 @@ maxLevel n | n == 0 = -1
maxOnLevel i n = floorLog (iterate g n !! i)
createLogFlockOfBirdsProtocol :: Int -> PopulationProtocol Int
createLogFlockOfBirdsProtocol :: Integer -> PopulationProtocol Integer
createLogFlockOfBirdsProtocol c = PopulationProtocol{ states = nub logQ
, initial = [1, 0]
, opinion = (== c)
, trans = logTrans
, predicate = Just $ toVar 1 ++ " >= " ++ show c} where
logQ = [2^i | i <- [0..(floorLog c-1)]] ++ [c .&. (shift (complement 0) i) | i <- [0..(floorLog c + 1)]]
logQ = [2^i | i <- [0..(genericFloorLog c-1)]] ++ [c .&. (shift (complement 0) i) | i <- [0..(genericFloorLog c + 1)]]
logTrans (x, y) | x + y >= c = (c, c)
| x == y && 2*x < c = (2*x, 0)
| y >= floorLog c && y + x `elem` logQ = (x+y, 0)
| y >= fromIntegral (genericFloorLog c) && y + x `elem` logQ = (x+y, 0)
| otherwise = (x, y)
createPolyLogFlockOfBirdsProtocol :: Int -> PopulationProtocol THState
createPolyLogFlockOfBirdsProtocol c =
......
Markdown is supported
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