public int GetEarliestStart(ResultContext kpiContext, SimulationWorkschedule simulationWorkschedule, SimulationType simulationType, int simulationId, List <SimulationWorkschedule> schedules = null)
        {
            if (simulationType == SimulationType.Central)
            {
                var orderId = simulationWorkschedule.OrderId.Replace(oldValue: "[", newValue: "").Replace(oldValue: "]", newValue: "");
                var start   = kpiContext.SimulationOperations
                              .Where(predicate: x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType)
                              .Where(predicate: a =>
                                     a.OrderId.Equals("[" + orderId.ToString() + ",") ||
                                     a.OrderId.Equals("," + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("[" + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("," + orderId.ToString() + ",")).Min(selector: b => b.Start);
                return(start);
            }

            var children = new List <SimulationWorkschedule>();

            children = schedules.Where(predicate: x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType)
                       .Where(predicate: a => a.ParentId.Equals(value: simulationWorkschedule.ProductionOrderId.ToString())).ToList();

            if (!children.Any())
            {
                return(simulationWorkschedule.Start);
            }
            var startTimes = children.Select(selector: child => GetEarliestStart(kpiContext: kpiContext, simulationWorkschedule: child, simulationType: simulationType, simulationId: simulationId, schedules: schedules)).ToList();

            return(startTimes.Min());
        }
Example #2
0
        public int GetEarliestStart(ProductionDomainContext kpiContext, SimulationWorkschedule simulationWorkschedule, SimulationType simulationType, int simulationId, List <SimulationWorkschedule> schedules = null)
        {
            if (simulationType == SimulationType.Central)
            {
                var orderId = simulationWorkschedule.OrderId.Replace("[", "").Replace("]", "");
                var start   = kpiContext.SimulationWorkschedules
                              .Where(x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType)
                              .Where(a =>
                                     a.OrderId.Equals("[" + orderId.ToString() + ",") ||
                                     a.OrderId.Equals("," + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("[" + orderId.ToString() + "]") ||
                                     a.OrderId.Equals("," + orderId.ToString() + ",")).Min(b => b.Start);
                return(start);
            }

            var children = new List <SimulationWorkschedule>();

            children = schedules.Where(x => x.SimulationConfigurationId == simulationId && x.SimulationType == simulationType).Where(a => a.ParentId.Equals(simulationWorkschedule.ProductionOrderId.ToString())).ToList();

            if (!children.Any())
            {
                return(simulationWorkschedule.Start);
            }
            var startTimes = children.Select(child => GetEarliestStart(kpiContext, child, simulationType, simulationId, schedules)).ToList();

            return(startTimes.Min());
        }
        /// <summary>
        /// Returns or creates corrosponding GanttTask Item with Property  type = "Project" and Returns it.
        /// -- Headline for one Project
        /// </summary>
        private GanttTask GetOrCreateTimeline(SimulationWorkschedule pow, int orderId = 0)
        {
            IEnumerable <GanttTask> project;

            // get Timeline
            switch (_schedulingState)
            {
            case 3:     // Machine Based
                project = _ganttContext.Tasks
                          .Where(predicate: x => x.type == GanttType.project && x.id == "M_" + pow.Machine);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(predicate: x => x.type == GanttType.project) + 1;
                    //var mg = _context.MachineGroups.First(x => x.Id.ToString() == pow.Machine.ToString()).Name;
                    var pt = CreateProjectTask(id: "M_" + pow.Machine, name: pow.Machine, desc: "", @group: 0, gc: (GanttColors)gc);
                    _ganttContext.Tasks.Add(item: pt);
                    return(pt);
                }

            //break;
            case 4:     // Production Order Based
                project = _ganttContext.Tasks
                          .Where(predicate: x => x.type == GanttType.project && x.id == "P" + pow.ProductionOrderId);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(predicate: x => x.type == GanttType.project) + 1;
                    var pt = CreateProjectTask(id: "P" + pow.ProductionOrderId, name: "PO Nr.: " + pow.ProductionOrderId, desc: "", @group: 0, gc: (GanttColors)gc);
                    _ganttContext.Tasks.Add(item: pt);
                    return(pt);
                }

            //break;
            default:     // back and forward
                project = _ganttContext.Tasks
                          .Where(predicate: x => x.type == GanttType.project && x.id == "O" + orderId);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(predicate: x => x.type == GanttType.project) + 1;
                    var pt = CreateProjectTask(id: "O" + orderId, name: _context.CustomerOrderParts.
                                               Include(navigationPropertyPath: x => x.CustomerOrder)
                                               .FirstOrDefault(predicate: x => x.Id == orderId)
                                               .CustomerOrder.Name, desc: "", @group: 0, gc: (GanttColors)gc);
                    _ganttContext.Tasks.Add(item: pt);
                    return(pt);
                }
                // break;
            }
        }
        private void CreateSimulationWorkSchedule(FCreateSimulationWork cws)
        {
            var ws  = cws.Operation;
            var sws = new SimulationWorkschedule
            {
                CreatedForOrderId         = string.Empty,
                WorkScheduleId            = ws.Key.ToString(),
                Article                   = ws.Operation.Article.Name,
                WorkScheduleName          = ws.Operation.Name,
                DueTime                   = (int)ws.DueTime,
                SimulationConfigurationId = Collector.simulationId.Value,
                SimulationNumber          = Collector.simulationNumber.Value,
                SimulationType            = Collector.simulationKind.Value,
                OrderId                   = "[" + cws.CustomerOrderId + "]",
                HierarchyNumber           = ws.Operation.HierarchyNumber,
                // TODO this is now a fArticleKey (Guid)
                ProductionOrderId = "[" + cws.fArticleKey + "]",
                Parent            = cws.IsHeadDemand.ToString(),
                ParentId          = "[]",
                Time        = (int)(Collector.Time),
                ArticleType = cws.ArticleType
            };

            var edit = _updatedSimulationWork.FirstOrDefault(predicate: x => x.WorkScheduleId.Equals(value: ws.Key.ToString()));

            if (edit != null)
            {
                sws.Start   = (int)edit.Start;
                sws.End     = (int)(edit.Start + edit.Duration);
                sws.Machine = edit.Machine;
                _updatedSimulationWork.Remove(item: edit);
            }
            simulationWorkschedules.Add(item: sws);
        }
