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 ); 
 | 
  *] 
 | 
} 
 |