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
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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsGoalsForCampaigns (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope
) const
{
  TextBody:
  [*
    totalcombislack_constname := typeof( MPTotalCampaignSequencingCombiSlackConstraint );
    scalefactor_totalcombislackVariables_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignSequencingCombiSlackVariable ), totalcombislack_constname );
    scalefactor_underselectioncombiVariables_const := this.ScaleConstraintTerm( typeof( MPUnderSelectionOfCampaignCombiVariable ), totalcombislack_constname );
    scalefactor_isselectedvar_const := this.ScaleConstraintTerm( typeof( MPIsCampaignCombiSelectedVariable ), totalcombislack_constname );
    scalefactor_ptqtyslack := this.ScaleConstraintTerm( typeof( MPPTQtyInCampaignSlackVariable ), totalcombislack_constname );
    scalefactor_incompatiblewithprevVariables_const := this.ScaleConstraintTerm( typeof( MPIsIncompatibleWithPrevOptSubUnitPeriodLastElementVariable ), totalcombislack_constname );
    
    totalcampaign_constname := typeof( MPTotalCampaignConstraint );
    scalefactor_totalcampaign_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignVariable ), totalcampaign_constname );
    scalefactor_totalcampaignutil_const := this.ScaleConstraintTerm( typeof( MPTotalUnitPeriodCampaignUtilizationSlackVariable ), totalcampaign_constname );
    scalefactor_totalcampaignmaxqty_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxQtyOverVariable ), totalcampaign_constname );
    scalefactor_totalcampaignminqty_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinQtyUnderVariable ), totalcampaign_constname );
    scalefactor_totalcampaignmindur_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMinDurationUnderVariable ), totalcampaign_constname );
    scalefactor_totalcampaignmaxdur_const := this.ScaleConstraintTerm( typeof( MPTotalCampaignMaxDurationOverVariable ), totalcampaign_constname );
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Sum the penalties due to incompatible Campaigns/TransitionStages between 2 consecutive combi, and the penalties due to the under-selection for all combis.
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////    
    totalcombislackctr := program.TotalCampaignSequencingCombiSlackConstraints().New();
    totalcombislackctr.RHSValue( 0.0 );
    totalcombislackctr.Sense( "=" );
    vartotalcombislack := program.TotalCampaignSequencingCombiSlackVariables().Get(); 
    totalcombislackctr.NewTerm( 1.0 * scalefactor_totalcombislackVariables_const, vartotalcombislack );
    
    traverse( scope.GetUnitPeriodInOptimizerRunConst(), Elements.OptCampaignUnitSubPeriod, ocusp )
    {
      varunderselectioncombi := program.UnderSelectionOfCampaignCombiVariables().Get( ocusp );
      totalcombislackctr.NewTerm( -1.0 * scalefactor_underselectioncombiVariables_const, varunderselectioncombi );
      varincompatiblewithprev := program.IsIncompatibleWithPrevOptSubUnitPeriodLastElementVariables().Get( ocusp );
      totalcombislackctr.NewTerm( -1.0 * scalefactor_incompatiblewithprevVariables_const, varincompatiblewithprev );
    
      traverse( ocusp, OptCampaignCombiActive, combi, combi.NrSequenceViolationsInternal() > 0 )
      { 
        varisselected := program.IsCampaignCombiSelectedVariables().Get( combi );
        totalcombislackctr.NewTerm( -1.0 * combi.NrSequenceViolationsInternal() * scalefactor_isselectedvar_const, varisselected );  
      }
    }    
    
    traverse( scope.GetOperationInOptimizerRunConst(), Elements, operation,
              operation.OperationInCampaignType( relsize ) > 0 
              or operation.OperationInTransitionType( relsize ) > 0 )
    {
      // Only select those periods that are relevant for this operation for the optimizer run
      periods := this.GetPeriodsForOperation( scope, operation );
    
      traverse( periods, Elements, period,
                period.GetIsInCampaignTypeHorizonUnit( operation.Unit() ) )
      {
        varslack := program.PTQtyInCampaignSlackVariables().Find(  operation, period );  
        if ( not isnull( varslack ) ) 
        {
          totalcombislackctr.NewTerm( -1.0 * scalefactor_ptqtyslack, varslack ); 
        }
      }
    }
    
    this.InitConstraintsGoalsForCampaignLimitations( program, scope )
    
    totalcampaignconst := program.TotalCampaignConstraints().New();
    totalcampaignconst.RHSValue( 0.0 );
    totalcampaignconst.NewTerm( -1.0 * scalefactor_totalcampaign_const, program.TotalCampaignVariables().Get() );
    totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignUtilizationPenaltyWeight() * scalefactor_totalcampaignutil_const, program.TotalUnitPeriodCampaignUtilizationSlackVariables().Get() );
    totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmaxqty_const , program.TotalCampaignMaxQtyOverVariables().Get() );
    totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignminqty_const, program.TotalCampaignMinQtyUnderVariables().Get() );
    totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmindur_const, program.TotalCampaignMinDurationUnderVariables().Get() );
    totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignMinMaxWeight() * scalefactor_totalcampaignmaxdur_const, program.TotalCampaignMaxDurationOverVariables().Get() );
    //totalcampaignconst.NewTerm( CapacityPlanningSuboptimizer::OptCampaignCombiSlackWeight() * scalefactor_totalcombislack_const , vartotalcombislack );
  *]
}