private bool IsTechnologicallyAllowed(ProductionOrderWorkSchedule schedule, List <ProductionOrderWorkSchedule> plannedSchedules) { //check for every child if its planned var child = GetHierarchyChild(schedule); if (child != null) { return(plannedSchedules .Any(a => a.Id == child.Id) || child.ProducingState == ProducingState.Waiting || child.ProducingState == ProducingState.Producing || child.ProducingState == ProducingState.Finished); } /* * && !plannedSchedules.Any(a => a.ProductionOrderId == child.ProductionOrderId * && a.HierarchyNumber == child.HierarchyNumber) * && child.ProducingState == ProducingState.Created) * return false; * * if (child != null) return true;*/ var childs = GetBomChilds(schedule); if (childs == null) { return(true); } return(childs.All(childSchedule => plannedSchedules .Any(a => a.Id == childSchedule.Id) || childSchedule.ProducingState == ProducingState.Waiting || childSchedule.ProducingState == ProducingState.Producing || childSchedule.ProducingState == ProducingState.Finished)); }
private decimal GetRemainTimeFromParents(ProductionOrderWorkSchedule schedule) { int transitionTime = Calculations.GetTransitionTimeForWorkSchedule(schedule); if (schedule == null) { return(0); } var parents = _context.GetParents(schedule); if (parents == null || !parents.Any()) { return(schedule.Duration + transitionTime); } var maxTime = 0; foreach (var parent in parents) { var time = GetRemainTimeFromParents(parent) + schedule.Duration + transitionTime; if (time > maxTime) { maxTime = (int)time; } } return(maxTime); }
public List <ProductionOrderWorkSchedule> GetBomParents(ProductionOrderWorkSchedule plannedSchedule) { var provider = plannedSchedule.ProductionOrder.DemandProviderProductionOrders; if (provider == null || provider.ToList().Any(dppo => dppo.DemandRequester == null)) { return(new List <ProductionOrderWorkSchedule>()); } var requester = (from demandProviderProductionOrder in provider select demandProviderProductionOrder.DemandRequester into req select req).ToList(); var pows = new List <ProductionOrderWorkSchedule>(); foreach (var singleRequester in requester) { if (singleRequester.GetType() == typeof(DemandOrderPart) || singleRequester.GetType() == typeof(DemandStock)) { return(null); } var demand = Demands.OfType <DemandProductionOrderBom>().Include(a => a.ProductionOrderBom) .ThenInclude(b => b.ProductionOrderParent).ThenInclude(c => c.ProductionOrderWorkSchedule) .Single(a => a.Id == singleRequester.Id); var schedules = demand.ProductionOrderBom.ProductionOrderParent.ProductionOrderWorkSchedule; pows.Add(schedules.Single(a => a.HierarchyNumber == schedules.Min(b => b.HierarchyNumber))); } return(pows); /*return (from demandProviderProductionOrder in provider * select demandProviderProductionOrder.DemandRequester into requester * where requester.GetType() == typeof(DemandProductionOrderBom) * select ((DemandProductionOrderBom)requester).ProductionOrderBom.ProductionOrderParent.ProductionOrderWorkSchedule into schedules * select schedules.Single(a => a.HierarchyNumber == schedules.Min(b => b.HierarchyNumber))).ToList();*/ }
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(); }
private ProductionOrderWorkSchedule GetHierarchyChild(ProductionOrderWorkSchedule productionOrderWorkSchedule) { var productionOrderWorkSchedules = _context.ProductionOrderWorkSchedules.AsNoTracking().Where(a => a.ProductionOrderId == productionOrderWorkSchedule.ProductionOrderId); productionOrderWorkSchedules = productionOrderWorkSchedules.Where(mainSchedule => mainSchedule.HierarchyNumber < productionOrderWorkSchedule.HierarchyNumber); return /*If*/ (!productionOrderWorkSchedules.Any() ? /* then return */ null : /* else return */ productionOrderWorkSchedules.Single(a => a.HierarchyNumber == productionOrderWorkSchedules.Max(b => b.HierarchyNumber))); }
/// <summary> /// Returns or creates corrosponding GanttTask Item with Property type = "Project" and Returns it. /// -- Headline for one Project /// </summary> private GanttTask GetOrCreateTimeline(ProductionOrderWorkSchedule pow, int orderId) { IEnumerable <GanttTask> project; // get Timeline switch (_schedulingState) { case 3: // Machine Based project = _ganttContext.Tasks .Where(x => x.type == GanttType.project && x.id == "M" + (pow.MachineId ?? 0)); if (project.Any()) { return(project.First()); } else { var gc = _ganttContext.Tasks.Count(x => x.type == GanttType.project) + 1; var pt = CreateProjectTask("M" + pow.Machine.Id, pow.Machine.Name, "", 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.Orders.FirstOrDefault(x => x.Id == orderId).Name, "", 0, (GanttColors)gc); _ganttContext.Tasks.Add(pt); return(pt); } // break; } }
private bool DetectCrossing(ProductionOrderWorkSchedule schedule, ProductionOrderWorkSchedule scheduleMg) { return((scheduleMg.Start <= schedule.Start && scheduleMg.End > schedule.Start) || (scheduleMg.Start < schedule.End && scheduleMg.End >= schedule.End) || (scheduleMg.Start > schedule.Start && scheduleMg.End < schedule.End)); }
private List <ProductionOrderWorkSchedule> GetBomChilds(ProductionOrderWorkSchedule productionOrderWorkSchedule) { var boms = productionOrderWorkSchedule.ProductionOrder.ProductionOrderBoms; var bomChilds = (from bom in boms where bom.DemandProductionOrderBoms != null && bom.DemandProductionOrderBoms.Any() from provider in bom.DemandProductionOrderBoms.First().DemandProvider.OfType <DemandProviderProductionOrder>() select provider.ProductionOrder.ProductionOrderWorkSchedule into schedules select schedules.Single(a => a.HierarchyNumber == schedules.Max(b => b.HierarchyNumber)) ).ToList(); return(!bomChilds.Any() ? null : bomChilds); }
//sets Starttime to the latest endtime of the children private int SetForwardTimeFromChild(ProductionOrderWorkSchedule workSchedule) { var pobs = workSchedule.ProductionOrder.ProductionOrderBoms; var latestEnd = (from pob in pobs where pob.DemandProductionOrderBoms.Any() from provider in pob.DemandProductionOrderBoms.First().DemandProvider.OfType <DemandProviderProductionOrder>() select provider.ProductionOrder.ProductionOrderWorkSchedule.Max(a => a.EndForward) ).Concat(new[] { 0 }).Max(); workSchedule.StartForward = latestEnd; return(workSchedule.StartForward); }
private bool AllSimulationChildrenFinished(ProductionOrderWorkSchedule item, List <ISimulationItem> timeTableItems) { var hierarchyFinished = SimulationHierarchyChildrenFinished(item, timeTableItems); if (hierarchyFinished != null) { return((bool)hierarchyFinished); } var bomFinished = SimulationBomChildrenFinished(item, timeTableItems); if (bomFinished != null) { return((bool)bomFinished); } return(true); }
public static int GetTransitionTimeForWorkSchedule(ProductionOrderWorkSchedule schedule) { var transitionTime = 0; switch (schedule.MachineGroupId) { case 1: transitionTime = 90; break; case 2: transitionTime = 210; break; case 3: transitionTime = 100; break; default: transitionTime = 0; break; } return(transitionTime); }
private int GetChildEndTime(ProductionOrderWorkSchedule shortest) { if (shortest.HierarchyNumber != shortest.ProductionOrder.ProductionOrderWorkSchedule.Min(a => a.HierarchyNumber)) { var children = _context.ProductionOrderWorkSchedules.Where(a => a.ProductionOrderId == shortest.ProductionOrderId && a.HierarchyNumber < shortest.HierarchyNumber) .Max(b => b.End); return(children); } var childrenBoms = _context.ProductionOrderBoms.Where(a => a.ProductionOrderParentId == shortest.ProductionOrderId).ToList(); var latestEnd = (from bom in childrenBoms where bom.DemandProductionOrderBoms.Any() from provider in bom.DemandProductionOrderBoms.First().DemandProvider.OfType <DemandProviderProductionOrder>() select provider.ProductionOrder.ProductionOrderWorkSchedule.Max(a => a.End) ).Concat(new[] { 0 }).Max(); return(latestEnd); }
/*public ProductionOrder CreateBomForProductionOrder(decimal quantity, ProductionOrder mainProductionOrder) * { * var article = Articles.Include(a => a.ArticleBoms).ThenInclude(c => c.ArticleChild).Single(a => a.Id == mainProductionOrder.ArticleId); * foreach (var item in article.ArticleBoms) * { * var thisQuantity = quantity * item.Quantity; * * var prodOrder = new ProductionOrder * { * ArticleId = item.ArticleChildId, * Name = "Prod. Auftrag: " + article.Name, * Quantity = thisQuantity, * }; * ProductionOrders.Add(prodOrder); * * var prodOrderBom = new ProductionOrderBom * { * Quantity = thisQuantity, * ProductionOrderParentId = mainProductionOrder.Id, * * }; * mainProductionOrder.ProductionOrderBoms.Add(prodOrderBom); * * CreateDemandProductionOrderBom(item.ArticleChildId, thisQuantity); * } * SaveChanges(); * return mainProductionOrder; * }*/ public void CreateProductionOrderWorkSchedules(ProductionOrder productionOrder) { var abstractWorkSchedules = WorkSchedules.Where(a => a.ArticleId == productionOrder.ArticleId).ToList(); foreach (var abstractWorkSchedule in abstractWorkSchedules) { //add specific workSchedule var workSchedule = new ProductionOrderWorkSchedule(); abstractWorkSchedule.CopyPropertiesTo <IWorkSchedule>(workSchedule); workSchedule.ProductionOrderId = productionOrder.Id; workSchedule.MachineId = null; workSchedule.ProducingState = ProducingState.Created; workSchedule.Duration *= (int)productionOrder.Quantity; ProductionOrderWorkSchedules.Add(workSchedule); SaveChanges(); } }
/// <summary> /// Creates new TimelineItem with a label depending on the schedulingState /// </summary> public GanttTask CreateGanttTask(ProductionOrderWorkSchedule item, long start, long end, GanttColors gc, string parent) { var gantTask = new GanttTask() { id = item.Id.ToString(), type = GanttType.task, desc = item.Name, text = _schedulingState == 4 ? item.MachineGroup.Name : "P.O.: " + item.ProductionOrderId, start_date = start.GetDateFromMilliseconds().ToString("dd-MM-yyyy HH:mm"), end_date = end.GetDateFromMilliseconds().ToString("dd-MM-yyyy HH:mm"), IntFrom = start, IntTo = end, parent = parent, color = gc, }; return(gantTask); }
public List <ProductionOrderWorkSchedule> GetParents(ProductionOrderWorkSchedule schedule) { var parents = new List <ProductionOrderWorkSchedule>(); if (schedule == null) { return(parents); } var parent = GetHierarchyParent(schedule); if (parent != null) { parents.Add(parent); return(parents); } var bomParents = GetBomParents(schedule); return(bomParents ?? parents); }
public ProductionOrderWorkSchedule GetHierarchyParent(ProductionOrderWorkSchedule pows) { ProductionOrderWorkSchedule hierarchyParent = null; var hierarchyParentNumber = int.MaxValue; //find next higher element foreach (var mainSchedule in pows.ProductionOrder.ProductionOrderWorkSchedule) { //if (mainSchedule.ProductionOrderId != pows.ProductionOrderId) continue; if (mainSchedule.HierarchyNumber <= pows.HierarchyNumber || mainSchedule.HierarchyNumber >= hierarchyParentNumber) { continue; } hierarchyParent = mainSchedule; hierarchyParentNumber = mainSchedule.HierarchyNumber; } return(hierarchyParent); }
private bool?SimulationHierarchyChildrenFinished(ProductionOrderWorkSchedule item, List <ISimulationItem> timeTableItems) { var hierarchyChildren = _context.ProductionOrderWorkSchedules.Where(a => a.ProductionOrderId == item.ProductionOrderId && a.HierarchyNumber < item.HierarchyNumber); if (!hierarchyChildren.Any()) { return(null); } var pows = (from hC in hierarchyChildren where hC.HierarchyNumber == hierarchyChildren.Max(a => a.HierarchyNumber) select hC).Single(); if (pows == null) { return(null); } return(pows.ProducingState == ProducingState.Finished); }
/// <summary> /// Defines start and end for the ganttchart based on the Scheduling State /// </summary> private void DefineStartEnd(ref long start, ref long end, ProductionOrderWorkSchedule item) { switch (_schedulingState) { case 1: start = (_today + item.StartBackward * 60000); end = (_today + item.EndBackward * 60000); break; case 2: start = (_today + item.StartForward * 60000); end = (_today + item.EndForward * 60000); break; default: start = (_today + item.Start * 60000); end = (_today + item.End * 60000); break; } }
private bool ItemsInStock(ProductionOrderWorkSchedule item) { var boms = _context.ArticleBoms.Where(a => a.ArticleParentId == item.ProductionOrder.ArticleId); if (boms == null) { return(false); } foreach (var bom in boms) { if (_context.Stocks .Single(a => a.ArticleForeignKey == bom.ArticleChildId) .Current // less then < item.ProductionOrder.Quantity * bom.Quantity) { return(false); } } return(true); }
//find starttime from parent and set the endtime of the workschedule to it private int SetBackwardTimeFromParent(ProductionOrderWorkSchedule productionOrderWorkSchedule, State state) { var parents = _context.GetBomParents(productionOrderWorkSchedule); int end; if (parents == null || !parents.Any()) { end = state == State.ForwardScheduleExists ? productionOrderWorkSchedule.EndForward : productionOrderWorkSchedule.ProductionOrder.Duetime; } else if (state != State.ForwardScheduleExists) { end = parents.Min(a => a.StartBackward); productionOrderWorkSchedule.EndBackward = end; } else { end = parents.Min(a => a.StartForward); productionOrderWorkSchedule.EndForward = end; } return(end); }
private PowsSimulationItem PrepareItem(TimeTable <ISimulationItem> timeTable, ProductionOrderWorkSchedule item, int simulationId) { //variates the worktime by the amount set in the parameters of the simulation var newDuration = _workTimeGenerator.GetRandomWorkTime(item.Duration); if (newDuration != item.EndSimulation - item.StartSimulation) { item.EndSimulation = item.StartSimulation + newDuration; item.DurationSimulation = newDuration; } //add next in line for this machine if (timeTable.Timer != item.StartSimulation) { item.StartSimulation = timeTable.Timer; item.EndSimulation = item.StartSimulation + item.DurationSimulation; } //generate simItem for the simulator based on the Item var simItem = new PowsSimulationItem(_context) { End = item.EndSimulation, Start = item.StartSimulation, SimulationId = simulationId, ProductionOrderId = item.ProductionOrderId, ProductionOrderWorkScheduleId = item.Id, SimulationState = SimulationState.Waiting, Quantity = item.ProductionOrder.Quantity }; item.ProducingState = ProducingState.Waiting; _context.ProductionOrderWorkSchedules.Update(item); _context.SaveChanges(); return(simItem); }
/// <summary> /// Receives the prior items to a given ProductionOrderWorkSchedule /// </summary> /// <param name="productionOrderWorkSchedule"></param> /// <returns>List<ProductionOrderWorkSchedule></returns> public Task <List <ProductionOrderWorkSchedule> > GetFollowerProductionOrderWorkSchedules(ProductionOrderWorkSchedule productionOrderWorkSchedule) { var rs = Task.Run(() => { var priorItems = new List <ProductionOrderWorkSchedule>(); // If == min Hierarchy --> get Pevious Article -> Highest Hierarchy Workschedule Item var maxHierarchy = ProductionOrderWorkSchedules.Where(x => x.ProductionOrderId == productionOrderWorkSchedule.ProductionOrderId) .Max(x => x.HierarchyNumber); if (maxHierarchy == productionOrderWorkSchedule.HierarchyNumber) { // get Previous Article priorItems.AddRange(GetParents(productionOrderWorkSchedule)); } else { // get Previous Workschedule var previousPows = ProductionOrderWorkSchedules.Where( x => x.ProductionOrderId == productionOrderWorkSchedule.ProductionOrderId && x.HierarchyNumber > productionOrderWorkSchedule.HierarchyNumber) .OrderBy(x => x.HierarchyNumber).FirstOrDefault(); priorItems.Add(previousPows); } return(priorItems); }); return(rs); }
private int FindStartOnMachine(List <ProductionOrderWorkSchedule> plannedSchedules, int machineId, ProductionOrderWorkSchedule shortest) { for (var i = plannedSchedules.Count - 1; i >= 0; i--) { if (plannedSchedules[i].MachineId == machineId) { return(DetectCrossing(plannedSchedules[i], shortest) ? plannedSchedules[i].End : (plannedSchedules[i].End > shortest.Start ? plannedSchedules[i].End : shortest.Start)); } } return(0); }
private bool HasHierarchyChildren(ProductionOrderWorkSchedule pows) { var powslist = _context.ProductionOrderWorkSchedules.Where(a => a.ProductionOrderId == pows.ProductionOrderId); return(pows.HierarchyNumber != powslist.Min(a => a.HierarchyNumber)); }
private List <ProductionOrderWorkSchedulesByTimeStep> AddToMachineGroup(MachineGroupProductionOrderWorkSchedule machine, ProductionOrderWorkSchedule productionOrderWorkSchedule) { //Todo: replace provider.first() var start = productionOrderWorkSchedule.StartBackward; var end = productionOrderWorkSchedule.EndBackward; if (productionOrderWorkSchedule.ProductionOrder.DemandProviderProductionOrders.First().State == State.ForwardScheduleExists) { start = productionOrderWorkSchedule.StartForward; end = productionOrderWorkSchedule.EndForward; } for (var i = start; i < end; i++) { var found = false; foreach (var productionOrderWorkSchedulesByTimeStep in machine.ProductionOrderWorkSchedulesByTimeSteps) { if (productionOrderWorkSchedulesByTimeStep.Time == i) { productionOrderWorkSchedulesByTimeStep.ProductionOrderWorkSchedules.Add(productionOrderWorkSchedule); found = true; break; } } if (!found) { var timestep = new ProductionOrderWorkSchedulesByTimeStep { Time = i, ProductionOrderWorkSchedules = new List <ProductionOrderWorkSchedule> { productionOrderWorkSchedule } }; machine.ProductionOrderWorkSchedulesByTimeSteps.Add(timestep); } } return(machine.ProductionOrderWorkSchedulesByTimeSteps); }