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
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsGoalsForCampaignLimitations (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    totalmaxqtyover_constname := typeof( MPTotalCampaignMaxQtyOverConstraint );
    scalefactor_totalmaxqtyover_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxQtyOverVariable ), totalmaxqtyover_constname );
    scalefactor_maxqtyoverwithin_const := this.ScaleConstraintTerm( typeof( MPMaxCampaignElementTypeQtyOverWithinVariable ), totalmaxqtyover_constname );
    scalefactor_maxqtyovermultiperiod_const := this.ScaleConstraintTerm( typeof( MPMaxCampaignElementTypeQtyOverMultiPeriodVariable ), totalmaxqtyover_constname );
    
    totalminqtyunder_constname := typeof( MPTotalCampaignMinQtyUnderConstraint );
    scalefactor_totalminqtyunder_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinQtyUnderVariable ), totalminqtyunder_constname );
    scalefactor_minqtyunderwithin_const := this.ScaleConstraintTerm( typeof( MPMinCampaignElementTypeQtyUnderWithinVariable ), totalminqtyunder_constname );
    scalefactor_minqtyundermulti_const := this.ScaleConstraintTerm( typeof( MPMinCampaignElementTypeQtyUnderMultiVariable ), totalminqtyunder_constname );
    
    totalmindurunder_constname := typeof( MPTotalCampaignMinDurUnderConstraint );
    scalefactor_totalmindurunder_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinDurationUnderVariable ), totalmindurunder_constname );
    scalefactor_mindurunderwithin_const := this.ScaleConstraintTerm( typeof( MPMinCampaignElementTypeDurUnderWithinVariable ), totalmindurunder_constname );
    scalefactor_mindurundermulti_const := this.ScaleConstraintTerm( typeof( MPMinCampaignElementTypeDurUnderMultiVariable ), totalmindurunder_constname );
    
    totalmaxdurover_constname := typeof( MPTotalCampaignMaxDurOverConstraint );
    scalefactor_totalmaxdurover_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxDurationOverVariable ), totalmaxdurover_constname );
    scalefactor_maxduroverwithin_const := this.ScaleConstraintTerm( typeof( MPMaxCampaignElementTypeDurOverWithinVariable ), totalmaxdurover_constname );
    scalefactor_maxdurovermulti_const := this.ScaleConstraintTerm( typeof( MPMaxCampaignElementTypeDurOverMultiVariable ), totalmaxdurover_constname );
      
    totalmaxqtyoverconstr := program.TotalCampaignMaxQtyOverConstraints().New();
    totalmaxqtyoverconstr.RHSValue( 0.0 );
    totalmaxqtyoverconstr.Sense( "=" );
    vartotalmaxqtyover := program.TotalCampaignMaxQtyOverVariables().Get(); 
    totalmaxqtyoverconstr.NewTerm( 1.0 * scalefactor_totalmaxqtyover_const, vartotalmaxqtyover );
    
    totalminqtyunderconstr := program.TotalCampaignMinQtyUnderConstraints().New();
    totalminqtyunderconstr.RHSValue( 0.0 );
    totalminqtyunderconstr.Sense( "=" );
    vartotalminqtyunder := program.TotalCampaignMinQtyUnderVariables().Get(); 
    totalminqtyunderconstr.NewTerm( 1.0 * scalefactor_totalminqtyunder_const, vartotalminqtyunder );
    
    totalmindurunderconstr := program.TotalCampaignMinDurUnderConstraints().New();
    totalmindurunderconstr.RHSValue( 0.0 );
    totalmindurunderconstr.Sense( "=" );
    vartotalmindurunder := program.TotalCampaignMinDurationUnderVariables().Get();
    totalmindurunderconstr.NewTerm( 1.0 * scalefactor_totalmindurunder_const, vartotalmindurunder );
    
    totalmaxduroverconstr := program.TotalCampaignMaxDurOverConstraints().New();
    totalmaxduroverconstr.RHSValue( 0.0 );
    totalmaxduroverconstr.Sense( "=" );
    vartotalmaxdurover := program.TotalCampaignMaxDurationOverVariables().Get();
    totalmaxduroverconstr.NewTerm( 1.0 * scalefactor_totalmaxdurover_const, vartotalmaxdurover );
    
    ocusps := selectset( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp, true )
    
    traverse( ocusps, Elements, ocusp )
    {
      //If this is a transition, we want these constraints to be hard ones
      //So we don't have these slack variables
      traverse( ocusp, OptCampaignCombiElement.OptCampaignElementType, ocet, not ocet.istype( OptCampaignTransitionType ) )
      {
        totalmaxqtyoverconstr.NewTerm( - 1.0 * scalefactor_maxqtyoverwithin_const, program.MaxCampaignElementTypeQtyOverWithinVariables().Get( ocet, ocusp ) )
        totalmaxqtyoverconstr.NewTerm( - 1.0 * scalefactor_maxqtyovermultiperiod_const, program.MaxCampaignElementTypeQtyOverMultiPeriodVariables().Get( ocet, ocusp ) )
        if ( isnull( ocusp.NextSubPeriod() ) )
        {
          totalmaxqtyoverconstr.NewTerm( - 1.0 * scalefactor_maxqtyoverwithin_const, program.MaxCampaignElementTypeQtyOverWithinLastVariables().Get( ocet, ocusp ) )
        }
        
        totalminqtyunderconstr.NewTerm( - 1.0 * scalefactor_minqtyunderwithin_const, program.MinCampaignElementTypeQtyUnderWithinVariables().Get( ocet, ocusp ) )
        totalminqtyunderconstr.NewTerm( - 1.0 * scalefactor_minqtyundermulti_const, program.MinCampaignElementTypeQtyUnderMultiVariables().Get( ocet, ocusp ) )
        
        totalmindurunderconstr.NewTerm( - 1.0 * scalefactor_mindurunderwithin_const, program.MinCampaignElementTypeDurUnderWithinVariables().Get( ocet, ocusp ) );
        totalmindurunderconstr.NewTerm( - 1.0 * scalefactor_mindurundermulti_const, program.MinCampaignElementTypeDurUnderMultiVariables().Get( ocet, ocusp ) );
        
        totalmaxduroverconstr.NewTerm( - 1.0 * scalefactor_maxduroverwithin_const, program.MaxCampaignElementTypeDurOverWithinVariables().Get( ocet, ocusp ) );
        totalmaxduroverconstr.NewTerm( - 1.0 * scalefactor_maxdurovermulti_const, program.MaxCampaignElementTypeDurOverMultiVariables().Get( ocet, ocusp ) );
      }
    }
  *]
}