陈清红
2025-04-14 880f3c0257eeb8c37761d484258fdd102a369a19
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 InitVariablesForTrip (
  CapacityPlanningSuboptimizer_CapacityPlanningAlgorithm program,
  const constcontent ProductInTrips userproductintrips,
  const LibOpt_Scope scope,
  const constcontent ProductInTrips pitinrun
) const
{
  Description: 'Initialize all variables related to trip containig period task lane leg.'
  TextBody:
  [*
    // create period task related variables
    
    runcontext := this.GetRunContextConst(); 
    // Init variables for all demand and supply of trips for each product
    traverse( pitinrun, Elements, productintrip )
    {
      // TripDemandQty variable UoM: Input PISP
      program.TripDemandQtyVariables().New( productintrip );        // Fulfilled demand quantity for product in trip
      // TripNewSupply variable UoM: Output PISP
      var := program.TripNewSupplyVariables().New( productintrip ); // The supply quantity for product in trip
    
      // Feedback as lowerbound
      if( productintrip.HasFeedback() )
      {
        lowerbound := sum( productintrip, FeedbackProductInTrip, feedback,
                           feedback.GetIsValidFeedback() and feedback.UnitPeriod() = productintrip.Trip().ArrivalUnitPeriod(),
                           feedback.FeedbackQuantity() );
    
        if ( lowerbound > 0 ) 
        {
          this.FreezeVariableLowerBound( var, lowerbound );
        }
      }
    }
    
    // Init variables for lot sizes and lot cost
    if( runcontext.UseLotSize() or runcontext.UseLotCost() ) //Modified by Khor for Lot cost goal
    {
      traverse( scope.GetTripInOptimizerRun(), Elements, trip, 
                trip.DepartureUnitPeriod().Period_MP().IsWithinLotSizeHorizon() )
      {
        unitperiod := trip.DepartureUnitPeriod();
      
        // Lot size of trip on departure period
        if( guard( unitperiod.HasLotSize(), false ) )
        {
          // TripNrOfLots variable UoM: Number
          tripnroflotsvar := program.TripNrOfLotsVariables().New( trip ); // Create integer variable
    
          // If this is a sliding windows run and the period is not in the sliding window, then relax the integer variable
          if( runcontext.IsSlidingWindowsRun()
              and not guard( unitperiod.Period_MP().GetIsInSlidingWindow( scope ), false ) )
          {
            tripnroflotsvar.VariableType( 'Continuous' );
          }
          
          // TripLotSizeUnder variable UoM: Unit
          varunder := program.TripLotSizeUnderVariables().New( trip );      // Additional quantity required to reach the multiples of lot size
          varover := program.TripLotSizeOverVariables().New( trip );      // Subtractive quantity required to reach the multiples of lot size
          this.FreezeVariableUpperBound( varunder, trip.LotSize() ); 
          this.FreezeVariableUpperBound( varover, trip.LotSize() );
        }
      }
    }
    
    // Freeze the user planning product in trip
    // User quantity must be adhered by the optimizer. Optimizer cannot change the transported quantity.
    traverse( userproductintrips, Elements, productintrip )
    {
      pitvar := program.TripNewSupplyVariables().Find( productintrip ); 
      if ( not isnull( pitvar ) ) 
      {
        this.FixVariableStyleGuide( pitvar, productintrip.Quantity() );
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}