Beispiel #1
0
        public IReadOnlyDictionary <Item, TransferData> GetRouteTotalTransfers(bool skipForOnlyOneVehicle = true)
        {
            if (!HasValidData || VehicleSchedule.Vehicle.Route != null)
            {
                TaskTransfers totalTransfers = new TaskTransfers();
                VehicleRoute  route          = VehicleSchedule.Vehicle.Route;
                if (skipForOnlyOneVehicle && route.Vehicles.Count == 1)
                {
                    return(null);
                }
                foreach (Vehicle vehicle in route.Vehicles.ToArray())
                {
                    if (vehicle.IsEnabled)
                    {
                        VehicleScheduleData vehicleData = VehicleScheduleDataManager.Current[vehicle];
                        float?mult;
                        if (vehicleData == null || !vehicleData.Capacity.HasValidData || (mult = vehicleData.ScheduleMonthlyMultiplier) == null)
                        {
                            return(null);
                        }
                        totalTransfers.Add(vehicleData.Capacity.TotalTransfers, mult, vehicleData.ScheduleAvereageDuration.Estimated);
                    }
                }

                return(totalTransfers.Transfers);
            }
            return(null);
        }
Beispiel #2
0
        /**
         * Simulate transfer task on provided storages.
         */
        private bool Transfer(TransferTask transferTask, Dictionary <VehicleUnit, StorageState> storages, ref TaskTransfers taskTransfers, ref TaskTransfers[] taskTransfersPerUnit, bool calculateTransfer = false, bool calculateTransferPerUnit = false)
        {
            ImmutableUniqueList <VehicleUnit> targetUnits = transferTask.GetTargetUnits();
            int targetUnitsCount = targetUnits.Count;

            Dictionary <VehicleUnit, int> loadingLimits = Manager <AdvancedTransferTaskAdapter> .Current?.GetCapacityLimits(transferTask, storages);

            for (int k = 0; k < targetUnitsCount; k++)
            {
                VehicleUnit targetUnit = targetUnits[k];
                if (storages.TryGetValue(targetUnit, out StorageState storage))
                {
                    if (storage.storage == null)
                    {
                        //autorefitable storage = cannot determine transfer
                        return(false);
                    }

                    int newCount;
                    if (loadingLimits != null && loadingLimits.TryGetValue(targetUnit, out int limit))
                    {
                        newCount = transferTask is LoadTask
                            ? Math.Max(storage.count, limit)
                            : Math.Min(storage.count, limit);
                    }
                    else
                    {
                        newCount = transferTask is LoadTask ? storage.storage.Capacity : 0;
                    }

                    if (storage.count != newCount)
                    {
                        if (calculateTransfer)
                        {
                            if (taskTransfers == null)
                            {
                                taskTransfers = new TaskTransfers();
                            }
                            taskTransfers.Add(storage.storage.Item, newCount - storage.count);
                        }
                        if (calculateTransferPerUnit)
                        {
                            int unitIndex = targetUnit.Vehicle.Units.IndexOf(targetUnit);
                            if (taskTransfersPerUnit == null)
                            {
                                taskTransfersPerUnit = new TaskTransfers[targetUnit.Vehicle.Units.Count];
                            }
                            if (taskTransfersPerUnit[unitIndex] == null)
                            {
                                taskTransfersPerUnit[unitIndex] = new TaskTransfers();
                            }
                            taskTransfersPerUnit[unitIndex].Add(storage.storage.Item, newCount - storage.count);
                        }
                        storage.count        = newCount;
                        storages[targetUnit] = storage;
                    }
                }
            }
            return(true);
        }
 public void Add(VehicleStationLocation station, TaskTransfers transfers, float?multiplier = null, bool estimated = false)
 {
     if (isReadonly)
     {
         throw new InvalidOperationException("TransfersPerStation is readonly");
     }
     if (_transfPerSt.TryGetValue(station, out TaskTransfers taskTransf))
     {
         taskTransf.Add(transfers, multiplier, estimated);
     }
     else
     {
         _transfPerSt.Add(station, new TaskTransfers(transfers, multiplier, estimated));
     }
 }
        public (IReadOnlyDictionary <Item, TransferData> tranfers, bool incompleteTransfers, bool estimatedTransfers) GetTransfers(VehicleStation station)
        {
            TaskTransfers transfersSum        = new TaskTransfers();
            bool          incompleteTransfers = false;
            bool          estimatedTransfers  = false;

            foreach (VehicleStation connStation in LazyManager <StationDemandManager> .Current.GetConnectedStationsEnum(station, true))
            {
                ImmutableList <Vehicle> vehicles = LazyManager <VehicleStationLocationManager> .Current.GetServicedVehicles(connStation.Location);

                Manager <VehicleScheduleDataManager> .Current.GetStationTaskTransfersSum(vehicles, connStation.Location, out bool incomplTransf, out bool isEstimated, transfersSum);

                incompleteTransfers |= incomplTransf;
                estimatedTransfers  |= isEstimated;
            }
            return(transfersSum.Transfers, incompleteTransfers, estimatedTransfers);
        }
