コード例 #1
0
        private (List <TechnicalObject>, List <RepairShop>) SetupInitialStates()
        {
            technicalObjects = _model.TechnicalObjects.Select(to => new TechnicalObject
            {
                Intensity    = to.Intensity,
                CurrentState = new WorkingTechnicalObjectState {
                    TimeToBreak = ExponentialValueGenerator.Get(to.Intensity)
                }
            }).ToList();

            repairShops = new List <RepairShop>();
            for (int i = 0; i < _model.RepairShops.Count(); i++)
            {
                if (_currentRepairStations[i] > 0)
                {
                    //добавляємо машини від усіх станцій
                    for (int j = 0; j < _currentRepairStations[i]; j++)
                    {
                        repairShops.Add(new RepairShop
                        {
                            RepairStationNumber = i,
                            CurrentState        = new OnStationRepairShopState()
                        });
                    }
                }
            }

            return(technicalObjects, repairShops);
        }
コード例 #2
0
        private (List <int>, List <int>) ProcessRepairEnd(int minimalRepairShopIndex, decimal timeStep)
        {
            var repairShop = repairShops[minimalRepairShopIndex];

            var technicalObjectIndex       = ((RepairingObjectRepairShopState)repairShop.CurrentState).ObjectToRepairIndex;
            var technicalObject            = technicalObjects[technicalObjectIndex];
            var brokenTechnicalObjectState = (BrokenTechnicalObjectState)technicalObject.CurrentState;

            // ReSharper disable once PossibleInvalidOperationException
            idleTimes.Add(time + timeStep - brokenTechnicalObjectState.IdleTimeStamp.Value);
            brokenTechnicalObjectState.IdleTimeStamp = null;

            technicalObject.CurrentState = new WorkingTechnicalObjectState
            {
                TimeToBreak = ExponentialValueGenerator.Get(technicalObject.Intensity)
            };

            var newBrokenTechnicalObjectIndex = GetBrokenTechnicalObjectIndexFromQueue();

            //якщо є зламані об'єкти, то отримуємо найперший із них
            if (newBrokenTechnicalObjectIndex >= 0)
            {
                var newBrokenTechnicalObject = technicalObjects[newBrokenTechnicalObjectIndex];
                // ReSharper disable once PossibleInvalidOperationException
                confirmationDelayTimes.Add(time + timeStep - ((BrokenTechnicalObjectState)newBrokenTechnicalObject.CurrentState).ConfirmationDelayTimeStamp.Value);
                ((BrokenTechnicalObjectState)newBrokenTechnicalObject.CurrentState).IdleTimeStamp = time + timeStep;

                repairShop.CurrentState = new GoToObjectRepairShopState
                {
                    ObjectToArriveIndex = newBrokenTechnicalObjectIndex,
                    TimeLeft            = _distanceMatrix.Matrix[technicalObjectIndex, newBrokenTechnicalObjectIndex] / _model.MachineSpeed
                };
            }
            else //їдемо на базу
            {
                repairShop.CurrentState = new BackToStationRepairShopState
                {
                    LastRepairedObjectIndex = technicalObjectIndex,
                    TimeLeft = _distanceMatrix.Matrix[_distanceMatrix.TechnicalObjectsCount + repairShop.RepairStationNumber, technicalObjectIndex] / _model.MachineSpeed
                };
            }

            return(new List <int> {
                technicalObjectIndex
            }, new List <int> {
                minimalRepairShopIndex
            });
        }