/// <summary> /// Notifies the instance that a bundle was placed in a pod. /// </summary> /// <param name="bundle">The bundle that was stored.</param> /// <param name="pod">The pod the bundle was placed in.</param> internal void NotifyInitialBundleStored(ItemBundle bundle, Pod pod) { // Raise the event InitialBundleStored?.Invoke(bundle, pod); // Update inventory fill level StorageUsage += bundle.BundleWeight; }
/// <summary> /// Submits a new bundle storage assignment decision to the allocator. /// </summary> /// <param name="bundle">The bundle that is being assigned to a storage pod.</param> /// <param name="pod">The pod in which the bundle shall be stored.</param> public void Submit(ItemBundle bundle, Pod pod) { // Store assignment until the next allocation update _podAssignments[bundle] = pod; // Notify instance about final decision Instance.NotifyItemStorageAllocationAvailable(pod, bundle); }
/// <summary> /// Adds the transaction to the ready list. /// </summary> /// <param name="bundle">The bundle that is going to be transferred.</param> /// <param name="pod">The pod the bundle is transferred to.</param> protected void AddToReadyList(ItemBundle bundle, Pod pod) { if (!IsAboveRefillThreshold(pod, bundle)) { // Add decision to buffer list if (_bufferedBundles.ContainsKey(pod)) { _bufferedBundles[pod].Add(bundle); } else { _bufferedBundles.Add(pod, new List <ItemBundle> { bundle }); } // Remember this buffering _bufferedBundlesTimes[pod] = Instance.Controller.CurrentTime; } else { // Immediately submit the decision instead of buffering it Instance.Controller.Allocator.Submit(bundle, pod); } // Remove the bundle from the list of pending ones (if it was immediately assigned this operation is actually redundant) _pendingBundles.Remove(bundle); // Also notify the pod about the new bundle pod.RegisterBundle(bundle); // Notify the instance about the decision Instance.NotifyItemStorageDecided(pod, bundle); }
/// <summary> /// Updates the element to the specified time. /// </summary> /// <param name="lastTime">The time before the update.</param> /// <param name="currentTime">The time to update to.</param> public virtual void Update(double lastTime, double currentTime) { // Retrieve the next bundle that we have not seen so far ItemBundle newBundle = Instance.ItemManager.RetrieveBundle(this); while (newBundle != null) { // Add it to the not yet decided bundles list _pendingBundles.Add(newBundle); // Retrieve the next bundle that we have not seen so far newBundle = Instance.ItemManager.RetrieveBundle(this); // Mark new situation SituationInvestigated = false; } // Decide about remaining bundles if (!SituationInvestigated) { // Measure time for decision DateTime before = DateTime.Now; // Do the actual work DecideAboutPendingBundles(); // Calculate decision time Instance.Observer.TimeReplenishmentBatching((DateTime.Now - before).TotalSeconds); // Remember that we had a look at the situation SituationInvestigated = true; } }
public void SetupBundlePurchaseDetails(ItemBundle bundle) { CloudGoodsBundle bundlePriceState; if (bundle.CoinPrice <= 0 && bundle.CreditPrice <= 0) { bundlePriceState = CloudGoodsBundle.Free; } else if (bundle.CoinPrice <= 0) { bundlePriceState = CloudGoodsBundle.CreditPurchasable; } else if (bundle.CreditPrice <= 0) { bundlePriceState = CloudGoodsBundle.CoinPurchasable; } else { bundlePriceState = CloudGoodsBundle.CreditCoinPurchaseable; } ChangePurchaseButtonDisplay(bundle.CreditPrice, bundle.CoinPrice, bundlePriceState); currentItemBundle = bundle; BundleName.text = bundle.Name; SetUpBundleItemsDisplay(bundle.bundleItems); }
public ItemInfo(string name, string items, int needEnergy, float needTime) { this.name = name; this.requireBundles = ItemBundle.GetBundles(items); this.needEnergy = needEnergy; this.needTime = needTime; }
/// <summary> /// Notifies the instance that a bundle was placed in a pod. /// </summary> /// <param name="pod">The pod the bundle was placed in.</param> /// <param name="bot">The corresponding bot.</param> /// <param name="bundle">The bundle that was moved from the input-station to the pod.</param> /// <param name="station">The station the bundle was distributed from.</param> internal void NotifyBundleStored(InputStation station, Bot bot, Pod pod, ItemBundle bundle) { // Store the number of handled bundles pod.StatBundlesHandled++; StatOverallBundlesHandled++; // Mark every bundle in the history with a timestamp _statBundleHandlingTimestamps.Add(new BundleHandledDatapoint(StatTime, bot.ID, pod.ID, station.ID, Controller.CurrentTime - bundle.TimeStamp, Controller.CurrentTime - bundle.TimeStampSubmit)); // Flush data points in case there are too many already if (_statBundleHandlingTimestamps.Count > STAT_MAX_DATA_POINTS) { StatFlushBundlesHandled(); } // Keep track of the maximal number of handled bundles if (StatMaxBundlesHandledByPod < pod.StatBundlesHandled) { StatMaxBundlesHandledByPod = pod.StatBundlesHandled; } // Log turnover time _statBundleTurnoverTimes.Add(Controller.CurrentTime - bundle.TimeStamp); // Log throughput time _statBundleThroughputTimes.Add(Controller.CurrentTime - bundle.TimeStampSubmit); // Update inventory fill level StorageUsage += bundle.BundleWeight; StorageReserved -= bundle.BundleWeight; // Raise the event BundleStored?.Invoke(station, bot, pod, bundle); }
private void SignalItemStorageAllocationAvailable(Pod pod, ItemBundle bundle) { // This is another event this controller should react upon SituationInvestigated = false; // Add the bundle to the todo list _itemBundles.Add(bundle); // Save the pod where the bundle is assigned to _bundleToPod[bundle] = pod; // Store the time the batch was first seen if (!_podBundles.ContainsKey(pod) || !_podBundles[pod].Any()) { _waitingTime[pod] = Instance.Controller.CurrentTime; } // Assign the bundle to the batch or create a new one if (_podBundles.ContainsKey(pod)) { _podBundles[pod].Add(bundle); } else { _podBundles[pod] = new List <ItemBundle>() { bundle } }; }
/// <summary> /// Adds the specified item to the station. /// </summary> /// <param name="item">The item to add.</param> /// <returns><code>true</code> if the item was added successfully, <code>false</code> otherwise.</returns> public bool Add(ItemBundle item) { if (CapacityInUse + item.BundleWeight <= Capacity) { // Add the bundle if (Instance.SettingConfig.VisualizationAttached) { lock (_syncRoot) _itemBundles.Add(item); } else { _itemBundles.Add(item); } // Keep track of capacity CapacityInUse = _itemBundles.Sum(b => b.BundleWeight); // Remove the bundle from the reservation list _registeredBundles.Remove(item); CapacityReserved = _registeredBundles.Sum(b => b.BundleWeight); // Notify instance about the allocation Instance.NotifyBundleAllocated(this, item); // Reset down-time _statDepletionTime = double.PositiveInfinity; // Return success return(true); } else { // Return fail return(false); } }
/// <summary> /// Allocates the input request. /// </summary> /// <param name="bundle">The bundle to allocate.</param> /// <param name="pod">The pod the bundle shall be stored in.</param> /// <param name="station">The station that shall handle the bundle.</param> private void Allocate(ItemBundle bundle, Pod pod, InputStation station) { // Indicate change at instance Instance.Changed = true; // Check whether decision is possible if (station.CapacityInUse + bundle.BundleWeight > station.Capacity) { throw new InvalidOperationException("Allocating the bundle to the station would exceed its capacity!"); } if (Instance.ControllerConfig.ItemStorageConfig.GetMethodType() != ItemStorageMethodType.Dummy && pod.CapacityInUse + bundle.BundleWeight > pod.Capacity) { throw new InvalidOperationException("Allocating the bundle to the pod would exceed its capacity!"); } // Remove from ready lists _iStationAssignments.Remove(bundle); _podAssignments.Remove(bundle); // Add the bundle to the station station.Add(bundle); // Mark the pod at the bundle bundle.Pod = pod; // Add storage request Instance.ResourceManager.NewItemBundleAssignedToStation(bundle, station, pod); // Notify item manager Instance.ItemManager.NewBundleAssignedToStation(station, bundle); // Remove bundle from item manager (Instance.ItemManager as ItemManager).TakeAvailableBundle(bundle); }
/// <summary> /// Notifies the instance that a bundle was allocated. /// </summary> internal void NotifyBundleAllocated(InputStation iStation, ItemBundle bundle) { // Store the time the bundle was submitted to the system bundle.TimeStampSubmit = Controller.CurrentTime; // Raise the event BundleAllocated?.Invoke(iStation, bundle); }
public static Models.Repository.ItemBundle CreateDtoItemBundle(this ItemBundle itemBundle) { return(new Models.Repository.ItemBundle { DisplayName = itemBundle.DisplayName, TenantId = itemBundle.TenantId }); }
/// <summary> /// Checks whether the given pod is ready for refill or has to be buffered some more. /// </summary> /// <param name="pod">The pod to check.</param> /// <param name="newBundle">The additional bundle to take into account.</param> /// <returns><code>true</code> if the pod is ready to be refilled, <code>false</code> otherwise.</returns> private bool IsAboveRefillThreshold(Pod pod, ItemBundle newBundle) { return // Check whether we are above the capacity threshold ((pod.CapacityInUse + pod.CapacityReserved + newBundle.BundleWeight) / pod.Capacity >= GetStorageBufferThreshold(pod) || // Additionally check for a buffering timeout Instance.Controller.CurrentTime - GetLastBufferingTime(pod) >= GetStorageBufferTimeout(pod)); }
/// <summary> /// Selects a pod for a bundle generated during initialization. /// </summary> /// <param name="instance">The active instance.</param> /// <param name="bundle">The bundle to assign to a pod.</param> /// <returns>The selected pod.</returns> public override Pod SelectPodForInititalInventory(Instance instance, ItemBundle bundle) { // Add to a random pod return(instance.Pods .Where(p => p.FitsForReservation(bundle)) .OrderBy(p => instance.Randomizer.NextDouble()) .First()); }
/// <summary> /// Notifies the instance that a bundle was registered with a pod. /// </summary> /// <param name="pod">The pod the bundle was registered with.</param> /// <param name="bundle">The bundle that was moved from the input-station to the pod.</param> internal void NotifyBundleRegistered(Pod pod, ItemBundle bundle) { // Update reserved fill level StorageReserved += bundle.BundleWeight; StorageBacklog -= bundle.BundleWeight; // Raise the event BundleRegistered?.Invoke(pod, bundle); }
void Update() { if (bundlePurchasing.currentItemBundle != itemBundle) { currentBundleIndex = 0; itemBundle = bundlePurchasing.currentItemBundle; SetBundleItemToDisplay(currentBundleIndex); } }
/// <summary> /// Reserves capacity of this station for the given bundle. The reserved capacity will be maintained when the bundle is allocated. /// </summary> /// <param name="bundle">The bundle for which capacity shall be reserved.</param> internal void RegisterBundle(ItemBundle bundle) { _registeredBundles.Add(bundle); CapacityReserved = _registeredBundles.Sum(b => b.BundleWeight); if (CapacityInUse + CapacityReserved > Capacity) { throw new InvalidOperationException("Cannot reserve more capacity than this station has!"); } }
public async Task CreateItemBundleAsync(ItemBundle itemBundle, CancellationToken cancellationToken = default) { if (itemBundle == null) { throw new ArgumentNullException(nameof(itemBundle)); } await itemBundleRepository.AddAsync(itemBundle.CreateDtoItemBundle(), cancellationToken); }
public void SetupBundlePurchaseDetails(ItemBundle bundle) { ChangePurchaseButtonDisplay(bundle.CreditPrice, bundle.CoinPrice, bundle.State); currentItemBundle = bundle; BundleName.text = bundle.Name; SetUpBundleItemsDisplay(bundle.bundleItems); }
/// <summary> /// Selects a pod for a bundle generated during initialization. /// </summary> /// <param name="instance">The active instance.</param> /// <param name="bundle">The bundle to assign to a pod.</param> /// <returns>The selected pod.</returns> public override Pod SelectPodForInititalInventory(Instance instance, ItemBundle bundle) { // Add to a pod with similar content Pod pod = instance.Pods .Where(b => b.FitsForReservation(bundle)) .OrderByDescending(p => p.ItemDescriptionsContained.Sum(containedItem => instance.FrequencyTracker.GetMeasuredFrequency(bundle.ItemDescription, containedItem))) .First(); return(pod); }
public void SetupUnityUIItemBundle(ItemBundle newItemBundle, UnityUIBundlePurchasing purchasing) { itemBundle = newItemBundle; bundlePurchasing = purchasing; CloudGoods.GetItemTexture(itemBundle.Image, OnReceivedItemTexture); Button button = GetComponent <Button>(); button.onClick.AddListener(OnClickedItemBundle); }
/// <summary> /// Adds the transaction to the ready list. /// </summary> /// <param name="bundle">The bundle that is going to be transferred.</param> /// <param name="station">The station the bundle is distributed from.</param> protected void AddToReadyList(ItemBundle bundle, InputStation station) { // Update capacity information station.RegisterBundle(bundle); // Update lists _pendingBundles.Remove(bundle); // Submit the decision Instance.Controller.Allocator.Submit(bundle, station); // Notify the instance about the decision Instance.NotifyReplenishmentBatchingDecided(station, bundle); }
/// <summary> /// Reserves capacity of this pod for the given bundle. The reserved capacity will be maintained when the bundle is allocated. /// </summary> /// <param name="bundle">The bundle for which capacity shall be reserved.</param> internal void RegisterBundle(ItemBundle bundle) { _registeredBundles.Add(bundle); CapacityReserved = _registeredBundles.Sum(b => b.BundleWeight); if (CapacityInUse + CapacityReserved > Capacity) { throw new InvalidOperationException("Cannot reserve more capacity than this pod has!"); } // Notify the instance about the reservation Instance.NotifyBundleRegistered(this, bundle); }
public static ItemBundle[] GetBundles(string txt) { var comma = txt.Split(','); int count = comma.Length; var bundles = new ItemBundle[count]; for (int i = 0; i < count; i++) { bundles[i] = new ItemBundle(comma[i]); } return(bundles); }
public StrawberryPlant() { MyPlantType = PlantType.kStrawBerryType; _GrowTime = 10; this.Name = "StrawberryPlant"; _MyDrops = new ItemBundle(); _MyDrops.outputID = Enums.ItemID.kItemStrawberry; _MyDrops.amount = 3; _MyDrops.odds = 100; CurrentDrop = _MyDrops; Setup(); }
public List <ItemBundle> ConvertToListItemBundle(string dataString) { List <ItemBundle> ItemBundles = new List <ItemBundle>(); string parsedString = ParseString(dataString); JsonData itemBundleData = LitJson.JsonMapper.ToObject(parsedString); for (int i = 0; i < itemBundleData.Count; i++) { ItemBundle itemBundle = new ItemBundle(); itemBundle.ID = int.Parse(itemBundleData[i]["ID"].ToString()); itemBundle.Name = itemBundleData[i]["Name"].ToString(); itemBundle.Description = itemBundleData[i]["Description"].ToString(); itemBundle.CreditPrice = int.Parse(itemBundleData[i]["CreditPrice"].ToString()); itemBundle.CoinPrice = int.Parse(itemBundleData[i]["CoinPrice"].ToString()); itemBundle.State = (CloudGoodsBundle)Enum.Parse(typeof(CloudGoodsBundle), itemBundleData[i]["State"].ToString()); itemBundle.Image = itemBundleData[i]["Image"].ToString(); //TODO Implement itembundle behaviours JsonData BundleItemData = itemBundleData[i]["items"]; for (int j = 0; j < BundleItemData.Count; j++) { BundleItem bundleItem = new BundleItem(); bundleItem.Quantity = int.Parse(BundleItemData[j]["Quantity"].ToString()); bundleItem.Name = BundleItemData[j]["Name"].ToString(); bundleItem.Image = BundleItemData[j]["Image"].ToString(); bundleItem.Description = BundleItemData[j]["Description"].ToString(); bundleItem.Quality = int.Parse(BundleItemData[j]["Quality"].ToString()); JsonData bundleItemDetailData = LitJson.JsonMapper.ToObject(BundleItemData[j]["Detail"].ToString()); for (int k = 0; k < bundleItemDetailData.Count; k++) { BundleItemDetails bundleDetails = new BundleItemDetails(); bundleDetails.BundleDetailName = bundleItemDetailData[k]["Name"].ToString(); bundleDetails.Value = float.Parse(bundleItemDetailData[k]["Value"].ToString()); bundleItem.bundleItemDetails.Add(bundleDetails); } itemBundle.bundleItems.Add(bundleItem); } ItemBundles.Add(itemBundle); } return(ItemBundles); }
/// <summary> /// Selects a pod for a bundle generated during initialization. /// </summary> /// <param name="instance">The active instance.</param> /// <param name="bundle">The bundle to assign to a pod.</param> /// <returns>The selected pod.</returns> public override Pod SelectPodForInititalInventory(Instance instance, ItemBundle bundle) { // Just choose a pod as if the system was already running Pod chosenPod = ChoosePod(bundle); if (chosenPod == null) { throw new InvalidOperationException("Could not find a pod for the given bundle - are we at capacity?"); } else { return(chosenPod); } }
private void SignalBundleStored(InputStation station, Bot bot, Pod pod, ItemBundle bundle) { // Init, if necessary if (_currentActualStock == null) { InitStockInfo(); } // Update overall load information CurrentActualOverallLoad += bundle.BundleWeight; // Update actual stock information _currentActualStock[bundle.ItemDescription] += bundle.ItemCount; // Update available stock information _currentAvailableStock[bundle.ItemDescription] += bundle.ItemCount; }
public async Task <Guid> AddAsync(ItemBundle itemBundle, CancellationToken cancellationToken = default) { if (itemBundle == null) { throw new ArgumentNullException(); } await toolShedContext.ItemBundleSet .AddAsync(itemBundle, cancellationToken); await toolShedContext.SaveChangesAsync(cancellationToken); return(itemBundle.ItemBundleId); }
/// <summary> /// Called whenever a new item has been assigned to an InputStation /// </summary> /// <param name="item">The assigned item.</param> /// <param name="inputStation">The InputStation the item is assigned to.</param> /// <param name="pod">The pod to store this item in.</param> public void NewItemBundleAssignedToStation(ItemBundle item, InputStation inputStation, Pod pod) { InsertRequest request = new InsertRequest(item, inputStation, pod); _availableStoreRequests.Add(request); if (request.Station != null) { _availableStoreRequestsPerStation[request.Station].Add(request); request.Station.StatCurrentlyOpenRequests = _availableStoreRequestsPerStation[request.Station].Count; } if (request.Pod != null) { _availableStoreRequestsPerPod[request.Pod].Add(request); } }
public List<ItemBundle> ConvertToListItemBundle(string dataString) { List<ItemBundle> ItemBundles = new List<ItemBundle>(); string parsedString = ParseString(dataString); JsonData itemBundleData = LitJson.JsonMapper.ToObject(parsedString); for (int i = 0; i < itemBundleData.Count; i++) { ItemBundle itemBundle = new ItemBundle(); itemBundle.ID = int.Parse(itemBundleData[i]["ID"].ToString()); itemBundle.Name = itemBundleData[i]["Name"].ToString(); itemBundle.Description = itemBundleData[i]["Description"].ToString(); itemBundle.CreditPrice = int.Parse(itemBundleData[i]["CreditPrice"].ToString()); itemBundle.CoinPrice = int.Parse(itemBundleData[i]["CoinPrice"].ToString()); itemBundle.State = int.Parse(itemBundleData[i]["State"].ToString()); //TODO Implement itembundle behaviours JsonData BundleItemData = itemBundleData[i]["items"]; for (int j = 0; j < BundleItemData.Count; j++) { BundleItem bundleItem = new BundleItem(); bundleItem.Quantity = int.Parse(BundleItemData[j]["Quantity"].ToString()); bundleItem.Name = BundleItemData[j]["Name"].ToString(); bundleItem.Image = BundleItemData[j]["Image"].ToString(); bundleItem.Description = BundleItemData[j]["Description"].ToString(); bundleItem.Quality = int.Parse(BundleItemData[j]["Quality"].ToString()); JsonData bundleItemDetailData = LitJson.JsonMapper.ToObject(BundleItemData[j]["Detail"].ToString()); for (int k = 0; k < bundleItemDetailData.Count; k++) { BundleItemDetails bundleDetails = new BundleItemDetails(); bundleDetails.BundleDetailName = bundleItemDetailData[k]["Name"].ToString(); bundleDetails.Value = int.Parse(bundleItemDetailData[k]["Value"].ToString()); bundleItem.bundleItemDetails.Add(bundleDetails); } itemBundle.bundleItems.Add(bundleItem); } ItemBundles.Add(itemBundle); } return ItemBundles; }
public void SetupNGUIItemBundle(ItemBundle newItemBundle, BundlePurchasing purchasing) { itemBundle = newItemBundle; bundlePurchasing = purchasing; }