/// <summary> /// Finalizes the instance. /// </summary> public void Flush() { // Set references to this object Compound.Instance = this; foreach (var instanceElement in Bots.AsEnumerable <InstanceElement>() .Concat(Pods.AsEnumerable <InstanceElement>()) .Concat(Elevators.AsEnumerable <InstanceElement>()) .Concat(InputStations.AsEnumerable <InstanceElement>()) .Concat(OutputStations.AsEnumerable <InstanceElement>()) .Concat(Waypoints.AsEnumerable <InstanceElement>()) .Concat(ItemDescriptions.AsEnumerable <InstanceElement>()) .Concat(ItemBundles.AsEnumerable <InstanceElement>())) { instanceElement.Instance = this; } //TODO:why is the code below commented out?? //// Generate Waypointgraph //WaypointGraph = new WaypointGraph(); //foreach (var waypoint in Waypoints) //{ // WaypointGraph.Add(waypoint); //} }
/// <summary> /// Creates a new input-station. /// </summary> /// <param name="id">The ID of the input station.</param> /// <param name="tier">The position (tier).</param> /// <param name="x">The position (x-coordinate).</param> /// <param name="y">The position (y-coordinate).</param> /// <param name="radius">The radius of the station.</param> /// <param name="capacity">The capacity of the station.</param> /// <param name="itemBundleTransfertime">The time it takes to handle one bundle at the station.</param> /// <param name="activationOrderID">The order ID of the station that defines the sequence in which the stations have to be activated.</param> /// <returns>The newly created input station.</returns> public InputStation CreateInputStation(int id, Tier tier, double x, double y, double radius, double capacity, double itemBundleTransfertime, int activationOrderID) { // Consider override values if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideInputStationCapacity) { capacity = SettingConfig.OverrideConfig.OverrideInputStationCapacityValue; } if (SettingConfig.OverrideConfig != null && SettingConfig.OverrideConfig.OverrideInputStationItemBundleTransferTime) { itemBundleTransfertime = SettingConfig.OverrideConfig.OverrideInputStationItemBundleTransferTimeValue; } // Init InputStation inputStation = new InputStation(this) { ID = id, Tier = tier, Radius = radius, X = x, Y = y, Capacity = capacity, ItemBundleTransferTime = itemBundleTransfertime, ActivationOrderID = activationOrderID }; inputStation.Queues = new Dictionary <Waypoint, List <Waypoint> >(); InputStations.Add(inputStation); tier.AddInputStation(inputStation); _idToInputStations[inputStation.ID] = inputStation; // Determine volatile ID int volatileID = 0; while (_volatileInputStationIDs.Contains(volatileID)) { volatileID++; } inputStation.VolatileID = volatileID; _volatileInputStationIDs.Add(inputStation.VolatileID); return(inputStation); }
/// <summary> /// Registers and returns a new ID for an object of the given type. /// </summary> /// <returns>A new unique ID that can be used to identify the object.</returns> public int RegisterInputStationID() { if (InputStations.Any() && _inputStationID <= InputStations.Max(e => e.ID)) { _inputStationID = InputStations.Max(e => e.ID) + 1; } return(_inputStationID++); }
/// <summary> /// Remove all stations from the instance. This is only usable for visualization purposes. /// </summary> public void VisClearStations() { InputStations.Clear(); OutputStations.Clear(); foreach (var tier in Compound.Tiers) { tier.InputStations.Clear(); tier.OutputStations.Clear(); } }
/// <summary> /// Removes all elements in scope from the instance. /// </summary> /// <param name="theTier">The tier to remove the elements from.</param> /// <param name="xMin">The min x-value of the scope.</param> /// <param name="xMax">The max x-value of the scope.</param> /// <param name="yMin">The min y-value of the scope.</param> /// <param name="yMax">The max y-value of the scope.</param> public void ModRemoveWaypoints(ITierInfo theTier, double xMin, double yMin, double xMax, double yMax) { Tier tier = theTier as Tier; // Remove waypoints List <Waypoint> remWaypoints = Waypoints.Where(w => w.Tier == tier && xMin <= w.X && w.X <= xMax && yMin <= w.Y && w.Y <= yMax).ToList(); // Remove all of them foreach (var waypoint in remWaypoints) { // Remove the waypoint - the waypoint graph handles all cascading path removals waypoint.Tier.RemoveWaypoint(waypoint); // Remove all elements that were connected to the waypoint foreach (var guard in Semaphores.SelectMany(s => s.Guards).Where(guard => guard.From == waypoint || guard.To == waypoint).ToArray()) { guard.Semaphore.UnregisterGuard(guard); if (guard.Semaphore.Guards.Count() == 0) { Semaphores.Remove(guard.Semaphore); } } foreach (var station in InputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveInputStation(station); InputStations.Remove(station); } foreach (var station in OutputStations.Where(s => s.Waypoint == waypoint).ToArray()) { station.Tier.RemoveOutputStation(station); OutputStations.Remove(station); } foreach (var pod in Pods.Where(p => p.Waypoint == waypoint).ToArray()) { pod.Tier.RemovePod(pod); Pods.Remove(pod); } foreach (var elevator in Elevators.Where(e => e.ConnectedPoints.Contains(waypoint))) { elevator.UnregisterPoint(waypoint); if (elevator.ConnectedPoints.Count == 0) { Elevators.Remove(elevator); } } // Make sure it is not on the list of storage locations anymore if (waypoint.PodStorageLocation) { ResourceManager.RemovePodStorageLocation(waypoint); } // Finally remove from the overall waypoint list Waypoints.Remove(waypoint); } // Also remove movables in scope List <Bot> remBots = Bots.Where(b => b.Tier == tier && xMin <= b.X && b.X <= xMax && yMin <= b.Y && b.Y <= yMax).ToList(); foreach (var bot in remBots) { Bots.Remove(bot); bot.Tier.RemoveBot(bot); } List <Pod> remPods = Pods.Where(p => p.Tier == tier && xMin <= p.X && p.X <= xMax && yMin <= p.Y && p.Y <= yMax).ToList(); foreach (var pod in remPods) { Pods.Remove(pod); pod.Tier.RemovePod(pod); } }