chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method CompleteForCampaignSequencingSimple (
  SelectorMeta selectormeta,
  RunContextMeta rcm,
  RunContextForCapacityPlanning runcontext
)
{
  TextBody:
  [*
    // this method is added for efficiency of the meta optimizer. We want to limit the duplicate calls to add operations, unitperiods, unit and trip. So we do this all the way at the end
    // based on period tasks and product in trips added 
    
    sequencecampaigns := runcontext.UseCampaignSequenceOptimizer() and runcontext.UseCampaign(); 
    if ( sequencecampaigns ) 
    {
      mp := runcontext.FirstPeriod_MP().MacroPlan(); 
      traverse( mp, Optimization.OptCampaignCampaignType, ctype ) 
      {
        ctype.IsActive( false ); 
      }
      unitswithperiodsinscope := construct( Units ); 
      anchorsforupstream := construct( ProductInStockingPointInPeriodPlanningLeafs ); 
      traverse( this.GetUnitInOptimizerRun(), Elements, unit, unit.HasCampaignType() ) 
      {
        traverse( unit, UnitPeriod, up, up.IsPlanning() and not up.IsPeriodFrozen() and not up.Period_MP().IsHistorical() ) 
        {
          unitswithperiodsinscope.Add( unit ); 
          this.Add( up ); 
          
          traverse( up, PeriodTaskOperation, pto, PeriodTaskOperation::GetIsValidPeriodTask( pto.Operation(), pto.UnitPeriod().Period_MP() ) ) 
          {
            this.Add( pto ); 
            this.Add( pto.Operation() ); 
            traverse( pto, DependentDemand.ProductInStockingPointInPeriodPlanningLeaf, pispip ) 
            {
              this.Add( pispip ); 
              anchorsforupstream.Add( pispip ); 
              this.Add( pispip.StockingPointInPeriod() ); 
              this.Add( pispip.Period_MP() ); 
            }
            traverse( pto, NewSupply.ProductInStockingPointInPeriodPlanningLeaf, pispip ) 
            {
              this.Add(  pispip ); 
              this.Add(  pispip.StockingPointInPeriod() ); 
              this.Add( pispip.Period_MP() ); 
            }
          } // end traverse period task 
        } // end traverse unit period
      } // end traverse unit with campaign type
      
      selectormeta.PISPGapFill( this, runcontext );
      
      unitswithperiodsinscope := unitswithperiodsinscope.Unique(); 
      unitswithperiodsinscope := selectsortedset(  unitswithperiodsinscope, Elements, unit, true, Real::Random() ); 
      maxnrcampaigntypesinscope := rcm.OptionMaxNrCampaignTypeActivePerUnit() ; 
    
      traverse( unitswithperiodsinscope, Elements, unit ) 
      {
        optcampaigntypes := selectsortedset(  unit, CampaignType_MP.OptCampaignCampaignType, ctype, true, Real::Random() ); 
        activenrofcampaignsforunit := Number::Random(0, maxnrcampaigntypesinscope ); 
        optcampaigntypes := optcampaigntypes.SelectFirst( activenrofcampaignsforunit ); 
        debuginfo(  'unit:', unit.Name(), 'active nr of campaigns = ', optcampaigntypes.Size() ); 
        traverse( optcampaigntypes, Elements, ctype ) 
        {
          debuginfo(  'Activating campaign ', ctype.Name() ); 
          ctype.IsActive( true ); 
        }
      }
      mp.Optimization().CampaignCombiGeneration().OptCampaign().SetIsActiveStatusCombis( rcm.OptionActiveWindowSizeCampaignOptimization(), this ); 
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}