| 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' } | 
| } |