yanyuan
2023-11-10 143ef74e2eeee697ac8fda3d9032a790fbb4e146
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
42
43
44
45
46
47
48
49
50
51
Quintiq file version 2.0
#parent: #root
Function CalcStandardDeviationServiceLevel
{
  TextBody:
  [*
    // Calculate the standard deviation of this service level
    achievedservicelevels := construct( Reals );
    
    // Traverse all Iterations' Simulations
    traverse( this, Iteration.Simulation, simulation )
    {
      totaldemand := 0.0;
      totalunfulfilleddemand := 0.0;
      
      // Traverse all SimulationPISPIP that belongs to the current Simulation
      traverse( this, IterationPISPIP.SimulationPISPIP, simpispip,
                simpispip.Simulation() = simulation )
      {
        // Add the SalesDemandQty & UnfulfilledDemandQty of the current SimulationPISPIP to the total variable respectively
        totaldemand := totaldemand + simpispip.SalesDemandQty();
        totalunfulfilleddemand := totalunfulfilleddemand + simpispip.UnfulfilledDemandQty();
      }
      
      // Default simulation service level to 100
      simservicelevel := 100.0;
      // Check if the current simulation has total demand larger than zero
      if( totaldemand > 0.0 )
      {
        // Calculate the simulation service level
        simservicelevel := 100 * ( 1.0 - totalunfulfilleddemand / totaldemand );
      }
      
      // Add the simulation service level to the set
      achievedservicelevels.Add( simservicelevel );
    }
    
    // Calculate the standard deviation of this service level with the set of achieved service levels
    averageservicelevel := average( achievedservicelevels, Elements, sl, sl );
    nrsimulations := achievedservicelevels.Size();
    standarddeviation := 0.0;
    if( nrsimulations > 0 )
    {
      standarddeviation := sqrt( sum( achievedservicelevels, Elements, sl,
                                      pow( sl - averageservicelevel, 2.0 ) )
                                 / achievedservicelevels.Size() );
    }
    
    this.StandardDeviationServiceLevel( standarddeviation );
  *]
}