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
Quintiq file version 2.0
#parent: #root
Method FreezeVariablesForPostponedSalesDemands (
  const CapacityPlanningSuboptimizer subopt,
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  Description:
  [*
    Generic method to freeze delayed salesdemand MathematicalProgram variables
    It can be used for LeafSalesDemandInPeriod, AggregatedSalesDemandInPeriod
  *]
  TextBody:
  [*
    varmpvariable := null( MPVariable );
    
    if( this.CanBePostponed() and this.NeedsToBePlanned() )
    {
      nextpispip := this.AsPlanningBaseSalesDemandInPeriod().NextPlanningPISPIP();
      // First set all variables to 0.0
      for( i := 1;
           i <= this.MaxPostponementPeriod()                  // within the maximum number of postponement periods
           and not isnull( nextpispip );                      // the next pispip exists
           i++ )
      {
        if( scope.Contains( nextpispip.PISPIPInOptimizerRun() ) )
        {
          varmpvariable := this.GetDelayedSalesDemandQtyVariable( program, nextpispip.Period_MP() );
          if( not isnull( varmpvariable ) )
          {
            subopt.FreezeVariableLowerUpperBound( varmpvariable, 0.0, 0.0 );
          }
        }
        nextpispip := nextpispip.NextPlanningPISPIP();
      }
      
      // If there are already postponed sales demand instances, then freeze variables to optimizer fulfilled quantity 
      traverse( this, AllPostponedSalesDemand, psd )
      {
        period := guard( psd.AsSalesDemandInPeriodBase().Period_MP(), constnull( Period_MP ) );
        if( not isnull(  period ) )
        {
          varmpvariable := this.GetDelayedSalesDemandQtyVariable( program, nextpispip.Period_MP() );
          if( not isnull( varmpvariable ) )
          {
            subopt.FreezeVariableLowerUpperBound( varmpvariable, psd.OptimizerFulfilledQuantity(), psd.OptimizerFulfilledQuantity() );
          }
        }
      } 
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}