Required Capacity Customization Point

Modifying activity capacity profiles in a customization

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

Creating the Class

To start, we will need to create two new classes that inherit from RequiredCapacityCustomization.  This customization class is located at: PT.Scheduler.Simulation.Customizations.RequiredCapacityCustomization.

Here is what a  basic class should look like:

public class RequiredCapacityCust : RequiredCapacityCustomization
{
//Declare any objects you need in your calculations here

//Customizations must have a name
public override string Name => "Required Capacity";

//Customizations must have a description
public override string Description => "Required Capacity customization used to determine run rate.";

/// <summary>
/// Determine the setup and processing spans of an activity or change the quantity per cycle. This function is called by the
/// scheduler prior to attempting to schedule
/// </summary>
protected override void BeforeRequiredCapacityCalculation(long a_simClock, BaseActivity a_activity, BaseResource a_resource, ref ChangableActivityValues r_changeValues)
{
//Place code here to calculate the related run rate
}

protected override void AfterRequiredCapacityCalculation(BaseActivity a_activity, BaseResource a_resource, RequiredCapacityChangeHelper a_rc, long a_startTicks)
{
//Use a_rc.RequiredCapacityChanger to override setup, run, or post processing

//Set processing to 30 minutes
a_rc.RequiredCapacityChanger.ProcessingSpan = new RequiredSpan(TimeSpan.FromMinutes(30).Ticks, false);

//Update activity comments and set post processing span
//Note that these changes update the activity and operation records resulting in actual data property changes
ActivityValueChanges actChange = new ActivityValueChanges(a_activity as InternalActivity);
actChange.Comments = "Comments";
actChange.Comments2 = "A second comment field";
actChange.PostProcessingSpanChange = TimeSpan.FromMinutes(30); //This will add, not set, 30 minutes to Operation Post Processing duration
a_rc.AddActivityChanges(actChange);
}

/// <summary>
/// This function is called before the system has calculated standard setup time. If a value other null is returned, then the system will use it and
/// skip calculating setup time a second time. Null return value signifies "pass" so system will need to calculate the setup.
/// </summary>
protected override RequiredSpanPlusSetup? CalculateSetup(InternalActivity a_act, InternalResource a_res, long a_startTicks, LeftNeighborSetupValues a_leftNeighborSetupValues)
{
//Place code here to calculate the setup
}

/// <summary>
/// Adjusts the setup time. This is called after setup time has been calculated by standard means and the standard setup is passed to this function. The value returned by this function overrides the standard setup.
/// </summary>
protected override RequiredSpanPlusSetup AdjustSetupTime(InternalActivity a_act, InternalResource a_res, long a_startTicks, RequiredSpanPlusSetup a_setupSpan, LeftNeighborSetupValues a_leftNeighborSetupValues)
{
//Place code here to adjust the setup
}
}

Here we have a few functions that can be overridden to begin customizing at the required capacity customization point:

BeforeRequiredCapacityCalculation can be used to calculate the setup/processing spans or the quantity per cycle of an activity using some custom logic that is not handled by the scheduler. This function can be called multiple times before attempting to schedule an activity. It is advisable to keep this in mind when designing the custom logic. It could slow the simulation considerably. Use this override if you need to set activity quantity per cycle or other properties before the other customization points are called.

AfterRequiredCapacityCalculation can be used to override setup, run, or post processing on the activity. It also allows for updating some activity properties such as comments. This customization point will be the last point called before the activity is scheduled with the calculated spans. Use this point if you need full control over the activity capacity. Note that ActivityValueChanges change properties on the data records which will remain outside of the customization. RequiredCapacityChanger will only change values for this simulation.

CalculateSetup can be used to skip calculating the standard setup time of the activity and use values as calculated by the custom logic of the customization. Use this override if the total setup can be determined by the customization. For example if attributes are calculated in the customization instead of using the standard logic.

AdjustSetupTime is called after the standard setup time has been calculated and can be used to modify the value. Use the override if you need to modify the setup but keep the other standard setup calculations.

Operation field TimeCustomizer, which was previously required for an operation to be processed in this customization point, became obsolete ofter Version 11.37.10

First, let's take a look at the parameters for BeforeRequiredCapacityCalculation:

  • long a_simClock: The ticks of the DateTime the scheduler is attempting to schedule an activity.
  • BaseActivity a_activity: The activity that is attempting to schedule.
  • BaseResource a_res: The resource the scheduler is attempting to schedule on.
  • ref ChangableActivityValues r_changeValues: Allows overriding setup and processing durations along with other activity properties such as comments.

Then let's take a look at the parameters for CaculateSetup:

  • BaseResource a_res: The resource the scheduler is attempting to schedule on.
  • BaseActivity a_activity: The activity that is attempting to schedule.
  •  long a_startTicks: The activity start date time ticks.
  • LeftNeighborSetupValues a_leftNeighborSetupValues: values for the operation scheduled before the activity trying to schedule currently

Then let's take a look at the parameters for AdjustSetupTime:

  • BaseResource a_res: The resource the scheduler is attempting to schedule on.
  • BaseActivity a_activity: The activity that is attempting to schedule.
  •  long a_startTicks: The activity start date time ticks.
  • RequiredSpanPlusSetup a_setupSpan: contains information about the activity's setup
  • LeftNeighborSetupValues a_leftNeighborSetupValues: values for the operation scheduled before the activity trying to schedule currently

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:

Modifying Setup in a customization example