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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Quintiq file version 2.0
#parent: #root
Method VerifyDependentDemand (
  MacroPlan macroplan,
  PeriodTask_MP periodTask,
  ProductInStockingPoint_MP ingredientPisp
)
{
  Description: 'Verify period task has expected dependent demand and whether the dependent demand is adhered to recipe configuration minimum and maximum bound.'
  TextBody:
  [*
    // Verify period task has correct ratio for each input ingredient.
    epsilon := 0.00025;
    
    if( this.Run().AssertNotIsNull( periodTask ) )
    {
      /* Note: min & max bound for metal demo
      Verification method for the min ratio of input ingredient 
      Si = [ input quantity of Si in La Quinta 
              + Input quantity of Scrap 3xxx in La Quinta * Minimum ratio of Si in recipe 3xxx 
              + Input quantity of Scrap 5xxx in La Quinta * Minimum ratio of Si in recipe 5xxx 
              + Input quantity of Prime in La Quinta * Minimum ratio of Si in recipe Prime ] /Total input quantity
      
       Verification method for the max ratio of input ingredient 
      Si = [ input quantity of Si in La Quinta 
              + Input quantity of Scrap 3xxx in La Quinta * Maximum ratio of Si in recipe 3xxx 
              + Input quantity of Scrap 5xxx in La Quinta * Maximum ratio of Si in recipe 5xxx 
              + Input quantity of Prime in La Quinta * Maximum ratio of Si in recipe Prime ] /Total input quantity
      */
      // Get total supply of periodtask
      totalInputQty := sum( periodTask, NewSupply, d, true, d.Quantity() );
      
      // Get recipe-ingredient ratio for input ingredient
      recipe3xxx := macroplan.FindRecipe( '3XXX' ).FindRecipeIngredient( '3XXX', ingredientPisp.ProductID() );
      recipe5xxx := macroplan.FindRecipe( '5XXX' ).FindRecipeIngredient( '5XXX', ingredientPisp.ProductID() );
      recipePrime := macroplan.FindRecipe( 'Prime' ).FindRecipeIngredient( 'Prime', ingredientPisp.ProductID() );
      
      scrap3xxxInPT:= this.GetDependentDemand( periodTask, macroplan.GetProduct( 'Scrap 3XXX' ) );
      scrap5xxxInPT := this.GetDependentDemand( periodTask, macroplan.GetProduct( 'Scrap 5XXX' ) );
      primeInPT := this.GetDependentDemand( periodTask, macroplan.GetProduct( 'Prime' ) );
      
      // Verify the actual ratio is between expected min & expected max
      dd := this.GetDependentDemand( periodTask, ingredientPisp );
      actualRatio := guard( dd.Quantity() / totalInputQty, 0.0 );
      
      scrap3xxx :=  guard( scrap3xxxInPT.Quantity()* recipe3xxx.Minimum(), 0.0 );
      scrap5xxx := guard( scrap5xxxInPT.Quantity() * recipe5xxx.Minimum(), 0.0 );
      prime :=  guard( primeInPT.Quantity() * recipePrime.Minimum(), 0.0 );
      
      expectedMin := ( dd.Quantity() + scrap3xxx + scrap5xxx + prime ) / totalInputQty;
      
      scrap3xxx :=  guard( scrap3xxxInPT.Quantity() * recipe3xxx.Maximum(), 0.0 );
      scrap5xxx :=  guard( scrap5xxxInPT.Quantity() * recipe5xxx.Maximum(), 0.0 );
      prime :=  guard( primeInPT.Quantity() * recipePrime.Maximum(), 0.0 );
      
      expectedMax := ( dd.Quantity() + scrap3xxx + scrap5xxx + prime ) / totalInputQty;
      
      this.Run().AssertGreaterOrEqual( expectedMin, actualRatio, epsilon, 'Verify minimum ratio for ' + ingredientPisp.Name() )
      this.Run().AssertLessOrEqual( expectedMax, actualRatio, epsilon, 'Verify maximum ratio for ' + ingredientPisp.Name() );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}