module Simulation.Aivika.Trans.GPSS.Block.Preempt
(preemptBlock,
PreemptBlockMode(..),
defaultPreemptBlockMode,
toFacilityPreemptMode,
fromFacilityPreemptMode) where
import Simulation.Aivika.Trans
import Simulation.Aivika.Trans.GPSS.Transact
import Simulation.Aivika.Trans.GPSS.Block
import Simulation.Aivika.Trans.GPSS.Facility
data PreemptBlockMode m a =
PreemptBlockMode { preemptBlockPriorityMode :: Bool,
preemptBlockTransfer :: Maybe (Maybe Double -> Block m (Transact m a) ()),
preemptBlockRemoveMode :: Bool
}
toFacilityPreemptMode :: MonadDES m => PreemptBlockMode m a -> FacilityPreemptMode m a
toFacilityPreemptMode m =
FacilityPreemptMode { facilityPriorityMode = preemptBlockPriorityMode m,
facilityTransfer = transfer,
facilityRemoveMode = preemptBlockRemoveMode m
}
where
transfer =
case preemptBlockTransfer m of
Nothing -> Nothing
Just f -> Just (\a dt -> blockProcess (f dt) a)
fromFacilityPreemptMode :: MonadDES m => FacilityPreemptMode m a -> PreemptBlockMode m a
fromFacilityPreemptMode m =
PreemptBlockMode { preemptBlockPriorityMode = facilityPriorityMode m,
preemptBlockTransfer = transfer,
preemptBlockRemoveMode = facilityRemoveMode m
}
where
transfer =
case facilityTransfer m of
Nothing -> Nothing
Just f -> Just (\dt -> Block $ \a -> f a dt)
defaultPreemptBlockMode :: MonadDES m => PreemptBlockMode m a
defaultPreemptBlockMode =
PreemptBlockMode { preemptBlockPriorityMode = False,
preemptBlockTransfer = Nothing,
preemptBlockRemoveMode = False
}
preemptBlock :: MonadDES m
=> Facility m a
-> PreemptBlockMode m a
-> Block m (Transact m a) (Transact m a)
preemptBlock r m =
Block { blockProcess = \a -> preemptFacility r a (toFacilityPreemptMode m) >> return a }