haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
Quintiq file version 2.0
#parent: #root
Method ActivateHierarchicalGoals (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  Description: 'Activate goal of current level, deactivate previous level goal, and freeze total goal value of previous goal'
  TextBody:
  [*
    assert( this.CurrentSubOptimizerLevel().IsFirst(), ' hierarchical goals are expected to be created for all goals for all levels prior to the very first cplex invocation ' ); 
    
    nrlevel := this.SubOptimizerLevel( relsize ); 
    
    // workaround for hierarhical goals - need a binary
    program.NewBinaryVariable(  'Dummy'); 
    
    if ( runcontext.IsMetaIteration() ) 
    {
      program.TimeLimit( this.GetRunContextMeta().OptionMaxTimePerIterationSeconds() * 2 * nrlevel ); 
    }
    else
    {
      mp := this.Run().OptimizationConst().astype( Optimization ).MacroPlan(); 
      timelimit := sum(  mp, StrategyMacroPlan.StrategyLevelMacroPlan, slm, true, slm.TimeLimit() ); 
      program.TimeLimit( timelimit ); 
    }
    debuginfo(  'Set program.TimeLimit = ', program.TimeLimit() ); 
          
    priority := this.SubOptimizerLevel( relsize ); // higher priority means solved first hierarchically
    traverse( this, SubOptimizerLevel, suboptlevel ) // sorted relation traversing in order of level number 0, 1, 2, ...
    {
        debuginfo( 'Create level goal', suboptlevel.LevelNumber() );  
    
        newgoal := program.NewGoal( CapacityPlanningSuboptimizer::HierarchicalGoalLevelName( suboptlevel.LevelNumber() ) ); 
        newgoal.Sense( 'Maximize' );  
        newgoal.Priority( priority ); 
        newgoal.Weight( 1.0 ); 
        
        if ( suboptlevel.IsExtraPTQTYLevelMetaOptimizer() ) 
        {
          this.AddPTQtyGoal( scope, program, newgoal );   
        }
        else
        {
          nextgoalvar := program.GoalForLevelVariables().Get( suboptlevel.GetStrategyLevelMacroPlan() ); 
          newgoal.NewTerm( 1.0, nextgoalvar );
          this.SetCPLEXParametersHierarchicalGoal( program, suboptlevel.GetStrategyLevelMacroPlan(), newgoal );   
        }
        
        priority--; 
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}