Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method GetDurationInCampaignUnitSubPeriod ( 
 | 
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, 
 | 
  CapacityPlanningSuboptimizer subopt 
 | 
) as Duration 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    //First element, so first should be set 
 | 
    elduration := Duration::Zero();  
 | 
    ocet := this.OptCampaignElementType();   
 | 
    subperiod := this.OptCampaignUnitSubPeriod();  
 | 
     
 | 
    if( this.IsFirstElementInUnitSubPeriod() ) 
 | 
    { 
 | 
      durationvar := program.DurationOfCampaignElementTypeStartVariables().Get( ocet, subperiod ) 
 | 
      elduration := Duration::Hours( subopt.GetOptimalValue( durationvar ) ); 
 | 
    } 
 | 
     
 | 
    if ( this.IsLastElementInUnitSubPeriod() )  
 | 
    { 
 | 
      durationvarend := program.DurationOfCampaignElementTypeEndVariables().Get( ocet, subperiod ) 
 | 
      elduration := elduration + Duration::Hours( subopt.GetOptimalValue( durationvarend ) ); // add because for special case of both first and last of sub period we need 'start' + 'end' 
 | 
    } 
 | 
     
 | 
    if ( this.IsMiddleElementInUnitSubPeriod() )  
 | 
    { 
 | 
      durationvar := program.DurationOfCampaignElementTypeMidVariables().Get( ocet, subperiod ) 
 | 
      elduration := Duration::Hours( subopt.GetOptimalValue( durationvar ) ); 
 | 
       
 | 
      //Note the exception case in which we have multiple of the same elementtypes in the mid part of the combi 
 | 
      nrelevar := program.NrOfCampaignElementWithinUnitSubPeriodVariables().Get( ocet, subperiod ) 
 | 
      nrOfSameElements := subopt.GetOptimalValue( nrelevar ); 
 | 
      elduration := elduration / nrOfSameElements; 
 | 
    } 
 | 
    return elduration; 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |