Exemple #1
0
        private void SaveCompletedContext(TimeTable <ISimulationItem> timetable, int simulationId, int simulationNumber)
        {
            var finishedOrders = _context.Orders.Where(a => a.State == State.Finished).Include(a => a.OrderParts).ThenInclude(b => b.DemandOrderParts);
            var counterPows    = _context.ProductionOrderWorkSchedules.Count();
            var counter        = (from order in finishedOrders.ToList()
                                  from orderPart in order.OrderParts.ToList()
                                  from dop in orderPart.DemandOrderParts.ToList()
                                  select CopyDemandsAndPows(dop, timetable, simulationId, simulationNumber)).Sum();

            _messageHub.SendToAllClients(counterPows + " Pows -> now " + _context.ProductionOrderWorkSchedules.Count());
            _messageHub.SendToAllClients(counter + " simPows deleted, now there are " + timetable.Items.Count + " left");
        }
Exemple #2
0
        private async Task Recalculate(TimeTable <ISimulationItem> timetable, int simulationId, int simNumber, List <ProductionOrderWorkSchedule> waitingItems)
        {
            var simConfig = _context.SimulationConfigurations.Single(a => a.Id == simulationId);

            /*
             * var filestream = System.IO.File.Create("D://stocks.csv");
             * var sw = new System.IO.StreamWriter(filestream);
             * foreach (var item in _context.Stocks)
             * {
             *  sw.WriteLine(item.Name + ";" + item.Current);
             * }
             * sw.Dispose();
             * filestream = System.IO.File.Create("D://waiting POs.csv");
             * sw = new System.IO.StreamWriter(filestream);
             * foreach (var item in waitingItems)
             * {
             *  sw.WriteLine(item.Name);
             * }
             * sw.Dispose();
             */
            //SaveCompletedContext(timetable,simulationId,simNumber);
            FillSimulationWorkSchedules(timetable.Items.OfType <PowsSimulationItem>().Where(a => a.SimulationState == SimulationState.Finished).ToList(), simulationId, simNumber, 0);
            _processMrp.UpdateDemandsAndOrders(simulationId);
            var time           = simConfig.Time;
            var maxAllowedTime = simConfig.Time + simConfig.MaxCalculationTime;
            var orderParts     = _context.OrderParts.Include(a => a.Order).Where(a => a.IsPlanned == false &&
                                                                                 a.Order.CreationTime <= time &&
                                                                                 a.Order.DueTime < maxAllowedTime).Include(a => a.Article).ToList();

            _messageHub.SendToAllClients("before orderParts");
            //await _processMrp.CreateAndProcessOrderDemand(MrpTask.All, _context, simulationId,_evaluationContext);
            foreach (var orderPart in orderParts.ToList())
            {
                _messageHub.SendToAllClients("Requirements: orderPart: " + orderPart.Id + ", DueTime: " + orderPart.Order.DueTime);
                var demand = _processMrp.GetDemand(orderPart);
                //run the requirements planning and backward/forward termination algorithm
                if (demand.State != State.Created)
                {
                    continue;
                }
                _processMrp.ExecutePlanning(demand, MrpTask.All, simulationId);
                orderPart.IsPlanned = true;
            }
            //_messageHub.SendToAllClients("before Rebuild");
            //rebuildNets.Rebuild(simulationId, _evaluationContext);
            _messageHub.SendToAllClients("before GT");
            capacityScheduling.GifflerThompsonScheduling(simulationId);
            _messageHub.SendToAllClients("finished GT");
            //await _processMrp.CreateAndProcessOrderDemand(MrpTask.All,_context,simulationId,_evaluationContext);
        }
Exemple #3
0
        public TimeTable <ISimulationItem> ProcessTimeline(TimeTable <ISimulationItem> timeTable)
        {
            var recalculate = timeTable.RecalculateTimer * (timeTable.RecalculateCounter + 1);

            if (!timeTable.Items.Any())
            {
                timeTable.Timer = recalculate;
                return(timeTable);
            }
            var start      = recalculate + 1;
            var startItems = timeTable.Items.Where(a => a.SimulationState == SimulationState.Waiting).ToList();

            if (startItems.Any())
            {
                start = startItems.Min(a => a.Start);
            }
            var end      = recalculate + 1;
            var endItems = timeTable.Items.Where(a => a.SimulationState == SimulationState.InProgress).ToList();

            if (endItems.Any())
            {
                end = endItems.Min(a => a.End);
            }
            // Timewarp - set Start Time
            if (recalculate < start && recalculate < end)
            {
                timeTable.Timer = recalculate;
                return(timeTable);
            }
            timeTable.Timer = start < end ? start : end;

            foreach (var item in (from tT in timeTable.Items
                                  where (tT.Start == timeTable.Timer && tT.SimulationState == SimulationState.Waiting) ||
                                  (tT.End == timeTable.Timer && tT.SimulationState == SimulationState.InProgress)
                                  select tT).ToList())
            {
                if (item.SimulationState == SimulationState.Waiting)
                {
                    AddToInProgress(item);
                }
                else
                {
                    HandleFinishedItems(item);
                }
            }

            // if Progress is empty Stop.
            return(timeTable);
        }
Exemple #4
0
        private void CheckForOrderRequests(TimeTable <ISimulationItem> timeTable)
        {
            var osi = timeTable.Items.Where(a => a.GetType() == typeof(OrderSimulationItem) && ((OrderSimulationItem)a).AddOrder).ToList();

            if (!osi.Any() || !osi.Any(b => ((OrderSimulationItem)b).AddOrder))
            {
                return;
            }
            foreach (var singleOsi in osi)
            {
                var order = (OrderSimulationItem)singleOsi;
                _context.Orders.Add(
                    _context.CreateNewOrder(order.ArticleIds[0], order.Amounts[0], 1, order.DueTime));
            }
        }
Exemple #5
0
        private void FinishSimulation(TimeTable <ISimulationItem> timeTable, int simulationId, int simNumber, SimulationConfiguration simConfig)
        {
            //copy workschedules to the simulationworkschedules which get written back to the local-db
            //FillSimulationWorkSchedules(timeTable.Items.OfType<PowsSimulationItem>().ToList(), simulationId, simNumber, 0);
            _messageHub.SendToAllClients("last Item produced at: " + _context.SimulationWorkschedules.Max(a => a.End));
            //calculate kpis
            CalculateKpis.MachineSattleTime(_context, simulationId, SimulationType.Central, simNumber);
            CalculateKpis.CalculateAllKpis(_context, simulationId, SimulationType.Central, simNumber, true, simConfig.Time);
            RemoveSimulationWorkschedules();
            //copy the relevant tables from the in-memory db to the local-db
            CopyResults.Copy(_context, _evaluationContext, simulationId, simNumber, SimulationType.Central);

            _messageHub.EndScheduler();
            _context.Database.CloseConnection();
            _evaluationContext.Database.CloseConnection();
        }
Exemple #6
0
        private TimeTable <ISimulationItem> UpdateGoodsDelivery(TimeTable <ISimulationItem> timeTable, int simulationId)
        {
            var purchaseParts = _context.PurchaseParts.Include(a => a.Purchase).Where(a =>
                                                                                      a.State != State.Finished &&
                                                                                      timeTable.Items.OfType <PurchaseSimulationItem>().All(b => b.PurchasePartId != a.Id));

            if (purchaseParts == null)
            {
                return(timeTable);
            }
            foreach (var purchasePart in purchaseParts)
            {
                // insert into timetable with rnd-duetime
                timeTable.Items.Add(CreateNewPurchaseSimulationItem(purchasePart, simulationId));
            }
            return(timeTable);
        }
Exemple #7
0
        private void UpdateWaitingItems(TimeTable <ISimulationItem> timeTable, List <ProductionOrderWorkSchedule> waitingItems)
        {
            var completeList =
                _context.ProductionOrderWorkSchedules.Where(a => a.ProducingState == ProducingState.Created);//CreateInitialTable();

            foreach (var item in completeList)
            {
                if (timeTable.Items.OfType <PowsSimulationItem>().Any(a => a.ProductionOrderWorkScheduleId == item.Id))
                {
                    continue;
                }
                if (waitingItems.Any(a => a.Id == item.Id))
                {
                    waitingItems.Remove(waitingItems.Find(a => a.Id == item.Id));
                }
                waitingItems.Add(item);
            }
        }
Exemple #8
0
        private async Task <TimeTable <ISimulationItem> > InitializeSimulation(int simulationId, int simNumber, SimulationConfiguration simConfig)
        {
            _messageHub.SendToAllClients("Start Simulation...", MessageType.info);
            _context = InMemoryContext.CreateInMemoryContext();
            InMemoryContext.LoadData(_evaluationContext, _context);
            capacityScheduling = new CapacityScheduling(_context);
            rebuildNets        = new RebuildNets(_context);
            await PrepareSimulationContext();

            await OrderGenerator.GenerateOrders(_context, simConfig, simNumber);

            _workTimeGenerator = new WorkTimeGenerator(simConfig.Seed, simConfig.WorkTimeDeviation, simNumber);
            var timeTable = new TimeTable <ISimulationItem>(simConfig.RecalculationTime);

            UpdateStockExchangesWithInitialValues(simulationId, simNumber);

            //call the initial central planning
            await Recalculate(timeTable, simulationId, simNumber, new List <ProductionOrderWorkSchedule>());

            CreateMachinesReady(timeTable);
            timeTable = UpdateGoodsDelivery(timeTable, simulationId);
            return(timeTable);
        }
Exemple #9
0
        private List <int> GetFreeMachines(TimeTable <ISimulationItem> timeTable)
        {
            var freeMachines = timeTable.ListMachineStatus.Where(a => a.Free).Select(a => a.MachineId).ToList();

            return(freeMachines);
        }