示例#1
0
        /// <summary>
        /// Set Start- and Endtime for ProductionOrderWorkSchedules for the given OrderPart excluding capacities in a backward schedule
        /// </summary>
        /// <param name="demand"></param>
        public void BackwardScheduling(IDemandToProvider demand)
        {
            var productionOrderWorkSchedules = new List <ProductionOrderWorkSchedule>();

            _context.GetWorkSchedulesFromDemand(demand, ref productionOrderWorkSchedules);
            productionOrderWorkSchedules = productionOrderWorkSchedules.OrderBy(a => a.ProductionOrderId).ThenByDescending(b => b.HierarchyNumber).ToList();
            foreach (var workSchedule in productionOrderWorkSchedules)
            {
                // set transition time relating to machine group.
                var transitionTime = Calculations.GetTransitionTimeForWorkSchedule(workSchedule);

                //Set hierarchy to something high that every workSchedule found will overwrite this value
                var hierarchyParent = _context.GetHierarchyParent(workSchedule);
                //if no hierarchy has been found
                if (hierarchyParent == null)
                {
                    if (demand.State == State.ForwardScheduleExists)
                    {
                        workSchedule.EndForward = SetBackwardTimeFromParent(workSchedule, demand.State);
                    }
                    else
                    {
                        workSchedule.EndBackward = SetBackwardTimeFromParent(workSchedule, demand.State);
                    }
                }
                else
                {
                    if (demand.State == State.ForwardScheduleExists)
                    {
                        workSchedule.EndForward = _context.ProductionOrderWorkSchedules.Single(a =>
                                                                                               (a.HierarchyNumber == hierarchyParent.HierarchyNumber) &&
                                                                                               (a.ProductionOrderId == workSchedule.ProductionOrderId)).StartForward;
                    }
                    else
                    {
                        workSchedule.EndBackward = _context.ProductionOrderWorkSchedules.Single(a =>
                                                                                                (a.HierarchyNumber == hierarchyParent.HierarchyNumber) &&
                                                                                                (a.ProductionOrderId == workSchedule.ProductionOrderId)).StartBackward;
                    }
                }
                if (demand.State == State.ForwardScheduleExists)
                {
                    workSchedule.StartForward = workSchedule.EndForward - workSchedule.Duration - transitionTime;
                    workSchedule.EndForward   = workSchedule.StartForward + workSchedule.Duration;
                }
                else
                {
                    workSchedule.StartBackward = workSchedule.EndBackward - workSchedule.Duration - transitionTime;
                    workSchedule.EndBackward   = workSchedule.StartBackward + workSchedule.Duration;
                }
            }
            _context.ProductionOrderWorkSchedules.UpdateRange(productionOrderWorkSchedules);

            _context.SaveChanges();
        }
示例#2
0
        private List <ProductionOrderWorkSchedule> CreateInitialTable()
        {
            //Todo: Revert changes after testing
            //var demands = _context.Demands.Include(a => a.DemandProvider).Where(a => a.State == State.ExistsInCapacityPlan).ToList();
            var demands = new List <IDemandToProvider>();

            demands.AddRange(_context.Demands.OfType <DemandOrderPart>().Include(a => a.DemandProvider).Where(a => a.State != State.Finished && a.DemandProvider.Any(b => b.State != State.Finished)).ToList());
            demands.AddRange(_context.Demands.OfType <DemandProductionOrderBom>().Include(a => a.DemandProvider).Where(a => a.State != State.Finished && a.DemandProvider.Any(b => b.State != State.Finished)).ToList());
            demands.AddRange(_context.Demands.OfType <DemandStock>().Include(a => a.DemandProvider).Where(a => a.State != State.Finished && a.DemandProvider.Any(b => b.State != State.Finished)).ToList());

            var pows = new List <ProductionOrderWorkSchedule>();

            foreach (var demand in demands)
            {
                _context.GetWorkSchedulesFromDemand(demand, ref pows);
            }
            pows = pows.Distinct().ToList();

            /*var test = pows.Where(a => a.ProductionOrder.DemandProviderProductionOrders.Any(b => b.State == State.Finished)).ToList();
             * while (test.Any())
             * {
             *  var item = test.First();
             *  pows.Remove(item);
             *  if (item != null)
             *      test.Remove(item);
             * }*/
            foreach (var singlePows in pows)
            {
                singlePows.StartSimulation    = singlePows.Start;
                singlePows.EndSimulation      = singlePows.End;
                singlePows.DurationSimulation = singlePows.Duration;
            }
            _context.SaveChanges();
            return(pows);
        }
        /// <summary>
        /// Get All Relevant Production Work Schedules an dpass them for each Order To
        /// </summary>
        private async Task GetSchedulesForOrderListAsync(IEnumerable <int> ordersParts)
        {
            foreach (var orderPart in ordersParts)
            {
                //var pows = await _context.GetProductionOrderBomRecursive(_context.ProductionOrders.FirstOrDefault(x => x.ArticleId == 1), 1);
                // get the corresponding Order Parts to Order
                var demands = _context.Demands.OfType <DemandOrderPart>()
                              .Include(x => x.OrderPart)
                              .Include(x => x.DemandProvider)
                              .Where(o => o.OrderPart.OrderId == orderPart)
                              .ToList();

                var pows = new List <ProductionOrderWorkSchedule>();
                foreach (var demand in demands)
                {
                    var data = _context.GetWorkSchedulesFromDemand(demand, ref pows);
                }


                foreach (var pow in pows)
                {
                    // check if head element is Created,
                    GanttTask timeline = GetOrCreateTimeline(pow, orderPart);
                    long      start = 0, end = 0;
                    DefineStartEnd(ref start, ref end, pow);
                    // Add Item To Timeline
                    _ganttContext.Tasks.Add(
                        CreateGanttTask(
                            pow,
                            start,
                            end,
                            timeline.color,
                            timeline.id
                            )
                        );
                    var c = await _context.GetFollowerProductionOrderWorkSchedules(pow);

                    if (!c.Any())
                    {
                        continue;
                    }
                    // create Links for this pow
                    foreach (var link in c)
                    {
                        _ganttContext.Links.Add(
                            new GanttLink
                        {
                            id     = Guid.NewGuid().ToString(),
                            type   = LinkType.finish_to_start,
                            source = pow.Id.ToString(),
                            target = link.Id.ToString()
                        }
                            );
                    } // end foreach link
                }     // emd pows
            }         // end foreach Order
        }
示例#4
0
        private bool CheckNeedForward(IDemandToProvider demand, int simulationId)
        {
            var pows = new List <ProductionOrderWorkSchedule>();

            return(demand.GetType() == typeof(DemandStock) || _context.GetWorkSchedulesFromDemand(demand, ref pows).Any(a => a.StartBackward < _context.SimulationConfigurations.Single(b => b.Id == simulationId).Time));
        }