Example #5
0
        /// <summary>
        /// Returns or creates corrosponding GanttTask Item with Property  type = "Project" and Returns it.
        /// -- Headline for one Project
        /// </summary>
        private GanttTask GetOrCreateTimeline(SimulationWorkschedule pow, int orderId = 0)
        {
            IEnumerable <GanttTask> project;

            // get Timeline
            switch (_schedulingState)
            {
            case 3:     // Machine Based
                project = _ganttContext.Tasks
                          .Where(x => x.type == GanttType.project && x.id == "M_" + pow.Machine);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(x => x.type == GanttType.project) + 1;
                    //var mg = _context.MachineGroups.First(x => x.Id.ToString() == pow.Machine.ToString()).Name;
                    var pt = CreateProjectTask("M_" + pow.Machine, pow.Machine, "", 0, (GanttColors)gc);
                    _ganttContext.Tasks.Add(pt);
                    return(pt);
                }

            //break;
            case 4:     // Production Order Based
                project = _ganttContext.Tasks
                          .Where(x => x.type == GanttType.project && x.id == "P" + pow.ProductionOrderId);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(x => x.type == GanttType.project) + 1;
                    var pt = CreateProjectTask("P" + pow.ProductionOrderId, "PO Nr.: " + pow.ProductionOrderId, "", 0, (GanttColors)gc);
                    _ganttContext.Tasks.Add(pt);
                    return(pt);
                }

            //break;
            default:     // back and forward
                project = _ganttContext.Tasks
                          .Where(x => x.type == GanttType.project && x.id == "O" + orderId);
                if (project.Any())
                {
                    return(project.First());
                }
                else
                {
                    var gc = _ganttContext.Tasks.Count(x => x.type == GanttType.project) + 1;
                    var pt = CreateProjectTask("O" + orderId, _context.OrderParts.
                                               Include(x => x.Order)
                                               .FirstOrDefault(x => x.Id == orderId)
                                               .Order.Name, "", 0, (GanttColors)gc);
                    _ganttContext.Tasks.Add(pt);
                    return(pt);
                }
                // break;
            }
        }
        /// <summary>
        /// Creates new TimelineItem with a label depending on the schedulingState
        /// </summary>
        public GanttTask CreateGanttTask(SimulationWorkschedule item, long start, long end, GanttColors gc, string parent)
        {
            var gantTask = new GanttTask()
            {
                id         = item.Id.ToString(),
                type       = GanttType.task,
                desc       = item.WorkScheduleName,
                text       = _schedulingState == 4 ? item.Machine : "P.O.: " + item.ProductionOrderId,
                start_date = start.GetDateFromMilliseconds().ToString(format: "dd-MM-yyyy HH:mm"),
                end_date   = end.GetDateFromMilliseconds().ToString(format: "dd-MM-yyyy HH:mm"),
                IntFrom    = start,
                IntTo      = end,
                parent     = parent,
                color      = gc,
            };

            return(gantTask);
        }
