LookaheadScheduler

class LookaheadScheduler(initialTasks: TaskInstance*) extends PriorityScheduler

A Scheduler to be used for look-ahead.

Should be used in conjunction with simulations which use the lookahead trait.

Relies on the use of Schedules for each TaskResource.

trait Scheduler
class Object
trait Matchable
class Any

Value members

Concrete methods

override
def complete(task: TaskInstance, time: Long): Unit

Adds an Task described by an (ID,time) pair to the list of completed IDs

Adds an Task described by an (ID,time) pair to the list of completed IDs

Definition Classes
@tailrec
final protected
def findNextTasks(currentTime: Long, resourceMap: Map[String, TaskResource], schedules: Map[String, Schedule], tasks: SortedSet[TaskInstance], scheduledThisIter: Seq[(UUID, Long)], lookaheadSetThisIter: Lookahead, result: Queue[TaskInstance]): Seq[TaskInstance]

Finds the TaskInstances that can be started now.

Finds the TaskInstances that can be started now.

The algorithm is recursive, and works by starting with the original lookahead structure and slowly reducing it as the algorithm progresses. Every time a task is scheduled, the subsequent tasks are discovered via the lookahead structure and are added to the task list, while the structure itself removes these tasks such that a single task cannot be returned more than once.

TaskInstances are assumed to be sorted by priority.

Taking each TaskInstance from high to low priority, the algorithm does the following:

  1. It merges the current Schedules of all the TaskResources involved in the Task.
  2. It finds the earliest possible starting time of the TaskInstance in the merged Schedule, using the task's minimum starting time.
  3. It finds the tasks that will start after the TaskInstance using the lookahead structure, and updates the structure.
  4. Takes the interval defined by the starting time and the estimated duration of the TaskInstance and adds it to the Schedules of all the involved TaskResources.
  5. If the starting time is equal to the current time, and all involved TaskResources are idle, it adds the TaskInstance to the result.
Value Params
currentTime

The current timestamp.

lookaheadSetThisIter

The lookahead structure to be used. Is reduced over time as tasks are scheduled.

resourceMap

The map of available TaskResources.

result

The accumulated TaskInstances so far (for tail recursion).

scheduledThisIter

The set of TaskInstances that have been scheduled so far and the times at which they are scheduled.

schedules

The map of Schedules for each TaskResource.

tasks

The set of TaskInstances that need to be considered.

Returns

The sequence of TaskInstances to start now.

override
def getNextTasks(currentTime: Long, resourceMap: Map[String, TaskResource]): Seq[TaskInstance]

Determines which TaskInstances to start next.

Determines which TaskInstances to start next.

TaskInstances are assumed to be sorted by priority.

Uses findNextTasks.

Value Params
currentTime

The current timestamp.

resourceMap

The map of available TaskResources.

Returns

The sequence of TaskInstances to start now.

See also

findNextTasks Finds currently running tasks by using the resourceMap and also considers these for scheduling.

Definition Classes
override
def removeLookahead(simulation: String): Unit

Removes the lookahead structure bcorresponding to an actor.

Removes the lookahead structure bcorresponding to an actor.

Value Params
simulation

The name of the simulation whose lookahead structure should be removed.

Definition Classes
override
def removeSimulation(simulation: String): Unit

Removes all TaskInstances belonging to an (presumably aborted) simulation.

Removes all TaskInstances belonging to an (presumably aborted) simulation.

Definition Classes
override
def setLookahead(simulation: String, obj: Lookahead): Unit

Adds / updates the lookahead structure corresponding to a particular actor.

Adds / updates the lookahead structure corresponding to a particular actor.

Value Params
obj

The lookahead structure to be added.

simulation

The name of the simulation that owns the lookahead structure.

Definition Classes

Inherited methods

override
def addTask(task: TaskInstance): Unit

Adds a TaskInstance to be scheduled.

Adds a TaskInstance to be scheduled.

Definition Classes
Inherited from
PriorityScheduler
override
def getTasks(): Iterable[TaskInstance]

Retrieves an iterable collection of queued TaskInstances.

Retrieves an iterable collection of queued TaskInstances.

Definition Classes
Inherited from
PriorityScheduler
def isIdleResource(r: String, resourceMap: Map[String, TaskResource]): Boolean

Checks if a named TaskResource is idle.

Checks if a named TaskResource is idle.

Value Params
r

The name of the TaskResource.

resourceMap

The map of available TaskResources.

Returns

true if the resource is idle, false otherwise.

Inherited from
Scheduler
override
def noMoreTasks(): Boolean

Checks if all Tasks have been scheduled.

Checks if all Tasks have been scheduled.

Definition Classes
Inherited from
PriorityScheduler
override
def removeTask(task: TaskInstance): Unit

Removes a TaskInstance that no longer needs scheduling.

Removes a TaskInstance that no longer needs scheduling.

Definition Classes
Inherited from
PriorityScheduler

Concrete fields

protected
val completed: Set[(UUID, Long)]
protected
val lookaheadObjects: Map[String, Lookahead]

Inherited fields

val tasks: SortedSet[TaskInstance]

A sorted queue of tasks that need to be run.

A sorted queue of tasks that need to be run.

Inherited from
PriorityScheduler