MRP Status Tracking for Customizations

How to keep track of MRP optimization status to decide if and when to use customization code during MRP

Tracking the Status

Given the multi-stage nature of MRP Optimization, it may be required to run a customization only during a specific stage of the Optimization process. To track MRP status, it is possible to subscribe to an event during the simulation initialization. This has to be done within a Schedulability Customization point. The following code snippet shows how it can be accomplished:

Note: for more information on this customization point, you can take a look at our article on the Schulability Customization Point

private bool m_initialized;

protected override void SimulationInitialization(ScenarioDetail a_sd, SchedulabilitySimulationInitializationHelper a_schedulabilityHelper, ScenarioDetail.SimulationType a_simulationType, ScenarioBaseT a_transmission)
{
if (!m_initialized)
{
using (var seoa = a_sd.Scenario.ScenarioEventsLock.EnterWrite())
{
seoa.Instance.MRPStatusUpdateEvent += MRPStatusUpdateEventHandler;
}

//Set initialized to true to prevent multiple subscriptions to the same event
m_initialized = true;
}
}

private SimulationProgress.Status m_mrpStatusCode;
public SimulationProgress.Status MRPStatusCode
{
get { return m_mrpStatusCode; }
}

/// <summary>
/// Update MRP status
/// </summary>
/// <param name="a_statusCode"></param>
/// <param name="a_detailParams"></param>
private void MRPStatusUpdateEventHandler(SimulationProgress.Status a_statusCode, object[] a_detailParams)
{
if (!Enabled)
{
a_statusCode = SimulationProgress.Status.Clear;
}

m_mrpStatusCode= a_statusCode;
}

Using the MRP Status Code

Now that we have the MRP status code handy, we can use it to check if the customization code needs to be executed. Below is an example of how we would use in the EndOfSimulationCleanup function within the EndOfSimulation Customization point:

Note: for more info on this customization point, you can take a look at our article on the EndOfSimulation Customization Point


private SchedulabilityCustomization m_schedulabilityCust;

protected override void EndOfSimulationCleanup(ScenarioDetail.SimulationType a_simType, ScenarioBaseT a_t, ScenarioDetail a_sd)
{
m_schedulabilityCust = a_sd.CustomizationInstances.SchedulabilityCustomization;
if (m_schedulabilityCust == null)
{
return;
}

//Customization applies only to Optimize and last Optimize of an MRP simulations
if (a_simType == ScenarioDetail.SimulationType.Optimize)
{
if (a_t is ScenarioDetailOptimizeT optimizeT && optimizeT.RunMRP)
{
if (m_schedulabilityCust.MRPStatusCode == SimulationProgress.Status.MRP_StartFinalOptimize)
{
PerformSomePostSimProcess(a_sd);
}
}
else
{
PerformSomePostSimProcess(a_sd);
}
}
}

Next Steps

Explore the following articles to learn all there is to know about customization projects in PlanetTogether:

Getting started with customizations

Advanced topics

Coming Soon...