haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
FunctionOverride CalcEstimate
{
  TextBody:
  [*
    // edz1 Sep-12-2016 (created)
    
    servicelevels := selectset( this, InventorySpecification.InventorySpecificationInServiceLevel.ServiceLevelBase, servicelevel, true );
    deviationfromtarget := 0.0;
    
    // The estimate of the move is equal to the deviation from target of the related service levels
    traverse( servicelevels, Elements, servicelevel )
    {
      // Select the best iteration service level related to this service level
      prevbestitsl := select( servicelevel, IterationServiceLevel, itsl, itsl.Iteration().IsBestIteration() );
      // Calculate the deviation from target
      target := servicelevel.TargetPercentage();
      deviationfromtarget := deviationfromtarget + ( target - guard( prevbestitsl.AchievedServiceLevel(), 0.0 ) );
    }
    
    if( not this.IsIncrease() )
    {
      deviationfromtarget := - deviationfromtarget;
    }
    
    // We use the factor to calculate the average deviation from target over all the service levels impacted by this move 
    // If there is more than 1 service level, then we also multiply the factor by 1.5
    // Otherwise the estimate for this move would always be worse than for a move linking to only one of the service levels
    factor := 1.0
    numberofservicelevels := servicelevels.Size();
    if( numberofservicelevels > 1 )
    {
      factor := pow( [Real]numberofservicelevels, 1/2 ) / numberofservicelevels;
    }
    
    value := factor * deviationfromtarget;
    
    // In reality the move will be too small to reach the target service level
    value := 0.5 * value;
    
    // Reduce the estimate if the last X times that this move was tried it did not find an improvement
    value := this.GetCorrectionEstimateForPreviousFailures() * value;
    
    this.Estimate( value );
  *]
}