Ejemplo n.º 1
0
        private void AddMachine(List <ProductionOrderWorkSchedule> plannedSchedules, ProductionOrderWorkSchedule shortest, int currentTime)
        {
            var machines = _context.Machines.Where(a => a.MachineGroupId == shortest.MachineGroupId).ToList();

            if (machines.Count == 1)
            {
                shortest.Start = GetChildEndTime(shortest);
                if (shortest.Start == 0)
                {
                    shortest.Start = currentTime;
                }
                shortest.End = shortest.Start + shortest.Duration;
                var earliestPlanned = FindStartOnMachine(plannedSchedules, machines.First().Id, shortest);
                var earliestPows    = FindStartOnMachine(plannedSchedules, machines.First().Id, shortest);
                var earliest        = (earliestPlanned > earliestPows) ? earliestPlanned : earliestPows;
                if (shortest.Start < earliest)
                {
                    shortest.Start = earliest;
                }
                shortest.MachineId = machines.First().Id;
                shortest.End       = shortest.Start + shortest.Duration;
            }

            else if (machines.Count > 1)
            {
                //Todo: possible boosts:
                //getchild, if same machinegroup take same machine default
                //else look for min free time if same start
                shortest.Start = GetChildEndTime(shortest);
                if (shortest.Start == 0)
                {
                    shortest.Start = currentTime;
                }
                shortest.End = shortest.Start + shortest.Duration;
                var earliestPlanned = FindStartOnMachine(plannedSchedules, machines.First().Id, shortest);
                var earliest        = earliestPlanned;
                var earliestMachine = machines.First();
                foreach (var machine in machines)
                {
                    var earliestThisMachine = FindStartOnMachine(plannedSchedules, machine.Id, shortest);
                    if (earliest <= earliestThisMachine || earliest <= shortest.Start)
                    {
                        continue;
                    }
                    earliest        = earliestThisMachine;
                    earliestMachine = machine;
                }


                if (shortest.Start < earliest)
                {
                    shortest.Start = earliest;
                }
                shortest.MachineId = earliestMachine.Id;
                shortest.End       = shortest.Start + shortest.Duration;
            }
            _context.Update(shortest);

            _context.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run requirements planning and backward/forward termination.
        /// </summary>
        /// <param name="demand"></param>
        /// <param name="task"></param>
        /// <param name="simulationId"></param>
        public void RunRequirementsAndTermination(IDemandToProvider demand, MrpTask task, int simulationId)
        {
            if (demand.State == State.Created)
            {
                ExecutePlanning(demand, task, simulationId);
                if (demand.State != State.Finished)
                {
                    demand.State = State.ProviderExist;
                }
                _context.Update(demand);
                _context.SaveChanges();
                _messageHub.SendToAllClients("Requirements planning completed.");
            }

            if (task == MrpTask.All || task == MrpTask.Backward)
            {
                _scheduling.BackwardScheduling(demand);
                demand.State = State.BackwardScheduleExists;
                _context.Update(demand);
                _context.SaveChanges();
                _messageHub.SendToAllClients("Backward schedule exists.");
            }

            if (task == MrpTask.All && CheckNeedForward(demand, simulationId) || task == MrpTask.Forward)
            {
                //schedules forward and then backward again with the finish of the forward algorithm
                _scheduling.ForwardScheduling(demand);
                demand.State = State.ForwardScheduleExists;
                _context.Update(demand);
                _context.SaveChanges();
                _scheduling.BackwardScheduling(demand);
                _messageHub.SendToAllClients("Forward schedule exists.");
            }
            _context.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("ArticleBomId,ArticleParentId,ArticleChildId,Quantity,Name")] M_ArticleBom articleBom)
        {
            if (id != articleBom.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(entity: articleBom);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArticleBomExists(id: articleBom.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(actionName: "Index"));
            }
            ViewData[index : "ArticleChildId"]  = new SelectList(items : _context.Articles, dataValueField : "Id", dataTextField : "Name", selectedValue : articleBom.ArticleChildId);
            ViewData[index : "ArticleParentId"] = new SelectList(items : _context.Articles, dataValueField : "Id", dataTextField : "Name", selectedValue : articleBom.ArticleParentId);
            return(View(model: articleBom));
        }
Ejemplo n.º 4
0
        public Task <bool> DoAtEnd <T>(List <TimeTable <T> .MachineStatus> listMachineStatus, int time) where T : ISimulationItem
        {
            var pows = _context.ProductionOrderWorkSchedules.Single(a => a.Id == ProductionOrderWorkScheduleId);

            pows.ProducingState = ProducingState.Finished;
            _context.ProductionOrderWorkSchedules.Update(pows);
            _context.SaveChanges();
            listMachineStatus.Single(b => b.MachineId == _context.ProductionOrderWorkSchedules.Single(a => a.Id == ProductionOrderWorkScheduleId).MachineId).Free = true;
            var powslist = _context.ProductionOrderWorkSchedules.Include(a => a.ProductionOrder).Where(a => a.ProductionOrderId == ProductionOrderId);

            if (powslist.Single(a => a.Id == ProductionOrderWorkScheduleId).HierarchyNumber !=
                powslist.Max(a => a.HierarchyNumber))
            {
                return(null);
            }
            var articleId = _context.ProductionOrders.Single(a => a.Id == ProductionOrderId).ArticleId;
            var stock     = _context.Stocks.Include(x => x.StockExchanges).Single(a => a.ArticleForeignKey == articleId);

            stock.Current += Quantity;
            stock.StockExchanges.Add(new StockExchange()
            {
                ExchangeType   = ExchangeType.Insert,
                Quantity       = Quantity,
                StockId        = stock.Id,
                RequiredOnTime = _context.SimulationConfigurations.Single(a => a.Id == SimulationId).Time,
                Time           = time
            });
            _context.Update(stock);
            _context.SaveChanges();
            return(null);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("ArticleBomId,ArticleParentId,ArticleChildId,Quantity,Name")] ArticleBom articleBom)
        {
            if (id != articleBom.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(articleBom);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArticleBomExists(articleBom.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ArticleChildId"]  = new SelectList(_context.Articles, "Id", "Name", articleBom.ArticleChildId);
            ViewData["ArticleParentId"] = new SelectList(_context.Articles, "Id", "Name", articleBom.ArticleParentId);
            return(View(articleBom));
        }
Ejemplo n.º 6
0
        private int CopyDemandsAndPows(IDemandToProvider dop, TimeTable <ISimulationItem> timetable, int simulationId, int simulationNumber)
        {
            var providerlist = dop.DemandProvider.OfType <DemandProviderProductionOrder>().ToList();
            var counter      = 0;

            while (providerlist.Any())
            {
                var provider = providerlist.First();
                foreach (var pob in provider.ProductionOrder.ProductionOrderBoms.ToList())
                {
                    foreach (var dpob in pob.DemandProductionOrderBoms.ToList())
                    {
                        CopyDemandsAndPows(dpob, timetable, simulationId, simulationNumber);
                    }
                    if (!pob.DemandProductionOrderBoms.Any())
                    {
                        _context.ProductionOrderBoms.Remove(pob);
                    }
                }
                provider = _context.Demands.OfType <DemandProviderProductionOrder>().Single(a => a.Id == provider.Id);
                if (provider.ProductionOrder.DemandProviderProductionOrders.Any(a => a.Id != provider.Id))
                {
                    _context.Demands.Remove(_context.Demands.Single(a => a.Id == provider.Id));
                    var po = _context.ProductionOrders.Single(a => a.Id == provider.ProductionOrderId);
                    po.DemandProviderProductionOrders.Remove(provider);
                    _context.Update(po);
                }
                else
                {
                    var items = new List <PowsSimulationItem>();
                    foreach (var schedule in provider.ProductionOrder.ProductionOrderWorkSchedule.ToList())
                    {
                        _context.ProductionOrderWorkSchedules.Remove(schedule);
                        var itemList = timetable.Items.OfType <PowsSimulationItem>()
                                       .Where(a => a.ProductionOrderWorkScheduleId == schedule.Id).ToList();
                        if (!itemList.Any())
                        {
                            continue;
                        }
                        items.Add(itemList.First());
                        timetable.Items.Remove(itemList.First());
                        counter++;
                    }
                    FillSimulationWorkSchedules(items, simulationId, simulationNumber, 0);

                    _context.ProductionOrders.Remove(provider.ProductionOrder);
                    _context.Demands.Remove(provider);
                    _context.Demands.Remove(provider.DemandRequester);
                }
                _context.SaveChanges();
                providerlist.RemoveAt(0);
            }
            return(counter);
        }