com.workflowfm.proter

Type members

Classlikes

case
class Arrival(time: Long, rate: Distribution, simulationGenerator: SimulationRefGenerator, limit: Option[Int], count: Int) extends DiscreteEvent

Event used to model a repeating process.

Event used to model a repeating process.

An arrival rate is used to indicate when new instances of a simulation should be added to the coordinator.

Value Params
count

A counter of the next simulation instance that will be generated

rate

The arrival rate of the simulation

simulationGenerator

The simulation generator for getting new instances of a simulation

time

The timestamp of the event

Asynchronous Simulation implementation with callback functions.

Asynchronous Simulation implementation with callback functions.

Each task needs to be accompanied by a callback function that implements the simulation logic to be followed when the task completes.

case
class Constant(value: Double) extends Distribution

A constant value generator.

A constant value generator.

Always generates the same value.

Value Params
value

The value to generate.

case
class ConstantLong(value: Long) extends LongDistribution

A constant Long value generator.

A constant Long value generator.

Always generates the same value.

Value Params
value

The value to generate.

class Coordinator(scheduler: Scheduler, singleThread: Boolean, startingTime: Long)(using x$4: ExecutionContext) extends Manager with HashMapPublisher

Provides coordination for discrete event simulation of multiple asynchronous simulations.

Provides coordination for discrete event simulation of multiple asynchronous simulations.

Default implementation of Manager.

It can run in a single thread or multi-threaded depending on the singleThread constructor parameter. In the multi-threaded setting, task completions are reported to the simulations asynchronously through a new thread (Future) each time. This allows simulations to run things concurrently, with the added overhead of thread spawning.

Value Params
scheduler

The Scheduler responsible for task allocation at any given time.

singleThread

Flag to run everything in a single thread or else use Futures.

startingTime

The starting timestamp of the entire simulation.

sealed
trait DiscreteEvent extends Ordered[DiscreteEvent]

Discrete Events that need to be handled by the Coordinator..

Discrete Events that need to be handled by the Coordinator..

A random function sampling some probability distribution to produce a Double value.

A random function sampling some probability distribution to produce a Double value.

It can be used to generate a value for simulation parameters (typically duration and cost). It can be a Constant which always provides the same value or any probability distribution.

Distributions must also provide an estimate of the generated values such that can be used in an environment of imperfect knowledge. For example, the Scheduler does not know the actual durations of tasks, which can vary from the expected estimate for various reasons.

case
class Exponential(mean: Double) extends Distribution
case
class FinishingTask(time: Long, task: TaskInstance) extends DiscreteEvent

Event fired when a Task has finished.

Event fired when a Task has finished.

Value Params
task

The Task that was finished.

time

The timestamp of the event

Extends AsyncSimulation with callbacks that fulfil a Promise/Future.

Extends AsyncSimulation with callbacks that fulfil a Promise/Future.

This can be helpful for simulation implementations that use Futures to capture their asynchronous logic.

A random function sampling some probability distribution to produce a Long value.

A random function sampling some probability distribution to produce a Long value.

It can be used to generate a value for simulation parameters (typically duration). It can be a ConstantLong which always provides the same value or any probability distribution.

Distributions must also provide an estimate of the generated values such that can be used in an environment of imperfect knowledge. For example, the Scheduler does not know the actual durations of tasks, which can vary from the expected estimate for various reasons.

trait Lookahead

A Lookahead contains information about the order in which tasks run.

A Lookahead contains information about the order in which tasks run.

The structure is immutable. It is built by the simulation and passed to the scheduler where it is used for scheduling by revealing information about future tasks so that look-ahead can be achieved.

case
class LookaheadSet(lookaheadSet: Set[(Map[UUID, Long] => Option[Long], List[Task])]) extends Lookahead

A Lookahead that uses a set in the implementation

A Lookahead that uses a set in the implementation

Value Params
completed

The initial completed tasks. Empty by default.

lookaheadSet

The initial set used. Empty by default.

See also
case
class Lookaheads(lookaheads: Queue[Lookahead]) extends Lookahead

A Structure used for combining multiple Lookaheads into one.

A Structure used for combining multiple Lookaheads into one.

Value Params
lookaheads

A queue of the Lookaheads which are included in this strucutre.

Companion
object
object Lookaheads
Companion
class
trait LookingAhead extends Simulation

