Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CreatePeriodTaskInCombiElements ( 
 | 
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, 
 | 
  CapacityPlanningSuboptimizer suboptimizer 
 | 
) 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    traverse( this, OptCampaignCombiElement, combielement ) 
 | 
    { 
 | 
      optelementtype := combielement.OptCampaignElementType(); 
 | 
       
 | 
      traverse( optelementtype, OptCampaignOperationInElementType, optoperationinelementtype ) 
 | 
      { 
 | 
        operation := optoperationinelementtype.Operation(); 
 | 
        combielementoptsubunitperiod := combielement.OptCampaignUnitSubPeriod(); 
 | 
         
 | 
        varptqtyinelementtypestart := program.PTQtyInCampaignElementTypeStartVariables().Get( optoperationinelementtype, combielementoptsubunitperiod ); 
 | 
        quantitystart := suboptimizer.GetOptimalValue( varptqtyinelementtypestart ); 
 | 
         
 | 
        varptqtyinelementtypemid := program.PTQtyInCampaignElementTypeMidVariables().Get( optoperationinelementtype, combielementoptsubunitperiod ); 
 | 
        quantitymid := suboptimizer.GetOptimalValue( varptqtyinelementtypemid ); 
 | 
         
 | 
        varptqtyinelementtypeend := program.PTQtyInCampaignElementTypeEndVariables().Get( optoperationinelementtype, combielementoptsubunitperiod ); 
 | 
        quantityend := suboptimizer.GetOptimalValue( varptqtyinelementtypeend ); 
 | 
         
 | 
        finalquantity := 0.0; 
 | 
         
 | 
        if( combielement.IsFirstElementInUnitSubPeriod() 
 | 
            and combielement.IsLastElementInUnitSubPeriod() ) 
 | 
        { 
 | 
          // Sum all the quantities in an OptSubUnitPeriod if a element spans the whole OptSubUnitPeriod 
 | 
          finalquantity := quantitystart + quantityend; 
 | 
        }  
 | 
        else if( combielement.IsFirstElementInUnitSubPeriod() ) // first not last 
 | 
        { 
 | 
          // Set the quantity to the value of the variable PTQtyInElementTypeStart if an OptCampaignCombiElement is the first element of an OptSubUnitPeriod 
 | 
          finalquantity := quantitystart; 
 | 
        } 
 | 
        else if( combielement.IsLastElementInUnitSubPeriod() ) // last not first 
 | 
        { 
 | 
          // Set the quantity to the value of the variable PTQtyInElementTypeEnd if an OptCampaignCombiElement is the last element of an OptSubUnitPeriod 
 | 
          finalquantity := quantityend; 
 | 
        } 
 | 
        else // middle element  
 | 
        { 
 | 
          // Distribute the quantity evenly 
 | 
          nrofmidelements := counter( this, OptCampaignCombiElement, ele, 
 | 
                                      not ele.IsFirstElementInUnitSubPeriod() 
 | 
                                      and not ele.IsLastElementInUnitSubPeriod() 
 | 
                                      and ele.OptCampaignUnitSubPeriod() = combielementoptsubunitperiod 
 | 
                                      and ele.OptCampaignElementType() = optelementtype );       
 | 
          finalquantity := quantitymid / nrofmidelements; 
 | 
        } 
 | 
         
 | 
        optperiodtaskincombielement := OptCampaignPeriodTaskInCombiElement::Create( combielement, operation ); 
 | 
        optperiodtaskincombielement.Quantity( finalquantity ); 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |