| Quintiq file version 2.0 | 
| #parent: #root | 
| Function CalcQuantityToMove | 
| { | 
|   TextBody: | 
|   [* | 
|     // cye1 Jan-20-2017 (created) | 
|      | 
|     value := 0.0; | 
|     bestitsl := select( this, IterationServiceLevel, itsl, itsl.Iteration().IsBestIteration() ); | 
|     targetsl := this.TargetPercentage(); | 
|      | 
|       if( not isnull( bestitsl ) ) | 
|       { | 
|         // Select all simulation pispips that are related to this service level that had unfilfilled demand in the best run | 
|         simpispips := selectset( bestitsl, IterationPISPIP.SimulationPISPIP, simpispip, | 
|                                  guard( simpispip.ProductInStockingPointInPeriodPlanningLeaf().GetServiceLevel() = this, false )  // Only evaluate the pispips that are related to the service level | 
|                                );   | 
|          | 
|         if( exists( simpispips, Elements, simpisp, simpisp.HasUnfulfilledDemand() ) ) | 
|         { | 
|           // The average shortage in the pispips with a shortage | 
|           averageshortage := average( simpispips, Elements, simpispip, simpispip.HasUnfulfilledDemand(), simpispip.UnfulfilledDemandQty() ); | 
|            | 
|           // The desired total shortage is ( 100% - target servicelevel ) * total demand | 
|           desiredtotalshortage := ( ( 100.0 - targetsl ) / 100.0 ) * sum( simpispips, Elements, simpispip, | 
|                                                                          simpispip.SalesDemandQty() ); | 
|            | 
|           // The desired average shortage is then the desired total shortage divided by the number of pispips with a shortage | 
|           // Please note that this will undersestimate the new shortage since some of these pispips may only have a very small unfulfilled demand | 
|           desiredavgshortage := desiredtotalshortage / simpispips.Size(); | 
|           value := averageshortage - desiredavgshortage; | 
|          | 
|         } | 
|      | 
|     } | 
|      | 
|     this.QuantityToMove( value ); | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |