private void PodItemReserved(Pod pod, ItemDescription item, Management.ExtractRequest request)
 {
     // Skip callback, if inactive
     if (!_instance.SettingConfig.MonitorWellSortedness)
     {
         return;
     }
     // Return if not in use yet
     if (_podsContainingItems == null)
     {
         return;
     }
     // --> Remove pod from list of pods offering the item, if it was the last one
     if (!pod.IsAvailable(item))
     {
         _podsAvailableItems[item].Remove(pod);
     }
 }
        private void ItemExtracted(Pod pod, ItemDescription item)
        {
            // Skip callback, if inactive
            if (!_instance.SettingConfig.MonitorWellSortedness)
            {
                return;
            }
            // Return if not in use yet
            if (_podsContainingItems == null)
            {
                return;
            }
            // --> Update pod utility
            int  itemDemand       = _instance.StockInfo.GetCurrentDemand(item);
            bool updateUtilityMax = false;

            // Update demand by new content of pod (pod lost one of these items)
            if (itemDemand >= pod.CountContained(item))
            {
                // The demand for this item is still high, but we can now supply one item less (because the content is low in comparison to the demand)
                _podUtility[pod]--;
                // Check whether utility max has to be updated
                if (pod == _podUtilityMaxPod)
                {
                    updateUtilityMax = true;
                }
            }
            // Update to new demand (demand for the given item sunk by one)
            foreach (var itemPod in _podsContainingItems[item])
            {
                // If the demand for the item is less then the pod content, we need to update to the new demand by decreasing the utility by one
                if (itemDemand < itemPod.CountContained(item))
                {
                    _podUtility[itemPod]--;
                    // Check whether utility max has to be updated
                    if (itemPod == _podUtilityMaxPod)
                    {
                        updateUtilityMax = true;
                    }
                }
            }
            // Refresh new max
            if (updateUtilityMax)
            {
                VolatileKeyValuePair <Pod, double> bestUtility = _podUtility.ArgMax(pu => pu.Value);
                _podUtilityMaxPod = bestUtility.Key;
                PodUtilityMax     = bestUtility.Value;
            }
            // --> Remove pod from list of pods containing / offering the item, if it was the last one
            if (!pod.IsAvailable(item))
            {
                _podsAvailableItems[item].Remove(pod);
            }
            if (!pod.IsContained(item))
            {
                _podsContainingItems[item].Remove(pod);
            }
            // --> Update pod speed
            _podSpeed[pod] -= _instance.FrequencyTracker.GetStaticFrequency(item);
            if (pod == _podSpeedMaxPod)
            {
                // Refresh max value
                VolatileKeyValuePair <Pod, double> bestSpeed = _podSpeed.ArgMax(ps => ps.Value);
                _podSpeedMaxPod = bestSpeed.Key;
                PodSpeedMax     = bestSpeed.Value;
            }
        }