yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
Quintiq file version 2.0
#parent: #root
Method ExtendCombi
{
  TextBody:
  [*
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    //If the campaign or transition that starts the combi has a max duration then we need combis for 
    //each subperiod up till the max dutation ending with each possible transition like: 
    //A | A-> B (both in the same period
    //A | A | A-> B
    //A | A | A | A-> B
    //
    //
    //If the campaign or tranisit that starts the combi has a min duration and no max duration then we
    //want a mid combi which exist of a single subperiod with the campaign/transition and a combi with
    //the min duration. Which campaign A minduration is 2 days this looks like:
    //A 
    //A | A : A-> B 
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    
    lastelement := this.LastCombiElement();      
    hasminduration := this.HasminDurationCombi();
    hasmaxduration := this.HasMaxDurationCombi();
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    //If the combi does not have a max duration then we need one combi with a single element so we need
    //to duplicate the combi here to preserve the single element combi
    ///////////////////////////////////////////////////////////////////////////////////////////////////
    if( not this.HasFixedStartAndDuration()
        and this.OptCampaignCombiElement( relsize ) = 1 
        and not this.HasMaxDurationCombi()
      )
    {
      singlecombi := this.DuplicateCombi();
      singlecombi.IsCompleteCombi( true );  
    }
    
    
    //For debugging
    /*
    this.CalcName();
    if( this.OptCampaignUnitSubPeriod().StartTime().Date() = Date::Construct( 2018,1,1) )
    {
      info(  this.Name()
             , hasminduration 
             , this.MaxEndTimeFirstElement(), this.MaxEndTimeFirstElement() , lastelement.OptCampaignUnitSubPeriod().EndTime()
             , this.NeedsExtensionElement()
             , this.NeedsExtensionSubPeriod()
             ) 
    }
    */
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //If the combi has a min and or maxduration it and the duration is longer than the last subperiod added then the
    //combi needs to be extended with an additional subperiod.
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if( this.NeedsExtensionSubPeriod() )
    {
      //If the last element is longer than the period add the same element again but the attached to the next period
      if( hasmaxduration )
      {
        if( not hasminduration 
            or ( hasminduration and lastelement.OptCampaignUnitSubPeriod().EndTime() >= this.MinEndTimeFirstElement() ) )
        {
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          //Duplicate the combi if it is longer than minduration. The original will be used to grow with more 
          //subperiods. The copy is used to complete the combi with the next element in the last periodthis.MinEndTimeFirstElement()
          ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
          combi := this.DuplicateCombi();
          combi.ExtendCombiwithNextElement();
        }
      }
      //Add the next subperiod with the same element type
      this.ExtendCombiWithNextSubPeriod();
    }
    else if( this.NeedsExtensionElement() )
    {
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
      //if there is already a 2nd element type in the combi then every extensions requires a duplicate to keep track of 
      //all possible combination.
      ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
      if( not lastelement.IsFirstElementTypeInCombi() )
      {
        combi := this.DuplicateCombi();
        combi.IsCompleteCombi( true );
      }
      this.ExtendCombiwithNextElement();
      
    }
    else
    {
      this.IsCompleteCombi( true );  
    }
  *]
}