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
Quintiq file version 2.0
#parent: #root
Method CompleteForSmallPuzzle (
  LibOpt_Task task,
  RunContextForCapacityPlanning runcontext,
  LibOpt_Scope outscope
)
{
  TextBody:
  [*
    threshold_when_to_complete := 0.75; // at 95% of all pit or pto's we just add the rest 
    macroplan := this.Optimization().astype( Optimization ).MacroPlan(); 
    
    nrpispipsinscope := outscope.GetPISPIPInOptimizerRun().Size(); 
    if ( nrpispipsinscope = runcontext.NumberOfPISPIPPlanningGlobal() ) 
    {
      pto := outscope.GetPeriodTaskOperationInOptimizerRun(); 
      nrptoglobal := sum( macroplan, Unit.Operation, op, true, op.PeriodTaskOperation( relsize ) ); 
      if ( pto.Size() < nrptoglobal and pto.Size() >= threshold_when_to_complete * nrptoglobal ) 
      {
        debuginfo(  'Completing operation for small puzzle. Adding # period task:', nrptoglobal - pto.Size() );  
        traverse( macroplan, Unit, unit, unit.IsInOptimizerPuzzle() ) 
        {
          traverse( unit, Operation.PeriodTaskOperation, periodtaskop, periodtaskop.UnitPeriod().Period_MP().IsInOptimizerPuzzle() and 
                    PeriodTaskOperation::GetIsValidPeriodTask( periodtaskop.Operation(), periodtaskop.UnitPeriod().Period_MP() ) ) 
          {
            outscope.Add( periodtaskop ); 
          }
        }
      }
      
      pit := outscope.GetProductInTripInOptimizerRun(); 
      nrpitglobal := sum(  macroplan, Unit.Lane.LaneLeg.Trip, trip, trip.GetIsValidNonFrozenTrip(), trip.ProductInTrip( relsize ) ); 
      if ( pit.Size() < nrpitglobal and pit.Size() >= threshold_when_to_complete * nrpitglobal ) 
      {
        debuginfo(  'Completing product in trips for small puzzle. Adding # pit:', nrpitglobal - pit.Size() ); 
        traverse( macroplan, Unit, unit, unit.IsInOptimizerPuzzle() ) 
        {
          departurecutoff := maxvalue(  unit.EndOfFrozen(), runcontext.FirstPeriod_MP().Start() ); 
          traverse( unit, 
                    Lane.LaneLeg.Trip.ProductInTrip, 
                    prodintrip, 
                    prodintrip.Trip().GetIsValidNonFrozenTrip() 
                    and prodintrip.IsInOptimizerPuzzle()
                    and prodintrip.Trip().Departure() >=  departurecutoff ) 
          {
            outscope.Add( prodintrip ); 
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}