lazhen
2025-01-09 8afe90b633046db39042aada36b88193062f8cff
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
Quintiq file version 2.0
#parent: #root
MethodOverride InitConstraintsForCapacityUsage (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  MPConstraint minconst,
  MPConstraint maxconst,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope,
  const CapacityPlanningSuboptimizer subopt
) const
{
  TextBody:
  [*
    // minconst and maxconst UoM: Unit
    
    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 );
    
    this.AddTermsForCapacityUsage( program,
                                   minconst,
                                   maxconst,
                                   scope,
                                   subopt,
                                   this,
                                   0.0, // Unused argument scalefactor_periodtaskqty_minconst
                                   0.0, // Unused argument scalefactor_periodtaskqty_maxconst
                                   scalefactor_tripnewsupply_minconst,
                                   scalefactor_tripnewsupply_maxconst,
                                   bound );
    
    varoverload := this.GetCapacityOverloadedVariable( program ); 
    
    // Term: UnitCapacityOverloaded variable
    // UoM:         [Time]
    maxconst.NewTerm( -1.0 * subopt.ScaleConstraintTerm( typeof( MPUnitCapacityOverloadedQuantityVariable ), 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 );
    }
    
    this.UpdateRHSForPeriodTasksNotInScope( minconst, maxconst, runcontext, scope, subopt, scalefactor_rhs_minconst, scalefactor_rhs_maxconst );
  *]
}