chenqinghong
2024-05-07 3ec06a830367465068963156dcc1d8e522571c13
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
Quintiq file version 2.0
#parent: #root
Method CreateTrips (
  LaneLegs lanelegsforoptimizations,
  Period_MPs periods,
  output Trips updatedtrips_o
)
{
  Description: 'Pre-create trips to be fed as input for CPLEX'
  TextBody:
  [*
    validatestring := '';
    sanitycheckfeedback := '';
    
    //startofhorizon := this.MacroPlan().StartOfHistorical();
    earliesttripdeparture := minselect( periods, Elements, period, true, period.SequenceNr() ).Start();
    
    // For each lane leg, create all possible trips that does not fall outside selected planning horizon.
    traverse( lanelegsforoptimizations, Elements, laneleg )
    {
      startoftrip := laneleg.LeadTime() + earliesttripdeparture;      // Used to identify if the departure date of trip falls outside selected planning horizon
    
      // Only create trips if the departure date and arrival date is within the selected planning horizon.
      traverse( periods, Elements, period, period.End() >= startoftrip )
      {
        trip := select( laneleg, Trip, trip, guard( trip.ArrivalUnitPeriod().Period_MP() = period, false ) );
    
        if( isnull( trip )
            and Trip::ValidateInput( validatestring, sanitycheckfeedback, laneleg, period ) ) // Only create valid trip
        {
          trip := Trip::Create( laneleg, period );
        }
    
        if( not isnull( trip ) )
        {
          // Create product in trips for each existing trip.
          traverse( laneleg, LaneLegInput.ProductInStockingPoint_MP.Product_MP, product )
          {
            trip.AddProduct( product, 0.0, false );
          }
          updatedtrips_o.Add( trip );
        }
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}