| Quintiq file version 2.0 | 
| #parent: #root | 
| Method InitConstraintsForSecondaryCapacityUsage ( | 
|   CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program, | 
|   MPMinUnitSecondaryCapacityQtyConstraint minconst, | 
|   MPMaxUnitSecondaryCapacityQtyConstraint maxconst, | 
|   const RunContextForCapacityPlanning runcontext, | 
|   const LibOpt_Scope scope, | 
|   const CapacityPlanningSuboptimizer subopt | 
| ) const | 
| { | 
|   TextBody: | 
|   [* | 
|     // secondary minconst and maxconst UoM: TransportCapacity | 
|      | 
|     bound := 0.0;                                   // To prevent infeasible when the unit is closed | 
|      | 
|     scalefactor_tripnewsupply_maxconst := subopt.ScaleConstraintTerm( typeof( MPTripNewSupplyVariable ), typeofexpression( maxconst ) ); | 
|     scalefactor_tripnewsupply_minconst := subopt.ScaleConstraintTerm( typeof( MPTripNewSupplyVariable ), typeofexpression( minconst ) ); | 
|      | 
|     scalefactor_rhs_minconst := subopt.ScaleConstraintRHS( typeofexpression( minconst ), 1.0 ); | 
|     scalefactor_rhs_maxconst := subopt.ScaleConstraintRHS( typeofexpression( maxconst ), 1.0 ); | 
|      | 
|     targetuom := this.TransportCapacity().SecondaryUnitOfMeasure(); | 
|      | 
|     traverse( this, PeriodTask_MP.astype( PeriodTaskLaneLeg ), ptll, | 
|               scope.Contains(  ptll.Trip().TripInOptimizerRun() ) )     // Only if the trip is part of this optimizer run | 
|     { | 
|       traverse( ptll, Trip.ProductInTrip, productintrip, | 
|                 scope.Contains( productintrip.ProductInTripInOptimizerRun() ) ) // Only if the productintrip is part of this optimizer run | 
|       { | 
|         uomconversion := productintrip.GetUOMConversionFactor( targetuom ); | 
|         factor := ptll.Process_MP().GetCapacityUsagePerQuantity( this ); | 
|          | 
|         var := program.TripNewSupplyVariables().Get( productintrip ); | 
|      | 
|         // Term:    uomconversion   *      factor          * TripNewSupply variable | 
|         // UoM: [Output PISP to Unit] * [ Time / Unit] *      [Output PISP] | 
|         maxconst.NewTerm( uomconversion * factor * scalefactor_tripnewsupply_maxconst, var ); | 
|         minconst.NewTerm( uomconversion * factor * scalefactor_tripnewsupply_minconst, var ); | 
|      | 
|         bound := bound + factor * var.LowerBound(); | 
|       } | 
|     } | 
|      | 
|     varoverload := program.UnitSecondaryCapacityOverloadedVariables().Get( this ); | 
|      | 
|     // Term: UnitCapacityOverloaded variable | 
|     // UoM:         [Time] | 
|     maxconst.NewTerm( -1.0 * subopt.ScaleConstraintTerm( typeof( MPUnitSecondaryCapacityOverloadedVariable ), typeofexpression( maxconst ) ), varoverload ); | 
|      | 
|     if( this.NrOfOpen() <= 0 )    // If the unit is closed, it should not be allowed to plan anything, and the overloaded capacity is served as the slack to prevent infeasible | 
|     { | 
|       subopt.FreezeVariableUpperBound( varoverload, bound ); | 
|     } | 
|      | 
|     // Update the RHS based on the trips outside the optimizer horizon | 
|     traverse( this, PeriodTask_MP.astype( PeriodTaskLaneLeg ), ptll ) | 
|     { | 
|       traverse( ptll, Trip.ProductInTrip, pit, | 
|                 not scope.Contains( pit.ProductInTripInOptimizerRun() ) | 
|                 and ( pit.HasRegularProductForOptimizer() or pit.Product_MP().GetIsInOptimizerRun( runcontext.IsPostProcessing() ) ) ) | 
|       { | 
|         // The quantity of this product in trip that is outside the horizon | 
|         fixedquantity := pit.SecondaryQuantityInProcessUOM(); | 
|         newrhsminconst := subopt.GetConstraintRHS( minconst, scalefactor_rhs_minconst ) - fixedquantity; | 
|         minconst.RHSValue( newrhsminconst * scalefactor_rhs_minconst ); | 
|        | 
|         newrhsmaxconst := subopt.GetConstraintRHS( maxconst, scalefactor_rhs_maxconst ) - fixedquantity; | 
|         maxconst.RHSValue( newrhsmaxconst * scalefactor_rhs_minconst ); | 
|       } | 
|     } | 
|   *] | 
|   InterfaceProperties { Accessibility: 'Module' } | 
| } |