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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Quintiq file version 2.0
#parent: #root
Method CapacityPlanningAlgorithmHandleFeasibleOperationPeriodTask (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  LibOpt_Task task
)
{
  Description: 'Assign the optimal quantity from optimizer for period task planned quantity'
  TextBody:
  [*
    scope := task.Scope(); 
    // Assign PTQty to PeriodTask.OptimizerQuantity.
    if ( this.GetPeriodsFromPeriodTaskOperation() ) 
    {
      traverse( scope.GetPeriodTaskOperationInOptimizerRun(), Elements, pt ) 
      {
        period := pt.UnitPeriod().Period_MP(); 
        operation := pt.Operation(); 
        ptvar := program.PTQtyVariables().Get( operation, period );
        
        quantity := this.GetOptimalValue( ptvar );
        
        if ( pt.Operation().IsBlending() and runcontext.IsMetaIteration() ) // no filtering for numerical sensitive blending operation in meta optimizer
        {
          quantity := this.GetOptimalValueUnfiltered( ptvar ); 
        }
    
        if ( quantity <= 0 ) 
        {
          quantity := 100; 
          quantity := 0.0; 
        }
        
        if ( not ( quantity = 0 and pt.Quantity() = 0 ) ) // if both are 0 we can skip. Otherwise if they are different we clearly need to plan, both even if equal groups may be different 
        {
          this.CapacityPlanningAlgorithmHandleFeasibleOperationPeriodTask_SetPT( program, runcontext, pt, quantity )
        }
      }
    }
    else
    {
      traverse( scope.GetOperationInOptimizerRun(), Elements, operation )
      {
        traverse( operation, Unit.PlanningUnitPeriod, unitperiod )
        {
          period := unitperiod.Period_MP();
          ptvar := program.PTQtyVariables().Find( operation, period );
      
          // if the ptvar is null, then this combination of operation and period is not considered in this optimizer run
          if( not isnull( ptvar ) )
          {
            quantity := this.GetOptimalValue( ptvar );
            if ( quantity <= 0 ) 
            {
              quantity := 100; 
              quantity := 0.0; 
            }
      
            pt := PeriodTaskOperation::FindPeriodTaskOperationTypeIndex( period.Start(), operation.ID() );
      
            if( isnull( pt ) and quantity > 0.0 )     // only create if the period task does not exist and the planned quantity is greater than zero
            {
              pt := PeriodTaskOperation::CreateValidPeriodTask( operation, unitperiod, quantity, false );
            }
            if( not isnull( pt ) )
            {
              this.CapacityPlanningAlgorithmHandleFeasibleOperationPeriodTask_SetPT( program, runcontext, pt, quantity ); 
            }
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}