chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsforCampaignCalcElementTypePeriodOverloadedEnd (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    campaignoverloadend_constname := typeof( MPCalcElementTypePeriodOverloadedEndConstraint );
    scalefactor_PTQtyInCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeEndVariable ), campaignoverloadend_constname );
    scalefactor_CampaignElementTypePeriodOverloadedEnd_const := this.ScaleConstraintTerm( typeof( MPCampaignElementTypePeriodOverloadedEndVariable ), campaignoverloadend_constname );
    scalefactor_DurationOfCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPDurationOfCampaignElementTypeEndVariable ), campaignoverloadend_constname );
    
    traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
    {
      traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet )
      {
        constr := program.CalcElementTypePeriodOverloadedEndConstraints().New( ocet, ocusp );
        // Sum ( max capacity usage per quantity * PTQty in Element Type end )
        traverse( ocet, OptCampaignOperationInElementType, ocoet )
        {
          maxcap := ocoet.Operation().GetCapacityUsagePerQuantity( ocusp.UnitPeriod() );
          varcampaignptqtyend := program.PTQtyInCampaignElementTypeEndVariables().Get( ocoet, ocusp );
          constr.NewTerm( maxcap * scalefactor_PTQtyInCampaignElementTypeEnd_const, varcampaignptqtyend ); 
        }
        // Add slack variable ElementTypePeriodUnderloadedEnd
        varcampaignoverloadend := program.CampaignElementTypePeriodOverloadedEndVariables().Get( ocet, ocusp );
        constr.NewTerm( -1.0 * scalefactor_CampaignElementTypePeriodOverloadedEnd_const, varcampaignoverloadend );
        
        // Subtract total available capactity * relative duration of element end type
        totalcap := ocusp.UnitPeriod().GetTotalAvailableCapacity();
        duration := ocusp.UnitPeriod().Duration();
        factor := totalcap / duration.HoursAsReal();
        varcampaigndurationend := program.DurationOfCampaignElementTypeEndVariables().Get( ocet, ocusp );
        constr.NewTerm( -factor * scalefactor_DurationOfCampaignElementTypeEnd_const, varcampaigndurationend );
      } 
    }
  *]
}