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
Quintiq file version 2.0
#parent: #root
Function CalcLotSizeViolationContinuous
{
  TextBody:
  [*
    process := this.PeriodTask_MP().Process_MP();
    pisp := guard( this.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP(), null( ProductInStockingPoint_MP ) );
    period := guard( this.PeriodTask_MP().UnitPeriod().Period_MP(), null( Period_MP ) );
    
    value := 0.0; 
    if( guard( process.HasInputLotSize()
               and pisp.HasInputLotSize()                     // To prevent division by zero
               and period.IsWithinLotSizeHorizon(),       // Only check within the lotsize horizon
               false )
       )  
    {
      quantitytotal := sum( this, ProductInStockingPointInPeriodPlanningLeaf.DependentDemand, dd, dd.ProcessInput() = this.ProcessInput(), dd.Quantity() ); 
      
      // calculate distance to the nearest lot. 
      lotsize := pisp.PISPSpecification().InputLotSize(); 
      requiredlot := Util::Ceil( quantitytotal /  lotsize ); 
      load := lotsize * requiredlot; 
      diff1 := load - quantitytotal; 
      diff2 := abs(  ( load - lotsize ) - quantitytotal ); 
      value := minvalue(  diff1, diff2 ); 
      
      value := value * this.PeriodTask_MP().UnitPeriod().Unit().DefaultUOMConversionFactor()
    }
    this.LotSizeViolationContinuous( value );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}