| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsForGoalsForLevelGoal ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   const RunContextForCapacityPlanning runcontext, | 
|   const LibOpt_Scope scope | 
| ) const | 
| { | 
|   Description: 'Initialize constraints for calculating goal value for each level' | 
|   TextBody: | 
|   [* | 
|     traverse( this, MacroPlan.StrategyMacroPlan.StrategyLevelMacroPlan, level )  | 
|     {  | 
|       // below we define the single variable that is goal to consider during level 'level' by adding goal terms to the defining constraint 'const' | 
|       levelgoalvar := program.GoalForLevelVariables().Get( level );   | 
|      | 
|       const := program.GoalConstraints().New(  level );   | 
|       const.NewTerm( -1.0, levelgoalvar );  | 
|       const.Sense( '=' );     | 
|        | 
|       // workaround because cannot write to attribute on level - 1.0 means true | 
|       this.StoreValueInProgram( program, 'collect_values_model_SetCPLEXBoundFromPlan' + [String] level.Level(), 1.0 );  | 
|       this.StoreValueInProgram( program, 'collect_values_model_TotalBoundFromPlan' + [String] level.Level(), 0.0 );  | 
|        | 
|       if ( runcontext.IsMetaIteration()  | 
|            and level.Level() >= runcontext.WeightLevelNonFinancial().StockingPointCapacityLevel()  | 
|            and runcontext.WeightLevelNonFinancial().StockingPointCapacityWeight() > 0  | 
|            and runcontext.WeightLevelNonFinancial().StockingPointCapacityLevel() > 0 )  | 
|       { | 
|         weight := this.GetRunContextMeta().OptionRestrictSPcapacityWeight();  | 
|         const.NewTerm( -1.0 * weight, program.TotalStockingPointCapacityMetaVariables().Get() ); // use (1-epsilon) max capacity limits. Keep supressing SP inventory | 
|       } | 
|     } | 
|      | 
|     weightlevels := this.GetRunContextConst().WeightLevelNonFinancial();   | 
|        | 
|       // non-financial kpi | 
|     // Goal term for maximization = 1.0 * weight * variable scale factor for kpi / goal scaling factor | 
|      | 
|     // workaround because we cannot write to attribute   | 
|     //>> | 
|     value_collect_values_model_TotalBlendingViolation := 0.0;  | 
|     value_collect_values_model_MPTotalFulfillmentVariables := 0.0; | 
|     value_collect_values_model_MPTotalSalesDemandPriorityVariable := 0.0; | 
|     value_collect_values_model_MPTotalPostponentPenaltyVariable := 0.0;  | 
|     value_collect_values_model_MPTotalMaximumInventoryLevelVariable := 0.0; | 
|     value_collect_values_model_MPTotalMinimumInventoryLevelVariable := 0.0; | 
|     value_collect_values_model_MPTotalTargetInventoryLevelVariable := 0.0;  | 
|     value_collect_values_model_MPTotalFulfillmentTargetVariable := 0.0;  | 
|     value_collect_values_model_MPTotalUnitCapacityVariable := 0.0;  | 
|     value_collect_values_model_MPTotalUnitSecondaryCapacityVariable := 0.0;  | 
|     value_collect_values_models_MPTotalMinimumUnitCapacityVariable := 0.0;  | 
|     value_collect_values_models_MPTotalMinimumUnitSecondaryCapacityVariable := 0.0;  | 
|     value_collect_values_model_TotalLotSizeVariables := 0.0;  | 
|     value_collect_values_model_TotalProcessMaximumQuantityVariables := 0.0;  | 
|     value_collect_values_model_TotalStockingPointCapacityVariables := 0.0;  | 
|     value_collect_values_model_TotalMaximumSupplyVariables := 0.0;  | 
|     value_collect_values_model_TotalMinimumSupplyVariables := 0.0;  | 
|     value_collect_values_model_TotalTargetSupplyVariables := 0.0;  | 
|     value_collect_values_model_MPTotalCO2EmissionVariables := 0.0; | 
|     value_collect_values_model_TotalShiftPatternChangesPenaltyVariable := 0.0; | 
|      | 
|     if ( runcontext.IsMetaIteration() )  | 
|     { | 
|       if( runcontext.UseBlending() ) | 
|       { | 
|         value_collect_values_model_TotalBlendingViolation := program.RetrieveReal( 'collectvalues_model_TotalBlendingViolation' );  | 
|       } | 
|       value_collect_values_model_MPTotalFulfillmentVariables := program.RetrieveReal( 'collect_values_model_MPTotalFulfillmentVariables' );  | 
|       value_collect_values_model_MPTotalSalesDemandPriorityVariable := program.RetrieveReal( 'collect_values_model_MPTotalSalesDemandPriorityVariable' );  | 
|       value_collect_values_model_MPTotalPostponentPenaltyVariable := program.RetrieveReal( 'collect_values_model_MPTotalPostponementPenaltyVariables' );  | 
|       value_collect_values_model_MPTotalMaximumInventoryLevelVariable := program.RetrieveReal( 'collect_values_model_MPTotalMaximumInventoryLevelVariable' );  | 
|       value_collect_values_model_MPTotalMinimumInventoryLevelVariable := program.RetrieveReal( 'collect_values_model_MPTotalMinimumInventoryLevelVariable' );  | 
|       value_collect_values_model_MPTotalTargetInventoryLevelVariable := program.RetrieveReal( 'collect_values_model_MPTotalTargetInventoryLevelVariable' );  | 
|       value_collect_values_model_MPTotalFulfillmentTargetVariable := program.RetrieveReal( 'collect_values_model_MPTotalFulfillmentTargetVariable' );  | 
|        | 
|       value_collect_values_model_MPTotalUnitCapacityVariable := program.RetrieveReal( 'collect_values_model_MPTotalUnitCapacityVariable' );  | 
|       value_collect_values_model_MPTotalUnitSecondaryCapacityVariable := program.RetrieveReal( 'collect_values_model_MPTotalUnitSecondaryCapacityVariable' );  | 
|       value_collect_values_models_MPTotalMinimumUnitCapacityVariable := program.RetrieveReal( 'collect_values_models_MPTotalMinimumUnitCapacityVariable' );  | 
|       value_collect_values_models_MPTotalMinimumUnitSecondaryCapacityVariable := program.RetrieveReal( 'collect_values_models_MPTotalMinimumUnitSecondaryCapacityVariable'); | 
|        | 
|       value_collect_values_model_TotalLotSizeVariables := program.RetrieveReal( 'collect_values_model_TotalLotSizeVariables' );  | 
|       value_collect_values_model_TotalProcessMaximumQuantityVariables := program.RetrieveReal( 'collect_values_model_TotalProcessMaximumQuantityVariables' ); | 
|        | 
|       value_collect_values_model_TotalStockingPointCapacityVariables := program.RetrieveReal( 'collect_values_model_TotalStockingPointCapacityVariables');  | 
|        | 
|       value_collect_values_model_TotalMaximumSupplyVariables := program.RetrieveReal( 'collect_values_model_TotalMaximumSupplyVariables' );  | 
|       value_collect_values_model_TotalMinimumSupplyVariables := program.RetrieveReal( 'collect_values_model_TotalMinimumSupplyVariables' );  | 
|       value_collect_values_model_TotalTargetSupplyVariables := program.RetrieveReal( 'collect_values_model_TotalTargetSupplyVariables' );  | 
|       value_collect_values_model_MPTotalCO2EmissionVariables := program.RetrieveReal( 'collect_values_model_MPTotalCO2EmissionVariable' ); | 
|        | 
|       if( runcontext.UseShiftOptimization() ) | 
|       { | 
|         value_collect_values_model_TotalShiftPatternChangesPenaltyVariable := program.RetrieveReal( 'collect_values_model_MPTotalShiftPatternChangesPenaltyVariables' ); | 
|       } | 
|     } | 
|     //<< | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.BlendingLevel(), weightlevels.BlendingWeight(), | 
|                            -1.0, program.TotalBlendingVariables().Get(), true, value_collect_values_model_TotalBlendingViolation ); | 
|                             | 
|     this.AddGoalToLevel( program, weightlevels.CampaignLevel(), weightlevels.CampaignWeight(), | 
|                        -1.0, program.TotalCampaignVariables().Get(), false, 0.0 ); | 
|      | 
|      | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.FulfillmentLevel(), weightlevels.FulfillmentWeight(), | 
|                        1.0, program.TotalFulfillmentVariables().Get(), true, value_collect_values_model_MPTotalFulfillmentVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.FulfillmentTargetLevel(), weightlevels.FulfillmentTargetWeight(), | 
|                        1.0, program.TotalFulfillmentTargetVariables().Get(), true, value_collect_values_model_MPTotalFulfillmentTargetVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.LotSizeLevel(), weightlevels.LotSizeWeight(), | 
|                        -1.0, program.TotalLotSizeVariables().Get(), true, value_collect_values_model_TotalLotSizeVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.InventoryMixBalancingLevel(), weightlevels.InventoryMixBalancingWeight(), | 
|                        -1.0, program.TotalInventoryMixBalancingVariables().Get(), false, 0.0 ); | 
|                   | 
|     this.AddGoalToLevel( program, weightlevels.MaximumInventoryLevel(), weightlevels.MaximumInventoryLevelWeight(), | 
|                        -1.0, program.TotalMaximumInventoryLevelVariables().Get(), true, value_collect_values_model_MPTotalMaximumInventoryLevelVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.MinimumInventoryLevel(), weightlevels.MinimumInventoryLevelWeight(), | 
|                        -1.0, program.TotalMinimumInventoryLevelVariables().Get(), true, value_collect_values_model_MPTotalMinimumInventoryLevelVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.MaximumSupplyLevel(), weightlevels.MaximumSupplyWeight(), | 
|                        -1.0, program.TotalMaximumSupplyVariables().Get(), true, value_collect_values_model_TotalMaximumSupplyVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.MinimumSupplyLevel(), weightlevels.MinimumSupplyWeight(), | 
|                        -1.0, program.TotalMinimumSupplyVariables().Get(), true, value_collect_values_model_TotalMinimumSupplyVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.MinimumUnitCapacityLevel(), weightlevels.MinimumUnitCapacityWeight(), | 
|                        -1.0, program.TotalMinimumUnitCapacityVariables().Get(), true, value_collect_values_models_MPTotalMinimumUnitCapacityVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.MinimumUnitCapacityLevel(), weightlevels.MinimumUnitCapacityWeight(), | 
|                        -1.0, program.TotalMinimumUnitSecondaryCapacityVariables().Get(), true, value_collect_values_models_MPTotalMinimumUnitSecondaryCapacityVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.PostponementPenaltyLevel(), weightlevels.PostponementPenaltyWeight(), | 
|                        -1.0, program.TotalPostponementPenaltyVariables().Get(), true, value_collect_values_model_MPTotalPostponentPenaltyVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.ProcessMaximumQuantityLevel(), weightlevels.ProcessMaximumQuantityWeight(), | 
|                        -1.0, program.TotalProcessMaximumQuantityVariables().Get(), true, value_collect_values_model_TotalProcessMaximumQuantityVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.SalesDemandPriorityLevel(), weightlevels.SalesDemandPriorityWeight(), | 
|                        1.0, program.TotalSalesDemandPriorityVariables().Get(), true, value_collect_values_model_MPTotalSalesDemandPriorityVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.ServiceLevelLevel(), weightlevels.ServiceLevelWeight(), | 
|                        1.0, program.TotalServiceLevelVariables().Get(), false, 0.0 ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.SlackLevel(), weightlevels.SlackWeight(), | 
|                        -1.0, program.TotalSlackVariables().Get(), false, 0.0 ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.StockingPointCapacityLevel(), weightlevels.StockingPointCapacityWeight(), | 
|                        -1.0, program.TotalStockingPointCapacityVariables().Get(), true, value_collect_values_model_TotalStockingPointCapacityVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.SupplyTargetLevel(), weightlevels.SupplyTargetWeight(), | 
|                        -1.0, program.TotalSupplyTargetVariables().Get(), true, value_collect_values_model_TotalTargetSupplyVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.TargetInventoryLevel(), weightlevels.TargetInventoryLevelWeight(), | 
|                        -1.0, program.TotalTargetInvLevelVariables().Get(), true, value_collect_values_model_MPTotalTargetInventoryLevelVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.UnitCapacityLevel(), weightlevels.UnitCapacityWeight(), | 
|                        -1.0, program.TotalUnitCapacityVariables().Get(), true, value_collect_values_model_MPTotalUnitCapacityVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.UnitCapacityLevel(), weightlevels.UnitCapacityWeight(), | 
|                        -1.0, program.TotalUnitSecondaryCapacityVariables().Get(), true, value_collect_values_model_MPTotalUnitSecondaryCapacityVariable ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.CapacitySmoothingLevel(), weightlevels.CapacitySmoothingWeight(), | 
|                        -1.0, program.TotalCapacitySmoothingSlackVariables().Get(), false, 0.0 ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.ExpiredQtyLevel(), weightlevels.ExpiredQtyWeight(), | 
|                        -1.0, program.TotalExpiredQtyVariables().Get(), false, 0.0 ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.CO2EmissionLevel(), weightlevels.CO2EmissionWeight(), | 
|                        -1.0, program.TotalCO2EmissionVariables().Get(), true, value_collect_values_model_MPTotalCO2EmissionVariables ); | 
|      | 
|     this.AddGoalToLevel( program, weightlevels.ShiftPatternChangesPenaltyLevel(), weightlevels.ShiftPatternChangesPenaltyWeight(), | 
|                          -1.0, program.TotalShiftPatternChangesPenaltyVariables().Get(), true, value_collect_values_model_TotalShiftPatternChangesPenaltyVariable ); | 
|      | 
|     // Accounts kpi | 
|     traverse( scope.GetAccountsInOptimizerRunConst(), Elements, account )  | 
|     { | 
|       factor := ifexpr( account.IsMaximize(), 1.0, -1.0 ); | 
|      | 
|       traverse( account, AccountAssignment.AccountCostDriver, driver ) | 
|       { | 
|         var := null( MPVariable ); | 
|                               | 
|         if( driver.Name() = Translations::MP_AccountAssignmentCostDriverFixed() )                 // fixed | 
|         { | 
|           // we don't need fixed cost in the optimizer. | 
|         } | 
|         else if ( driver.Name() = Translations::MP_AccountAssignmentCostDriverInventorySupply() )  | 
|         { | 
|           // cost driver inventory supply not applicable in optimizer                             // inventory supply | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverStaffing() )         // staffing | 
|         { | 
|           var := program.DriverStaffingVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverInventoryValue() )   // inventory value | 
|         { | 
|           var := program.DriverInventoryValueVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverInventoryHolding() ) // inventory holding | 
|         { | 
|           var := program.DriverInventoryHoldingVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverNrOfUnits() )        // nr of units | 
|         { | 
|           var := program.DriverNrOfUnitsVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverSales() )            // sales | 
|         { | 
|           var := program.DriverSalesVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverTime() )             // time | 
|         { | 
|           var := program.DriverTimeVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverVolume() )           // volume | 
|         { | 
|           var := program.DriverVolumeVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverLot() )              // Lot | 
|         { | 
|           var := program.DriverLotVariables().Get( account, driver ); | 
|         } | 
|         else if( driver.Name() = Translations::MP_AccountAssignmentCostDriverChangeover() )        // Changeover | 
|         { | 
|           var := program.DriverChangeoverVariables().Get( account, driver ); | 
|         } | 
|         else if ( driver.Name() = Translations::MP_AccountAssignmentCostDriverOneTime() )         // One-time | 
|         { | 
|           var := program.DriverOneTimeVariables().Get( account, driver );  | 
|         } | 
|         else | 
|         { | 
|           info( '>>> Missing goal value assignment for account ', account.Name(), ' driver name:', driver.Name() );   | 
|         } | 
|         if( not isnull( var ) ) | 
|         { | 
|           this.AddGoalToLevel( program, | 
|                                account.Level(), | 
|                                account.Weight(), | 
|                                factor, | 
|                                var,  | 
|                                false,  | 
|                                0.0 );   | 
|         } | 
|       }    | 
|     } | 
|      | 
|     this.SetKPILowerBounds( program, runcontext, scope.IsGeneratedByPreProductionSelector() ); | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |