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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsforCampaignCalcElementTypePeriodUnderloadedEnd (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    campaignunderloadend_constname := typeof( MPCalcElementTypePeriodUnderloadedEndConstraint );
    scalefactor_PTQtyInCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeEndVariable ), campaignunderloadend_constname );
    scalefactor_CampaignElementTypePeriodUnderloadedEnd_const := this.ScaleConstraintTerm( typeof( MPCampaignElementTypePeriodUnderloadedEndVariable ), campaignunderloadend_constname );
    scalefactor_DurationOfCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPDurationOfCampaignElementTypeEndVariable ), campaignunderloadend_constname );
    
    traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
    {
      traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet )
      {
        constr := program.CalcElementTypePeriodUnderloadedEndConstraints().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
        varcampaignunderloadend := program.CampaignElementTypePeriodUnderloadedEndVariables().Get( ocet, ocusp );
        constr.NewTerm( 1.0 * scalefactor_CampaignElementTypePeriodUnderloadedEnd_const, varcampaignunderloadend );
        
        // 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 );
      } 
    }
  *]
}