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
Quintiq file version 2.0
#parent: #root
Method AddGoalToLevel (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  Number goallevel,
  Real goalweight,
  Real coefficient,
  MPVariable goalvar,
  Boolean useboundfromplan,
  Real boundfromplan
) const
{
  TextBody:
  [*
    if( goalweight > 0.0 )
    {
      traverse( this, MacroPlan.StrategyMacroPlan.StrategyLevelMacroPlan, level ) 
      {
        if( goallevel = level.Level() )
        {
          totalcoefficient := coefficient * goalweight * ifexpr( level.Level() = 0, 1.0, this.ScaleGoalTerm( typeofexpression( goalvar ), level ) ); // exception level 0 no need to scale all terms coeff 1
          goalconstr := program.GoalConstraints().Get( level );  
          goalconstr.NewTerm( totalcoefficient, goalvar );
          
          // workaround for not being able to write to attribute 
          if ( not useboundfromplan ) // only set bound from plan if all added kpis have computable bounds (0 means false below, bounds are initialized at 1)
          {
            this.StoreValueInProgram( program, 'collect_values_model_SetCPLEXBoundFromPlan' + [String] level.Level(), 0.0 ); 
          }
          if ( not goalvar = program.TotalLotSizeVariables().Get()  // lot size bound is set separately on total lot size var
               and not goalvar = program.TotalStockingPointCapacityVariables().Get() // spip cap we give a separate bound, because it aggregates a lot of noise (don't want it to spread to other KPIs)
               and not goalvar = program.TotalBlendingVariables().Get() ) // for blending we give individual bound because of sensitive nature
          {
            // workaround for not being able to write to attribute
            name := 'collect_values_model_TotalBoundFromPlan' + [String] level.Level(); 
            value_collect_values_model_TotalBoundFromPlan := program.RetrieveReal( name );   
            newvalue := value_collect_values_model_TotalBoundFromPlan + totalcoefficient * boundfromplan; 
            this.StoreValueInProgram( program, name, newvalue ); 
          }
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}