haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForOperationDependentDemandInputSet (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const RunContextForCapacityPlanning runcontext,
  const LibOpt_Scope scope
) const
{
  Description: 'Initialize constraints for dependent demands which is part of an input group and belongs to an input set.'
  TextBody:
  [*
    maxconstname := typeof( MPOperationInputSetUpperBoundConstraint ); 
    minconstname := typeof( MPOperationInputSetLowerBoundConstraint );
    
    scalefactor_periodtaskqty_maxconst := this.ScaleConstraintTerm( typeof( MPPTQtyVariable ), maxconstname );
    scalefactor_operationinputsetover_maxconst := this.ScaleConstraintTerm( typeof( MPOperationInputSetOverVariable ), maxconstname );
    scalefactor_periodtaskqty_minconst := this.ScaleConstraintTerm( typeof( MPPTQtyVariable ), minconstname );
    scalefactor_operationinputsetunder_minconst := this.ScaleConstraintTerm( typeof( MPOperationInputSetUnderVariable ), minconstname );
    scalefactor_partialoperationdemandqty_maxconst := this.ScaleConstraintTerm( typeof( MPPartialOperationDemandQtyVariable ), maxconstname );
    scalefactor_partialoperationdemandqty_minconst := this.ScaleConstraintTerm( typeof( MPPartialOperationDemandQtyVariable ), minconstname );
    scalefactor_operationdemandqty_maxconst := this.ScaleConstraintTerm( typeof( MPOperationDemandQtyVariable ), maxconstname );
    scalefactor_operationdemandqty_minconst := this.ScaleConstraintTerm( typeof( MPOperationDemandQtyVariable ), minconstname );
         
    scalefactor_rhs_maxconst := this.ScaleConstraintRHS( maxconstname, 1.0 );
    scalefactor_rhs_minconst := this.ScaleConstraintRHS( minconstname, 1.0 );    
         
    traverse( scope.GetOperationInputSetInOptimizerRunConst(), Elements, set,
              not exists( set, OperationInput, input,
                          not input.GetIsProductInOptimizerRun( runcontext.IsPostProcessing() ) ) ) // Filter the set if one or more inputs is excluded
    {
      
      operation := set.Operation();
      // If the outputquantity is zero, then the uom is the uom of the unit
      maxfactor := set.MaxQuantity();
      minfactor := set.MinQuantity();
      if( operation.OutputQuantity() > 0.0 )
      {
        maxfactor := set.MaxQuantity() / operation.OutputQuantity();
        minfactor := set.MinQuantity() / operation.OutputQuantity();
      }
    
      if ( this.GetPeriodsFromPeriodTaskOperation() ) 
      {
        traverse( operation, PeriodTaskOperationInScope, pto ) 
        {
          period := pto.UnitPeriod().Period_MP(); 
          this.InitConstraintsForOperationDependentDemandInputSet_Add( program, 
                                                                 runcontext, 
                                                                 scope, 
                                                                 set, 
                                                                 period,
                                                                 pto, 
                                                                 scalefactor_periodtaskqty_maxconst,
                                                                 scalefactor_operationinputsetover_maxconst,
                                                                 scalefactor_periodtaskqty_minconst,
                                                                 scalefactor_operationinputsetunder_minconst,
                                                                 scalefactor_partialoperationdemandqty_maxconst,
                                                                 scalefactor_partialoperationdemandqty_minconst,
                                                                 scalefactor_operationdemandqty_maxconst,
                                                                 scalefactor_operationdemandqty_minconst,
                                                                 scalefactor_rhs_maxconst,
                                                                 scalefactor_rhs_minconst, 
                                                                 maxfactor, 
                                                                 minfactor );
        }
                  
      }
      else
      {
        periods := this.GetPeriodsForOperation( scope, operation );
      
        traverse( periods, Elements, period )
        {
          this.InitConstraintsForOperationDependentDemandInputSet_Add( program, 
                                                                       runcontext, 
                                                                       scope, 
                                                                       set, 
                                                                       period,
                                                                       null(  PeriodTaskOperation ), 
                                                                       scalefactor_periodtaskqty_maxconst,
                                                                       scalefactor_operationinputsetover_maxconst,
                                                                       scalefactor_periodtaskqty_minconst,
                                                                       scalefactor_operationinputsetunder_minconst,
                                                                       scalefactor_partialoperationdemandqty_maxconst,
                                                                       scalefactor_partialoperationdemandqty_minconst,
                                                                       scalefactor_operationdemandqty_maxconst,
                                                                       scalefactor_operationdemandqty_minconst,
                                                                       scalefactor_rhs_maxconst,
                                                                       scalefactor_rhs_minconst, 
                                                                       maxfactor, 
                                                                       minfactor );
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}