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
Quintiq file version 2.0
#parent: #root
Method InitConstraintsForTripDependentDemands (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const LibOpt_Scope scope,
  const constcontent ProductInTrips pitinrun,
  Number threadnr
) const
{
  Description: 'Initialize constraints for dependent demands for trips'
  TextBody:
  [*
    // for each product in trip:
    // dependent demand quantity = input factor * relative duration (should be always 1) * new supply quantity
    constddqtyname := typeof( MPTripDependentDemandQtyConstraint );
    
    scalefactor_tripdemandqty_constddqty := this.ScaleConstraintTerm( typeof( MPTripDemandQtyVariable ), constddqtyname );
    scalefactor_tripnewsupply_constddqty := this.ScaleConstraintTerm( typeof( MPTripNewSupplyVariable ), constddqtyname );
    
    scalefactor_rhs_constddqty := this.ScaleConstraintRHS( constddqtyname, 1.0 );
    
    traverse( pitinrun, 
              Elements, 
              productintrip, 
              CapacityPlanningSuboptimizer::GetThreadNr( this.ThreadAParameter(), this.ThreadBParameter(), productintrip.PreThreadNr() ) = threadnr )
    {
      // constddqty constraint UoM: Input PISP
      constddqty := program.TripDependentDemandQtyConstraints().New( productintrip );
      constddqty.Sense( '=' );
      constddqty.RHSValue( 0.0 * scalefactor_rhs_constddqty );
    
      factor := 1.0;
      dd := productintrip.DependentDemand();
    
      if( not isnull( dd ) )
      {
        factor := guard( dd.ProcessInput().Factor(), 1 )  // can be changed to be > 1 or < 1. By default is 1
                  * dd.RelativeDuration();
      }
      else
      {
        laneleginput := select( productintrip, Trip.LaneLeg.LaneLegInput, input,
                               input.ProductInStockingPoint_MP().Product_MP() = productintrip.Product_MP() );
    
        if( not isnull( laneleginput ) )
        {
          factor := laneleginput.Factor();
        }
      }
    
      // Term: [Input PISP]
      constddqty.NewTerm( -scalefactor_tripdemandqty_constddqty, program.TripDemandQtyVariables().Get( productintrip ) );
    
      uomconversion := productintrip.DeparturePISPConversionFactor();
    
      // Term:     uomconversion        *  factor  * TripNewSupply variable
      // UoM:  [Output PISP to Input PISP]  *   [-]    *     [Output PISP]
      constddqty.NewTerm( uomconversion * factor * scalefactor_tripnewsupply_constddqty, program.TripNewSupplyVariables().Get( productintrip ) );
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}