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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForCampaignMinQtyWithin (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    minqtywithin_constname := typeof( MPMinCampaignElementTypeQtyWithinConstraint );
    scalefactor_PTQtyWithin_const := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignElementTypeMidVariable ), minqtywithin_constname );
    scalefactor_NrOfElementsWithin_const := this.ScaleConstraintTerm( typeof( MPNrOfCampaignElementWithinUnitSubPeriodVariable ), minqtywithin_constname );
    scalefactor_MinElementTypeQtyUnderWithin_const := this.ScaleConstraintTerm( typeof( MPMinCampaignElementTypeQtyUnderWithinVariable ), minqtywithin_constname );
    
    traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
    {
      //Only do this for campaign / transitions that have a MinQuantity (and thus, MinQuantity is greater than 0 )
      traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet, ocet.MinQuantity() > 0.0 )
      {
        constr := program.MinCampaignElementTypeQtyWithinConstraints().New( ocet, ocusp );
        constr.RHSValue( 0.0 );
        
        traverse( ocet, OptCampaignOperationInElementType, oiet )
        {
          ptqyvar := program.PTQtyInCampaignElementTypeMidVariables().Get( oiet, ocusp );
          constr.NewTerm( 1.0 * scalefactor_PTQtyWithin_const, ptqyvar );
        }  
        
        //If this is a transition, we want these constraints to be hard ones
        if( not ocet.istype( OptCampaignTransitionType ) )
        {
          constr.NewTerm( 1.0 * scalefactor_MinElementTypeQtyUnderWithin_const, program.MinCampaignElementTypeQtyUnderWithinVariables().Get( ocet, ocusp ) );
        }
        constr.NewTerm( -ocet.MinQuantity() * scalefactor_NrOfElementsWithin_const, program.NrOfCampaignElementWithinUnitSubPeriodVariables().Get( ocet, ocusp ) );
      }
    }
  *]
}