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