Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CompleteCombiForLastPeriod ( 
 | 
  OptCampaignCombi combi, 
 | 
  output Campaign_MPs campaigns, 
 | 
  output Transition_MPs transitions 
 | 
) 
 | 
{ 
 | 
  Description: 'added combi transition and campaigns for last period of multiperiod combi' 
 | 
  TextBody: 
 | 
  [* 
 | 
    if ( not isnull( combi ) )  
 | 
    { 
 | 
      lastocusp := combi.LastCombiElement().OptCampaignUnitSubPeriod();  
 | 
      assert( not isnull( lastocusp ), 'expecting last combi element sub period is set' );  
 | 
      // keep adding campaign / transitions for as longs as they end within lastocusp 
 | 
      done := false;  
 | 
      while( campaigns.Size() + transitions.Size() > 0 and not done )  
 | 
      { 
 | 
        firstcampaign := guard( campaigns.Element( 0 ), null( Campaign_MP ) ); 
 | 
        firsttransition := guard( transitions.Element( 0 ), null( Transition_MP ) );   
 | 
        if ( isnull( firstcampaign ) )  
 | 
        { 
 | 
          combi.AddCombiElementTransition( firsttransition.TransitionType_MP(), lastocusp );  
 | 
          if ( firsttransition.End() <= lastocusp.EndTime() )  
 | 
          { 
 | 
            transitions.Remove( firsttransition ); // no need to continue anymore in next sub period  
 | 
          } 
 | 
          done := true;  
 | 
        } 
 | 
        else 
 | 
        { 
 | 
          if ( isnull( firsttransition ) )  
 | 
          { 
 | 
            combi.AddCombiElementCampaign( firstcampaign.CampaignType_MP(), lastocusp );  
 | 
            if ( firstcampaign.End() <= lastocusp.EndTime() )  
 | 
            { 
 | 
              campaigns.Remove( firstcampaign );  
 | 
            } 
 | 
            done := true;  
 | 
          } 
 | 
          else  
 | 
          { 
 | 
            // we still have both campaigns and transitions 
 | 
            if ( firstcampaign.Start() < firsttransition.Start() )  
 | 
            { 
 | 
              combi.AddCombiElementCampaign( firstcampaign.CampaignType_MP(), lastocusp );  
 | 
               
 | 
              done := firstcampaign.End() >= lastocusp.EndTime();  
 | 
              if ( firstcampaign.End() > lastocusp.EndTime() )  
 | 
              { 
 | 
                // don't remove campaign - need to continue with it next period(s).  
 | 
              } 
 | 
              else if ( firstcampaign.End() = lastocusp.EndTime() )   // special case of ending right at period end.  
 | 
              { 
 | 
                campaigns.Remove( firstcampaign );  
 | 
                // add combi element so it matches with the next period combi - but disallowed nonzero duration because this will lead to a mismatch if current combi start with same elt 
 | 
                elt := combi.AddCombiElementTransition( firsttransition.TransitionType_MP(), lastocusp );  
 | 
                elt.DebugFixEndDuration( true );  
 | 
                elt.DebugDurationOfCampaignElementTypeEndVariables( 0.0 );  
 | 
              } 
 | 
              else 
 | 
              { 
 | 
                campaigns.Remove( firstcampaign ); // campaign ending strictly before end of period, continue completing combi 
 | 
              } 
 | 
            }                                        
 | 
            else 
 | 
            { 
 | 
              combi.AddCombiElementTransition( firsttransition.TransitionType_MP(), lastocusp );  
 | 
              done := firsttransition.End() >= lastocusp.EndTime();  
 | 
              if ( firsttransition.End() > lastocusp.EndTime() ) 
 | 
              { 
 | 
                // don't remove transition - need to continue with it next period(s) 
 | 
              } 
 | 
              else if ( firsttransition.End() = lastocusp.EndTime() )    // special case of ending right at period end.  
 | 
              { 
 | 
                transitions.Remove( firsttransition );  
 | 
                // add combi element so it matches with the next period combi - but disallowed nonzero duration because this will lead to a mismatch if current combi start with same elt 
 | 
                elt := combi.AddCombiElementCampaign( firstcampaign.CampaignType_MP(), lastocusp ); 
 | 
                elt.DebugFixEndDuration( true );  
 | 
                elt.DebugDurationOfCampaignElementTypeEndVariables( 0.0 );       
 | 
              } 
 | 
              else 
 | 
              { 
 | 
                transitions.Remove( firsttransition ); // transition ending strictly before end of period, continue completing combi 
 | 
              }  
 | 
            } 
 | 
          }   
 | 
        }    
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
  InterfaceProperties { Accessibility: 'Module' } 
 | 
} 
 |