aivika-transformers-5.4: Transformers for the Aivika simulation library

CopyrightCopyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Simulation.Aivika.Trans.Resource.Base

Contents

Description

Tested with: GHC 8.0.1

This module defines an optimised version of the resource which can be acquired and then released by the discontinuous process Process. The resource can be either limited by the upper bound (run-time check), or it can have no upper bound. The latter is useful for modeling the infinite queue, for example.

The module is optimised in the sense that this kind of the resource has neither additional signals, nor counters that would may slow down the simulation.

Synopsis

Resource Types

type FCFSResource m = Resource m FCFS Source #

The ordinary FCFS (First Come - First Serviced) resource.

type LCFSResource m = Resource m LCFS Source #

The ordinary LCFS (Last Come - First Serviced) resource.

type SIROResource m = Resource m SIRO Source #

The SIRO (Serviced in Random Order) resource.

type PriorityResource m = Resource m StaticPriorities Source #

The resource with static priorities.

data Resource m s Source #

Represents the resource with strategy s applied for queuing the requests.

Creating Resource

newFCFSResource Source #

Arguments

:: MonadDES m 
=> Int

the initial count (and maximal count too) of the resource

-> Simulation m (FCFSResource m) 

Create a new FCFS resource with the specified initial count which value becomes the upper bound as well.

newFCFSResourceWithMaxCount Source #

Arguments

:: MonadDES m 
=> Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation m (FCFSResource m) 

Create a new FCFS resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newLCFSResource Source #

Arguments

:: MonadDES m 
=> Int

the initial count (and maximal count too) of the resource

-> Simulation m (LCFSResource m) 

Create a new LCFS resource with the specified initial count which value becomes the upper bound as well.

newLCFSResourceWithMaxCount Source #

Arguments

:: MonadDES m 
=> Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation m (LCFSResource m) 

Create a new LCFS resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newSIROResource Source #

Arguments

:: (MonadDES m, QueueStrategy m SIRO) 
=> Int

the initial count (and maximal count too) of the resource

-> Simulation m (SIROResource m) 

Create a new SIRO resource with the specified initial count which value becomes the upper bound as well.

newSIROResourceWithMaxCount Source #

Arguments

:: (MonadDES m, QueueStrategy m SIRO) 
=> Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation m (SIROResource m) 

Create a new SIRO resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newPriorityResource Source #

Arguments

:: (MonadDES m, QueueStrategy m StaticPriorities) 
=> Int

the initial count (and maximal count too) of the resource

-> Simulation m (PriorityResource m) 

Create a new priority resource with the specified initial count which value becomes the upper bound as well.

newPriorityResourceWithMaxCount Source #

Arguments

:: (MonadDES m, QueueStrategy m StaticPriorities) 
=> Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation m (PriorityResource m) 

Create a new priority resource with the specified initial and maximum counts, where Nothing means that the resource has no upper bound.

newResource Source #

Arguments

:: (MonadDES m, QueueStrategy m s) 
=> s

the strategy for managing the queuing requests

-> Int

the initial count (and maximal count too) of the resource

-> Simulation m (Resource m s) 

Create a new resource with the specified queue strategy and initial count. The last value becomes the upper bound as well.

newResourceWithMaxCount Source #

Arguments

:: (MonadDES m, QueueStrategy m s) 
=> s

the strategy for managing the queuing requests

-> Int

the initial count of the resource

-> Maybe Int

the maximum count of the resource, which can be indefinite

-> Simulation m (Resource m s) 

Create a new resource with the specified queue strategy, initial and maximum counts, where Nothing means that the resource has no upper bound.

Resource Properties

resourceStrategy :: Resource m s -> s Source #

Return the strategy applied for queuing the requests.

resourceMaxCount :: Resource m s -> Maybe Int Source #

Return the maximum count of the resource, where Nothing means that the resource has no upper bound.

resourceCount :: MonadDES m => Resource m s -> Event m Int Source #

Return the current count of the resource.

Requesting for and Releasing Resource

requestResource Source #

Arguments

:: (MonadDES m, EnqueueStrategy m s) 
=> Resource m s

the requested resource

-> Process m () 

Request for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.

requestResourceWithPriority Source #

Arguments

:: (MonadDES m, PriorityQueueStrategy m s p) 
=> Resource m s

the requested resource

-> p

the priority

-> Process m () 

Request with the priority for the resource decreasing its count in case of success, otherwise suspending the discontinuous process until some other process releases the resource.

tryRequestResourceWithinEvent Source #

Arguments

:: MonadDES m 
=> Resource m s

the resource which we try to request for

-> Event m Bool 

Try to request for the resource decreasing its count in case of success and returning True in the Event monad; otherwise, returning False.

releaseResource Source #

Arguments

:: (MonadDES m, DequeueStrategy m s) 
=> Resource m s

the resource to release

-> Process m () 

Release the resource increasing its count and resuming one of the previously suspended processes as possible.

releaseResourceWithinEvent Source #

Arguments

:: (MonadDES m, DequeueStrategy m s) 
=> Resource m s

the resource to release

-> Event m () 

Release the resource increasing its count and resuming one of the previously suspended processes as possible.

usingResource Source #

Arguments

:: (MonadDES m, EnqueueStrategy m s) 
=> Resource m s

the resource we are going to request for and then release in the end

-> Process m a

the action we are going to apply having the resource

-> Process m a

the result of the action

Acquire the resource, perform some action and safely release the resource in the end, even if the IOException was raised within the action.

usingResourceWithPriority Source #

Arguments

:: (MonadDES m, PriorityQueueStrategy m s p) 
=> Resource m s

the resource we are going to request for and then release in the end

-> p

the priority

-> Process m a

the action we are going to apply having the resource

-> Process m a

the result of the action

Acquire the resource with the specified priority, perform some action and safely release the resource in the end, even if the IOException was raised within the action.

Altering Resource

incResourceCount Source #

Arguments

:: (MonadDES m, DequeueStrategy m s) 
=> Resource m s

the resource

-> Int

the increment for the resource count

-> Event m () 

Increase the count of available resource by the specified number, invoking the awaiting processes as needed.

decResourceCount Source #

Arguments

:: (MonadDES m, EnqueueStrategy m s) 
=> Resource m s

the resource

-> Int

the decrement for the resource count

-> Process m () 

Decrease the count of available resource by the specified number, waiting for the processes capturing the resource as needed.