| Quintiq file version 2.0 | 
| #parent: #root | 
| Method CreateGapPlanningFromPeriod ( | 
|   Period_MP baseperiod | 
| ) as Period_MP | 
| { | 
|   Description: 'Create a gap planning period from a base period for which no planning period exists.' | 
|   TextBody: | 
|   [* | 
|     // ODE2 May-23-2017 (created) | 
|      | 
|     startofplanning := this.PeriodParameter_MP().StartOfPlanning(); | 
|      | 
|     baseperiod.IsIncludedInGapPlanningPeriod( true ); | 
|      | 
|     start := baseperiod.Start(); | 
|     end := baseperiod.End(); | 
|     currentplanningps := PeriodSpecification_MP::GetLowestLevelPlanningPeriodSpecification( baseperiod ); | 
|      | 
|     baseperiodnext := baseperiod.NextBasePeriod(); | 
|     nextplanningps := PeriodSpecification_MP::GetLowestLevelPlanningPeriodSpecification( baseperiodnext ); | 
|      | 
|     while( guard( this.GetHasPlanningPeriodSpecification( baseperiodnext.Start(), baseperiodnext.End() )          // Gap periods only get created on horizons for which planning periods are defined | 
|                   and not exists( this, PeriodSpecification_MP, ps,  | 
|                                   ps.HasInclusivePlanningPeriod( baseperiodnext.Start(), baseperiodnext.End() ) ) // No planning period on the considered horizon | 
|                   and not baseperiodnext.Start() = startofplanning                                                // If accross start of planning, gap period should be split into 2 periods  | 
|                   and currentplanningps = nextplanningps,  | 
|                   false ) ) | 
|     { | 
|       // Tag period as included in a gap to avoid re-creating a gap from that period in a future iteration | 
|       baseperiodnext.IsIncludedInGapPlanningPeriod( true );  | 
|       currentplanningps := PeriodSpecification_MP::GetLowestLevelPlanningPeriodSpecification( baseperiodnext ); | 
|       end := baseperiodnext.End(); | 
|        | 
|       baseperiodnext := baseperiodnext.NextBasePeriod(); | 
|       nextplanningps := PeriodSpecification_MP::GetLowestLevelPlanningPeriodSpecification( baseperiodnext ); | 
|     } | 
|      | 
|     // Create gap planning period | 
|     gapplanningperiod := this.CreateUpdateGapPlanningPeriod( start, end ); | 
|      | 
|     return gapplanningperiod; | 
|   *] | 
| } |