| Quintiq file version 2.0 | 
| #parent: #root | 
| Method ZeroCapacityReplenishment ( | 
|   MacroPlan macroPlan, | 
|   Real timeDifference, | 
|   UnitPeriodTimeBase uptb, | 
|   UnitPeriodTimeBases uptbs | 
| ) | 
| { | 
|   TextBody: | 
|   [* | 
|     debuginfo( "需要补零的时间(单位:小时)", timeDifference, "    需要补零的产能周期的开始时间:", uptb.StartDate().Format( "Y-M2-D2" ) ); | 
|          | 
|     //debuginfo( "考虑库存、lotsize" ); | 
|     //traverse ( unitPeriodTimeBase, PeriodTaskOperation, pto, timeDifference > 0 ) {  | 
|     //  minimumQuantityThatCanBeBorrowed := Real::MaxReal(); | 
|     //  minimumCapacityThatCanBeBorrowed := Real::MaxReal(); | 
|     //  traverse ( pto, NewSupply, ns, true ) { | 
|     //    targetBorrowSplitShiftLotsizeLimit := select( scenarioManager, SplitShiftLotsizeLimit, tempSSLL, tempSSLL.unitID() = unitPeriodTimeBase.UnitID() and | 
|     //                                                                                                     tempSSLL.productID() = ns.ProductInStockingPointInPeriodPlanningLeaf().ProductInStockingPoint_MP().ProductID() and | 
|     //                                                                                                     tempSSLL.startTime() <= ns.Start().Date() and | 
|     //                                                                                                     tempSSLL.endTime() >= ns.End().Date() ); | 
|     //    minimumQuantityThatCanBeBorrowed := minvalue( | 
|     //                                                  minvalue( ifexpr( not isnull( targetBorrowSplitShiftLotsizeLimit ) and targetBorrowSplitShiftLotsizeLimit.lotsize() < ns.Quantity(),  | 
|     //                                                                    ns.Quantity() - targetBorrowSplitShiftLotsizeLimit.lotsize(),  | 
|     //                                                                    Real::MaxReal() ), | 
|     //                                                            minvalue(  | 
|     //                                                                      ifexpr( ( ns.ProductInStockingPointInPeriodPlanningLeaf().InventoryLevelEnd() - ns.ProductInStockingPointInPeriodPlanningLeaf().MinInventoryLevel() ) > 0,  | 
|     //                                                                                ns.ProductInStockingPointInPeriodPlanningLeaf().InventoryLevelEnd() - ns.ProductInStockingPointInPeriodPlanningLeaf().MinInventoryLevel(),  | 
|     //                                                                                0.0  | 
|     //                                                                             ),  | 
|     //                                                                      ns.Quantity()     | 
|     //                                                                     )  | 
|     //                                                           ), | 
|     //                                                  minimumQuantityThatCanBeBorrowed  | 
|     //                                                 ); | 
|     //  } | 
|     //  minimumCapacityThatCanBeBorrowed := minimumQuantityThatCanBeBorrowed / pto.Operation().Throughput(); | 
|     //  nextUnitPeriodTimeBase := ifexpr( isnull( unitPeriodTimeBase.Next().astype( UnitPeriodTimeBase ) ), select( unitPeriodTimeBases, Elements, tempUPTB, tempUPTB.Start() = unitPeriodTimeBase.End() ), unitPeriodTimeBase.Next().astype( UnitPeriodTimeBase ) ); | 
|     //  while ( timeDifference > 0 and not isnull( nextUnitPeriodTimeBase ) and minimumCapacityThatCanBeBorrowed > 0 ) { | 
|     //    acceptableCapacity := ifexpr( ( nextUnitPeriodTimeBase.TotalAvailableCapacity().HoursAsReal() - nextUnitPeriodTimeBase.UsedCapacity().HoursAsReal() ) > 0, | 
|     //                                    nextUnitPeriodTimeBase.TotalAvailableCapacity().HoursAsReal() - nextUnitPeriodTimeBase.UsedCapacity().HoursAsReal(), | 
|     //                                    0.0 ); | 
|     //    unifiedProcessingTimeOfComplementZero := minvalue( timeDifference, minimumCapacityThatCanBeBorrowed, acceptableCapacity ); | 
|     //    debuginfo( "接纳的周期时间:", nextUnitPeriodTimeBase.StartDate().Format( "Y-M2-D2" ), String::Tab(),  | 
|     //               "接纳的周期能接受的产能:", acceptableCapacity, String::Tab(), | 
|     //               "剩余补零的产能:", timeDifference, String::Tab(), | 
|     //               "统一转移的产能:", unifiedProcessingTimeOfComplementZero, String::Tab() | 
|     //              ); | 
|     //    this.A_unifiedProcessingOfComplementZeroLogic( unifiedProcessingTimeOfComplementZero, pto, nextUnitPeriodTimeBase, macroPlan ); | 
|     //    minimumCapacityThatCanBeBorrowed := minimumCapacityThatCanBeBorrowed - unifiedProcessingTimeOfComplementZero; | 
|     //    timeDifference := timeDifference - unifiedProcessingTimeOfComplementZero; | 
|     //    if ( isnull( nextUnitPeriodTimeBase.Next() ) ) { | 
|     //      nextUnitPeriodTimeBase := select( unitPeriodTimeBases, Elements, tempUPTB, tempUPTB.Start() = nextUnitPeriodTimeBase.End() ); | 
|     //    } else { | 
|     //      nextUnitPeriodTimeBase := nextUnitPeriodTimeBase.Next().astype( UnitPeriodTimeBase ); | 
|     //    } | 
|     //  } | 
|     //} | 
|          | 
|     debuginfo( "不考虑库存、lotsize使其达到整班" ); | 
|     traverse ( uptb, PeriodTaskOperation, pto, timeDifference > 0 ) {  | 
|       minimumQuantityThatCanBeBorrowed := Real::MaxReal(); | 
|       minimumCapacityThatCanBeBorrowed := Real::MaxReal(); | 
|       traverse ( pto, NewSupply, ns, true ) { | 
|         minimumQuantityThatCanBeBorrowed := minvalue(  | 
|                                                       minvalue(  | 
|                                                                 ifexpr( ( ns.ProductInStockingPointInPeriodPlanningLeaf().InventoryLevelEnd() - ns.ProductInStockingPointInPeriodPlanningLeaf().MinInventoryLevel() ) > 0,  | 
|                                                                           ns.ProductInStockingPointInPeriodPlanningLeaf().InventoryLevelEnd() - ns.ProductInStockingPointInPeriodPlanningLeaf().MinInventoryLevel(),  | 
|                                                                           0.0  | 
|                                                                        ),  | 
|                                                                 ns.Quantity()     | 
|                                                                ),  | 
|                                                       minimumQuantityThatCanBeBorrowed  | 
|                                                      ); | 
|       } | 
|       minimumCapacityThatCanBeBorrowed := minimumQuantityThatCanBeBorrowed / pto.Operation().Throughput(); | 
|       nextUnitPeriodTimeBase := ifexpr( isnull( uptb.Next().astype( UnitPeriodTimeBase ) ), select( uptbs, Elements, tempUPTB, tempUPTB.Start() = uptb.End() ), uptb.Next().astype( UnitPeriodTimeBase ) ); | 
|       while ( timeDifference > 0 and not isnull( nextUnitPeriodTimeBase ) and minimumCapacityThatCanBeBorrowed > 0 ) { | 
|         acceptableCapacity := /*ifexpr( ( nextUnitPeriodTimeBase.TotalAvailableCapacity().HoursAsReal() - nextUnitPeriodTimeBase.UsedCapacity().HoursAsReal() ) > 0, | 
|                                         nextUnitPeriodTimeBase.TotalAvailableCapacity().HoursAsReal() - nextUnitPeriodTimeBase.UsedCapacity().HoursAsReal(), | 
|                                         0.0 )*/ | 
|                               ifexpr( nextUnitPeriodTimeBase.FreeCapacity().HoursAsReal() > 0, | 
|                                       nextUnitPeriodTimeBase.FreeCapacity().HoursAsReal(), | 
|                                       0.0 ); | 
|         unifiedProcessingTimeOfComplementZero := minvalue( timeDifference, minimumCapacityThatCanBeBorrowed, acceptableCapacity ); | 
|         debuginfo( "接纳的周期时间:", nextUnitPeriodTimeBase.StartDate().Format( "Y-M2-D2" ), String::Tab(),  | 
|                    "接纳的周期能接受的产能:", acceptableCapacity, String::Tab(), | 
|                    "剩余补零的产能:", timeDifference, String::Tab(), | 
|                    "统一转移的产能:", unifiedProcessingTimeOfComplementZero, String::Tab() | 
|                   ); | 
|         if ( unifiedProcessingTimeOfComplementZero > 0.0 ) { | 
|           this.UnifiedProcessingOfComplementZeroLogic( unifiedProcessingTimeOfComplementZero, pto, nextUnitPeriodTimeBase, macroPlan ); | 
|         } | 
|         minimumCapacityThatCanBeBorrowed := minimumCapacityThatCanBeBorrowed - unifiedProcessingTimeOfComplementZero; | 
|         timeDifference := timeDifference - unifiedProcessingTimeOfComplementZero; | 
|         if ( isnull( nextUnitPeriodTimeBase.Next() ) ) { | 
|           nextUnitPeriodTimeBase := select( uptbs, Elements, tempUPTB, tempUPTB.Start() = nextUnitPeriodTimeBase.End() ); | 
|         } else { | 
|           nextUnitPeriodTimeBase := nextUnitPeriodTimeBase.Next().astype( UnitPeriodTimeBase ); | 
|         } | 
|       } | 
|     } | 
|   *] | 
| } |