yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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' }
}