Kevin Kok Khah Whey
2023-11-07 5ae534ab606e6f2ba5ea60914224d665b0447d5a
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
97
98
99
100
101
102
103
104
105
106
107
108
Quintiq file version 2.0
#parent: #root
Method FixDecisionVariablesToCurrentPlanBasedOnLevel (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    /*
    subopt := this; 
    mustfixduetocurrentlevel := (subopt.CurrentLevel() + 1 < subopt.FocusLevel() );
    
    msg :=  'Must fix decision vars:' + [String] mustfixduetocurrentlevel +   ' level = '+ [String] (subopt.CurrentLevel()+1) + String::NewLine(); 
    userperiodtasks := selectset(  runcontext, UserPeriodTask, pto, true, true ); 
    nrfixed := 0; 
    nrunfixed := 0; 
    traverse( this.GetOperationInOptimizerRun(), Elements, operation ) 
    {
      periods := subopt.GetPeriodsForOperation( scope, operation );
      traverse( periods, Elements, period ) 
      {
        var := program.PTQtyVariables().Get( operation, period );
        if ( mustfixduetocurrentlevel ) 
        {
            // Freeze the user planning period tasks
           
           pt := select( operation, PeriodTaskOperation, po, true, po.UnitPeriod().Period_MP() = period ); 
           valuetofix := guard( pt.Quantity(), 0.0 ); 
           subopt.FixVariableStyleGuide( var, valuetofix );
           nrfixed++; 
        }
        else
        {
          this.SetPTQtyVariableProperties( scope, runcontext, userperiodtasks, operation, period, var ); 
          nrunfixed++; 
        }
      }
    }
    
    this.FixUserPeriodTask( userperiodtasks, program ); // don't alter the user period task operations
    
    msg := msg + 'ops fixed, unfixed= ' + [String]nrfixed + ','+ [String] nrunfixed + String::NewLine();
    
    // fixing trips 
    nrfixed := 0; 
    nrunfixed := 0; 
    traverse( scope.GetProductInTripInOptimizerRun(), Elements, productintrip )
    {
      var := program.TripNewSupplyVariables().Get( productintrip ); 
      if ( mustfixduetocurrentlevel ) 
      {
        subopt.FixVariableStyleGuide( var, productintrip.Quantity() );
        nrfixed++; 
      }
      else
      {
        var.LowerBound( productintrip.PITVarInitLowerBound() ); 
        var.UpperBound( productintrip.PITVarInitUpperBound() );
        nrunfixed++; 
      }
    }
    msg := msg + 'trips fixed, unfixed= ' + [String]nrfixed + ','+ [String] nrunfixed + String::NewLine();
    
      // Freeze variables for SalesDemands
    nrfixed := 0; 
    nrunfixed := 0;   
    traverse( scope.GetLeafSalesDemandInPeriodInRun(), Elements, lsdip, scope.Contains( lsdip.ProductInStockingPoint_MP().PISPInOptimizerRun() ) )
    {
        var := program.SalesDemandQtyVariables().Get( lsdip );      // Fulfilled quantity
        if ( mustfixduetocurrentlevel ) 
        {
          subopt.FixVariableStyleGuide( var, lsdip.FulfilledQuantity() );
          nrfixed++; 
        }
        else
        {
          var.LowerBound( lsdip.SalesDemandQtyVarInitLowerBound() ); 
          var.UpperBound( lsdip.SalesDemandQtyVarInitUpperBound() ); 
          nrunfixed++; 
        }
    } 
    
    traverse( scope.GetAggregatedSalesDemandInPeriodInRun(), Elements, asdip )
    {
      traverse ( asdip, DisaggregatedSalesDemandInPeriod, dasdip,
                 scope.Contains( dasdip.AsPlanningBaseSalesDemandInPeriod().PISPIPInOptimizerRun() ) )
      {
         var := program.DisaggregatedSalesDemandQtyVariables().Get( dasdip );
         if ( mustfixduetocurrentlevel ) 
         {
            subopt.FixVariableStyleGuide( var, dasdip.FulfilledQuantity() );
            nrfixed++; 
         }  
         else 
         {
            var.LowerBound( dasdip.SalesDemandQtyVarInitLowerBound() ); 
            var.UpperBound( dasdip.SalesDemandQtyVarInitUpperBound() ); 
            nrunfixed++; 
         }
      }
    }
    msg := msg + 'sales demands fixed, unfixed= ' + [String]nrfixed + ','+ [String] nrunfixed;
    debuginfo(  msg );
  *]
  InterfaceProperties { Accessibility: 'Module' }
}