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
Quintiq file version 2.0
#parent: #root
Method AllocateShelfLifeSupplyToDependentDemand (
  Product_MP product,
  DependentDemands dependentdemands,
  Real remainingsupplyafteroptfulfilled_o,
  RealVector source_quantityvector,
  RealVector source_agevector,
  Number source_agevectorsize,
  RealVector quantityvector,
  RealVector agevector,
  NumberVector indexvector
) declarative
{
  Description: 'Allocate available shelf life supply to dependent demands'
  TextBody:
  [*
    // Get the quantity available to completely fulfilled this dependent demand in case there's remaining supply after considering all optimizer fulfilled qty
    allocatableqty := minvalue( this.Quantity() - this.OptimizerFulfilledQuantity(), remainingsupplyafteroptfulfilled_o );
    remainingsupplyafteroptfulfilled_o := remainingsupplyafteroptfulfilled_o - allocatableqty;
    qtyrequired := this.OptimizerFulfilledQuantity() + allocatableqty;
    dd_quantityvector := RealVector::Construct();
    dd_agevector := RealVector::Construct();
    
    istrip := this.IsDependentDemandOfTrip();
    durationintrip_days := ifexpr( istrip,
                                   this.PeriodTask_MP().astype( PeriodTaskLaneLeg ).Trip().GetShelfLifeAgeToAdd(),
                                   0 );
      
    // Increase the age of the stocks by the lead time of the trip to simulate the age of the stocks when they arrived at destination PISPIP
    // This is to filter out supplies that will be expired when arrived at destination PISPIP
    source_agevector_aftermod := source_agevector.Plus( durationintrip_days );
    
    ShelfLife::SetAvailableAgeAndQuantityVectorAfterDemand( source_quantityvector, 
                                                            source_agevector_aftermod,
                                                            dd_quantityvector,
                                                            dd_agevector,
                                                            qtyrequired,
                                                            istrip, // ignore maturation if is DD of trip, as it can matures in the middle of the trip
                                                            true, // Is consume oldest stock first
                                                            this.ProductInStockingPointInPeriodPlanningLeaf(),
                                                            durationintrip_days // To un-age the stocks by leadtime so that they are back at their intended age
                                                          );
                                                                                                                                                         
    // Reassign the un-aged age vector back to source
    source_agevector.Resize( 0 );
    source_agevector.Append( source_agevector_aftermod );
         
    // Insert the index of the current DependentDemand within the sorted set into the vector
    dd_indexvector := NumberVector::Construct( dd_agevector.Size(),
                                               dependentdemands.Find( this ) );
    quantityvector.Append( dd_quantityvector );
    agevector.Append( dd_agevector );
    indexvector.Append( dd_indexvector );
  *]
}