yanweiyuan3
2023-08-09 588bc7829387dfc761cc25f06f77d4c81818bd10
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForCampaignCalcDurationOfElementTypeEnd (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    durationelementtypeend_constname := typeof( MPCalcDurationOfElementTypeEndConstraint );
    scalefactor_DurationOfCampaignElementTypeEnd_const := this.ScaleConstraintTerm( typeof( MPDurationOfCampaignElementTypeEndVariable ), durationelementtypeend_constname );
    scalefactor_IsLast_const := this.ScaleConstraintTerm( typeof( MPIsLastCampaignElementTypeVariable ), durationelementtypeend_constname );
    
    traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
    {
      traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet )
      {
        constr := program.CalcDurationOfElementTypeEndConstraints().New( ocet, ocusp );
        
        // Adding duration campaign element type end variable to constraint
        vardurationstart := program.DurationOfCampaignElementTypeEndVariables().Get( ocet, ocusp );
        constr.NewTerm( 1.0 * scalefactor_DurationOfCampaignElementTypeEnd_const, vardurationstart ); 
        
        // subtracting BigM which is the min between campaign max duration and the period duration
        bigm := minvalue( ifexpr( ocet.HasMaxDuration(), ocet.MaxDuration(), Duration::MaxDuration() ), ocusp.UnitPeriod().Duration() ).HoursAsReal();
        islast := program.IsLastCampaignElementTypeVariables().Get( ocet, ocusp );
        constr.NewTerm( - bigm * scalefactor_IsLast_const, islast );
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}