admin
2025-01-22 7e31442f0e9b07764e9c6a9680d3d4aeba5fe1de
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
52
Quintiq file version 2.0
#parent: #root
Method Stockin (
  ProductInStockingPoint_MP pisp,
  Number period,
  Real target
) as Real
{
  Description: 'Ask Quintiq for the predicted service level of a PISP, period and specific target.'
  TextBody:
  [*
    // this will calculate the service level
    
    // on leaf location, simply call stockin_leaf and store the distributions for new supply and starting stock  
    
    stockin_p := -1.0; // reset in both branches
    pispip := pisp.GetPISPIPFromPeriodNumber( period ); 
    
    if ( pisp.MEIO_IsLeaf() ) 
    {
      stockin_p := this.StockinLeaf( pisp, period, target ); 
    }
    else // if location is not leaf, we take weighted average of the child nodes on the periods that are period+leadtimeToChild for each child
    {
      weighted := 0.0; 
      totalDemand := 0.0; 
      pispip.MEIO_Target( target ); 
      traverse( MEIO_Engine::GetTreePISP( pisp ), Elements, child ) 
      {
        period_scope := period +this.GetLeadTime( child, pisp )
        if( period_scope <= this.LastPeriodNumber() )
        {
          totalDemand := totalDemand + MEIO_Engine::GetDemandExpectedValue( child, period_scope ); 
          mytarget := child.GetPISPIPFromPeriodNumber( period_scope ).MEIO_Target(); 
          weighted := weighted 
                      + ( MEIO_Engine::GetDemandExpectedValue( child, period_scope ) 
                          * this.StockinLeaf( child, period_scope, mytarget  ) ) 
        }
      }
      if( totalDemand > 0)
      {
        stockin_p := weighted / totalDemand  
      }
      else
      {
        stockin_p := 1
      } 
    }
    pispip.MEIO_Stockin( stockin_p);
    return stockin_p
  *]
}