| 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' } | 
| } |