Example #7
0
        public static void CreateSimulationWorkSchedule(WorkItem ws, string orderId, bool isHeadDemand)
        {
            var sws = new SimulationWorkschedule
            {
                WorkScheduleId            = ws.Id.ToString(),
                Article                   = ws.WorkSchedule.Article.Name,
                WorkScheduleName          = ws.WorkSchedule.Name,
                DueTime                   = ws.DueTime,
                EstimatedEnd              = ws.EstimatedEnd,
                SimulationConfigurationId = -1,
                OrderId                   = "[" + orderId + "]",
                HierarchyNumber           = ws.WorkSchedule.HierarchyNumber,
                ProductionOrderId         = "[" + ws.ProductionAgent.AgentId.ToString() + "]",
                Parent   = isHeadDemand.ToString(),
                ParentId = "[]"
            };

            AgentSimulation.SimulationWorkschedules.Add(sws);
        }
Example #8
0
        public Task <List <SimulationWorkschedule> > GetFollowerProductionOrderWorkSchedules(SimulationWorkschedule simulationWorkSchedule, SimulationType type, List <SimulationWorkschedule> relevantItems)
        {
            var rs = Task.Run(() =>
            {
                var priorItems = new List <SimulationWorkschedule>();
                // If == min Hierarchy --> get Pevious Article -> Highest Hierarchy Workschedule Item
                var maxHierarchy = relevantItems.Where(x => x.ProductionOrderId == simulationWorkSchedule.ProductionOrderId)
                                   .Max(x => x.HierarchyNumber);

                if (maxHierarchy == simulationWorkSchedule.HierarchyNumber)
                {
                    // get Previous Article
                    priorItems.AddRange(relevantItems
                                        .Where(x => x.ProductionOrderId == simulationWorkSchedule.ParentId &&
                                               x.HierarchyNumber == relevantItems
                                               .Where(w => w.ProductionOrderId == simulationWorkSchedule.ParentId)
                                               .Min(m => m.HierarchyNumber)));
                }
                else
                {
                    // get Previous Workschedule
                    var previousPows =
                        relevantItems.Where(
                            x => x.ProductionOrderId == simulationWorkSchedule.ProductionOrderId &&
                            x.HierarchyNumber > simulationWorkSchedule.HierarchyNumber)
                        .OrderBy(x => x.HierarchyNumber).FirstOrDefault();
                    priorItems.Add(previousPows);
                }
                return(priorItems);
            });

            return(rs);
        }
 /// <summary>
 /// Defines start and end for the ganttchart based on the Scheduling State
 /// </summary>
 private void DefineStartEnd(ref long start, ref long end, SimulationWorkschedule item)
 {
     start = (_today + item.Start * 60000);
     end   = (_today + item.End * 60000);
 }
Example #10
0
        private void FillSimulationWorkSchedules(List <PowsSimulationItem> items, int simulationId, int simulationNumber, MrpTask task)
        {
            foreach (var item in items)
            {
                var po   = _context.ProductionOrders.Include(b => b.Article).Single(a => a.Id == item.ProductionOrderId);
                var pows = _context.ProductionOrderWorkSchedules.Single(a => a.Id == item.ProductionOrderWorkScheduleId);

                if (task == MrpTask.None)
                {
                    var schedule = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.Id),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndSimulation,
                        EstimatedEnd              = pows.End,
                        EstimatedStart            = pows.Start,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Machine                   = pows.MachineId == null ? null : _context.Machines.Single(a => a.Id == pows.MachineId).Name,
                        Start                     = pows.StartSimulation,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.Central,
                        SimulationNumber          = simulationNumber,
                    };
                    _context.Add(schedule);
                    //_evaluationContext.Add(schedule.CopyDbPropertiesWithoutId());
                }

                if (task == MrpTask.Backward || task == MrpTask.All)
                {
                    var backward = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.ProductionOrderId),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndBackward,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Start                     = pows.StartBackward,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.BackwardPlanning,
                        SimulationNumber          = simulationNumber,
                        Machine                   = pows.MachineGroupId.ToString()
                    };
                    _context.Add(backward);
                    _evaluationContext.Add(backward.CopyDbPropertiesWithoutId());
                }
                if (task == MrpTask.Forward || task == MrpTask.All)
                {
                    var forward = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.ProductionOrderId),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndForward,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Start                     = pows.StartForward,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.ForwardPlanning,
                        SimulationNumber          = simulationNumber,
                        Machine                   = pows.MachineGroupId.ToString()
                    };
                    _context.Add(forward);
                    _evaluationContext.Add(forward.CopyDbPropertiesWithoutId());
                }
            }
            _context.SaveChanges();
            _evaluationContext.SaveChanges();
        }