Schedulability Customization Point

Adding custom logic to allow or prevent an activity from scheduling

This guide will step through the process of coding a Schedulability customization. If you are just getting started, you can learn about getting started with customizations

Creating the Class

To use custom logic for scheduling activities we will need to create a new class that inherits from SchedulabilityCustomization. This customization class is located at: PT.Scheduler.Simulation.Customizations.Schedulability

Here is what a basic class should look like:

public class CustomOverlap : SchedulabilityCustomization
{
//Declare any objects for the customization here

//Customizations must have a name
public override string Name => "Custom scheduling";

//Customizations must have a description
public override string Description => "Performs custom scheduling logic";

/// <summary>
/// This function is called by the scheduler before a simulation starts
/// It is useful to override this function to iterate through data objects and create some data mappings
/// that could be accessed later to perform the custom logic
/// </summary>
protected override void SimulationInitialization(ScenarioDetail a_sd, SchedulabilitySimulationInitializationHelper a_schedulabilityHelper, ScenarioDetail.SimulationType a_simulationType, ScenarioBaseT a_transmission)
{
//Create some mapping that can be used in the IsSchedulable function later
}

/// <summary>
/// This function is called by the scheduler when it is attempting to schedule an activity on a resource
/// Return true if the custom conditions are met; otherwise return false to attempt gain at a later time.
/// </summary>
protected override bool IsSchedulable(ScenarioDetail a_sd, ScenarioDetail.SimulationType a_simType, long a_clock, long a_simulationClock, BaseResource a_res, BaseActivity a_activity, SchedulableInfo a_schedulableInfo, out long o_postEventTime)
{
//This out value of type long is needed to let the scheduler know when to attempt scheduling again if conditions aren't met.
o_postEventTime = -1;

//Custom code goes here

if ( /*some condition met..*/)
{
return true;
}

o_postEventTime = some custom value;
return false;
}
}

 

Here we have two functions to override to begin customizing at the schedulability point:

SimulationInitialization can be used to override the Simulation Initialization as the name implies. This is useful for building a data mapping to use in IsSchedulable; caching data in a mapping dictionary could greatly improve the efficiency of the customization.

IsSchedulable can be used to add extra rules and conditions to allow or not allow the scheduler to schedule an activity. Note that returning true does not guarantee an activity being scheduled; the activity may yet fail to schedule due to some scheduler reasons outside the scope of the customization. 

 

First let's take a look at the parameters for SimulationInitialization.

  • ScenarioDetail a_sd: Via the various manager objects in this top level object, all other data objects can be accessed.
  • SchedulabilitySimulationInitializationHelper a_schedulabilityHelper: Provides change helper classes for activities and capacity intervals.
  • ScenarioDetail.SimulationType a_simulationType: The type of simulation that is being run.
  • ScenarioBaseT a_transmission: The transmission being processed.

 

Then let's take a look at the parameters for IsSchedulable.

  • ScenarioDetail a_sd: Via the various manager objects in this top level object, all other data objects can be accessed.
  • long a_clock: The ticks of the scenario clock date.
  • long a_simulationClock: The ticks of the DateTime the scheduler is attempting to schedule an activity.
  • BaseResource a_res: The resource the scheduler is attempting to schedule on.
  • BaseActivity a_activity: The activity that is attempting to schedule.
  • SchedulableInfo a_schedulableInfo: Defines the possible scheduling result of an activity on this result. The primary resource requirement is used to calculate.
  • out long o_postEventTime: Lets the scheduler know when to attempt scheduling again if conditions aren't met. Setting the value to -1 tells the scheduler to decide when to try again based on some internal conditions.

Next Steps

Explore the following articles to see an example of how this customization point can be used,  meet other types of scheduling requirements or to learn how to better navigate the PlanetTogether data objects explore the following articles:

 

Coming Soon...