A trait that adds Lookahead capabilities to a simulation.

A trait that adds Lookahead capabilities to a simulation.

Works in conjunction with LookaheadScheduler.

Provides a lookahead structure that can be built up by the simulation and then sent to the scheduler for use in making schedules which look into the future to consider upcoming tasks in scheduling.

trait Manager

Abstract simulation manager.

Abstract simulation manager.

case
object NoLookahead extends Lookahead

An empty Lookahead that does nothing.

An empty Lookahead that does nothing.

case
class SimDone(simulation: String, result: Try[Any]) extends SimResponse

Response issued when the simulation has completed.

Response issued when the simulation has completed.

Value Params
result

The (successful or failed) result of the simulation.

simulation

The name of the SimulationRef.

case
class SimReady(simulation: String, tasks: Seq[Task], abort: Seq[UUID], lookahead: Lookahead) extends SimResponse

Response issued when the simulation is still running and waiting for virtual time to pass.

Response issued when the simulation is still running and waiting for virtual time to pass.

Value Params
abort

A sequence of IDs of existing tasks that need to be aborted.

lookahead

An updated Lookahead structure.

simulation

The name of the SimulationRef.

tasks

A sequence of new tasks to be added for scheduling.

sealed

Captures the potential responses of a simulation case to an event.

Captures the potential responses of a simulation case to an event.

A simulation is notified by its Manager when relevant events have taken place, such as one of its tasks completing. The simulation can use subclasses of this trait to respond to such notification. The Manager will wait for such a response before it resumes the virtual time.

A manager for a single simulation case.

A manager for a single simulation case.

We view a simulation as a case or workflow of simulated tasks. This class is responsible for keeping track of all the tasks for the corresponding simulation, informing the Coordinator of new tasks to be added and informing the simulation processes when a task is completed.

=Basic Interaction Flow= The interaction flow with the Coordinator is expected as follows:

  1. The simulation logic starts executing via run.
  2. Tasks are added via task.
  3. When the simulation logic finishes producing tasks, it should call ready.
  4. Eventually, one of the tasks completes and complete is called. The simulation logic resumes execution.
  5. The simulation may now produce further tasks in reaction to the completed one(s). It can either handle and acknowledge each completed task individually using ack or use ready in one go as above.
  6. When the simulation logic completes, it can use succeed (instead of ack or ready) to notify the Coordinator of its result.

=Additional Functions= The simulation may also:

  1. React to things happening to other simulations. It can send a request to wait using simWait. The Coordinator will then wait for the Simulation to send new tasks or to complete, as if a task just completed. This needs to happen while the Coordinator is still waiting for the other simulation(s) we are reacting to.
  2. Abort previously added tasks using abort.
  3. Report completion due to failure using fail.
  4. Optionally maintain a Lookahead structure of future tasks, returning it through getLookahead.
Companion
object
object Simulation
Companion
class

A generator of simulation instances.

A generator of simulation instances.

This is used to model repeating processes, for instance with a given arrival rate.

It generates copies of a SimulationRef. It must ensure that each copy has a unique name and is independent from all other copies. An integer counter is provided as an argument for that purpose, though it is not necessary to use that.

An abstract reference to simulation logic.

An abstract reference to simulation logic.

Includes the basic interface that we expect from a simulation case:

  1. Starting the simulation.
  2. Notifying when tasks complete.
  3. Stopping/aborting the simulation.

A generator of simulation instances.

A generator of simulation instances.

This is used to model repeating processes, for instance with a given arrival rate.

It generates copies of a SimulationRef. It must ensure that each copy has a unique name and is independent from all other copies. An integer counter is provided as an argument for that purpose, though it is not necessary to use that.

class SingleTaskSimulation(val name: String, val manager: Manager, resources: Seq[String], duration: LongDistribution, cost: Distribution, interrupt: Int, priority: Int) extends Simulation

A Simulation that simulates a single Task.

A Simulation that simulates a single Task.

Value Params
cost

A Distribution for the cost of the Task.

duration

A Distribution for the duration of the Task.

interrupt

The Task.interrupt parameter.

manager

The Manager of the simulation.

name

The simulation name.

priority

The explicit priority of the Task.

resources

The names of the TaskResources the Task will require.

class SingleTaskSimulationGenerator(baseName: String, resources: Seq[String], duration: Distribution, cost: Distribution, interrupt: Int, priority: Int) extends SimulationGenerator
Value Params
baseName