Beispiel #5
0
        public IReadOnlyDictionary <Item, TransferData> GetRouteTaskTransfers(RootTask task, bool skipForOnlyOneVehicle = true)
        {
            if (task == null)
            {
                throw new ArgumentNullException("task");
            }
            if (!HasValidData || VehicleSchedule.Vehicle.Route != null)
            {
                TaskTransfers routeTransfers = new TaskTransfers();
                VehicleRoute  route          = VehicleSchedule.Vehicle.Route;
                if (skipForOnlyOneVehicle && route.Vehicles.Count == 1)
                {
                    return(null);
                }
                int taskIndex = task.GetIndex();
                foreach (Vehicle vehicle in route.Vehicles.ToArray())
                {
                    if (vehicle.IsEnabled)
                    {
                        VehicleScheduleData vehicleData = VehicleScheduleDataManager.Current[vehicle];
                        float?mult;
                        if (vehicleData == null || !vehicleData.Capacity.HasValidData || (mult = vehicleData.ScheduleMonthlyMultiplier) == null)
                        {
                            return(null);
                        }

                        IReadOnlyDictionary <Item, TransferData> transfers = vehicleData.Capacity.GetTransfers(vehicle.Schedule.GetTasks()[taskIndex]);
                        if (transfers != null)
                        {
                            routeTransfers.Add(transfers, mult, vehicleData.ScheduleAvereageDuration.Estimated);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }

                return(routeTransfers.Transfers);
            }
            return(null);
        }
Beispiel #6
0
        private bool ProcessSchedule(Dictionary <VehicleUnit, StorageState> storages, bool onlyRefit, Dictionary <RootTask, TaskTransfers> transfers = null, Dictionary <int, Dictionary <RootTask, TaskTransfers> > transfersPerUnit = null)
        {
            ImmutableList <RootTask> tasks = VehicleSchedule.GetTasks();
            int tasksCount = tasks.Count;

            for (int i = 0; i < tasksCount; i++)
            {
                RootTask task = tasks[i];
                ImmutableList <SubTask> subTasks = task.GetSubTasks();
                int             subTaskCount     = subTasks.Count;
                TaskTransfers   transfer         = null;
                TaskTransfers[] transferPerUnit  = null;

                for (int j = 0; j < subTaskCount; j++)
                {
                    SubTask subTask = subTasks[j];
                    if (subTask is RefitTask refitTask)
                    {
                        if (!Refit(refitTask, storages))
                        {
                            return(false);
                        }
                    }
                    else
                    if (!onlyRefit && subTask is TransferTask transferTask)
                    {
                        if (!Transfer(transferTask, storages, ref transfer, ref transferPerUnit, transfers != null, transfersPerUnit != null))
                        {
                            return(false);
                        }
                    }
                }

                if (transfer != null)
                {
                    transfers.Add(task, transfer);
                }
                if (transferPerUnit != null && transferPerUnit.Length > 0)
                {
                    for (int j = 0; j < transferPerUnit.Length; j++)
                    {
                        TaskTransfers unitTransfer = transferPerUnit[j];
                        if (unitTransfer != null)
                        {
                            if (!transfersPerUnit.TryGetValue(j, out Dictionary <RootTask, TaskTransfers> unitTransfers))
                            {
                                unitTransfers = new Dictionary <RootTask, TaskTransfers>();
                                transfersPerUnit.Add(j, unitTransfers);
                            }

                            if (unitTransfers.TryGetValue(task, out TaskTransfers addedUnitTransfers))
                            {
                                addedUnitTransfers.Add(unitTransfer);
                            }
                            else
                            {
                                unitTransfers.Add(task, unitTransfer);
                            }
                        }
                    }
                }
            }
            return(true);
        }
 public void Add(TaskTransfers transfers, float?multiplier = null, bool estimated = false)
 {
     Add(transfers._transfers, multiplier, estimated);
 }