Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
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' }
}