The base string (prefix) to use in the name.

cost

The cost of the task.

duration

The duration distribution of the task.

priority

The priority to be given to the task.

resources

The resources required by the task.

case
class StartingSim(time: Long, simulation: SimulationRef) extends DiscreteEvent

Event fired when a simulation needs to start.

Event fired when a simulation needs to start.

Value Params
simulation

The Simulation that needs to start.

time

The timestamp of the event

case
class Task(name: String, id: Option[UUID], duration: LongDistribution, cost: Distribution, minStartTime: Long, resources: Seq[String], interrupt: Int, priority: Int, createTime: Long)

A generator/factory of tasks (specifically TaskInstances).

A generator/factory of tasks (specifically TaskInstances).

As a case class, it can be easily manipulated dynamically to alter its values.

Uses Distributions for the duration and cost. These may be based on random variables. The actual values are sampled at task creation time.

Although typically only 1 task is generated, in principle it can generate multiple task instances with the same properties. However, each task generated will have different samples of the Distributions.

Value Params
cost

The generator of the cost.

createTime

A custom creation time. Negative values correspond to the current time.

duration

The generator of the duration.

id

An optional unique id of the task. Otherwise a random ID will be used.

interrupt

The TaskInstance.interrupt property of the task.

minStartTime

The earliest possible starting time of the task.

name

The name of the task.

priority

The explicit priority of the task.

resources

The resources of this task

Companion
object
object Task
Companion
class
class TaskInstance(val id: UUID, val name: String, val simulation: String, val created: Long, val minStartTime: Long, val resources: Seq[String], val duration: Long, val estimatedDuration: Long, val cost: Double, val interrupt: Int, val priority: Int) extends Ordered[TaskInstance]

An instance of a task to be performed in virtual time.

An instance of a task to be performed in virtual time.

Value Params
created

The timestamp when this task was created.

duration

The actual duration of the task.

estimatedDuration

The estimated duration of the task.

id

A unique id that separates this task from any other task. A workflow may spawn multiple tasks with the same name, so this is necessary.

initialCost

A one-off cost of performing this task.

interrupt

The number of times the task can be interrupted in favour of a more urgent one. This parameter is not currently being used.

minStartTime

The earliest possible starting time of this task.

name

A descriptive name.

priority

The explicit priority of the task.

resources

The names of the TaskResources required by this task.

simulation

A unique name of the simulation this task belongs to.

Note

We expect that task instances are only generated through a Task. The samples of the parameters are generated by the Coordinator. The duration can be specified through random sampling in a Distribution. We store the estimated value as well as the actual sampled value.

class TaskResource(val name: String, val costPerTick: Double)

A persistent resource to be used by Tasks/TaskInstances.

A persistent resource to be used by Tasks/TaskInstances.

A TaskResource, or simply "resource", corresponds to a persistent resource. Typical examples are human actors or persistent machinery.

Each Task may require a different combination of resources.

Each TaskResource is assumed to have a unique name and a costPerTick, i.e. the cost (if any) of using the resource per unit of time.

We say a TaskResource is ''attached'' to a TaskInstance when the task that uses this resource is being performed. The currentTask variable holds the task that is currently attached to the resource (if any) coupled with the virtual timestamp of when it started. A TaskResource is ''idle''' when it has no tasks attached to it.

The Coordinator calls upon startTask to attach a task to the resource and finishTask to detach it. The Coordinator has full control over the resource and makes all necessary checks to ensure consistent behaviour (e.g. not starting a TaskInstance when another TaskInstance is already attached).

Value Params
costPerTick

The cost of using the resource per unit of time.

name

The name of the resource.

case
class TimeLimit(time: Long) extends DiscreteEvent

Event fired when a global time limit has been reached.

Event fired when a global time limit has been reached.

Value Params
time

The timestamp of the event

case
class Uniform(min: Double, max: Double) extends Distribution

A uniform distribution.

A uniform distribution.

Samples a random variable uniformly between min and max.

Value Params
max

The maximum possible value.

min

The minimum possible value.

case
class UniformLong(min: Long, max: Long) extends LongDistribution

A uniform Long distribution.

A uniform Long distribution.

Samples a random variable uniformly between min and max.

Value Params
max

The maximum possible value.

min

The minimum possible value.