Example #1
0
        /// <summary>
        /// An algorithm for capacity-leveling. Writes Start/End in ProductionOrderWorkSchedule.
        /// </summary>
        public void GifflerThompsonScheduling(int simulationId)
        {
            var notplanned = new List <ProductionOrderWorkSchedule>();
            // Datenbank.Collection.Methode(collection => collection.field == parameter).Field
            //.Single Return an Object instead of an Collection of that requested Object.
            var currentTime = _context.SimulationConfigurations.Single(a => a.Id == simulationId).Time;

            //var productionOrderWorkSchedules = GetProductionSchedules(simulationId);
            var productionOrderWorkSchedules = _context.ProductionOrderWorkSchedules.Where(a => a.ProducingState == ProducingState.Created).ToList();

            productionOrderWorkSchedules = ResetStartEnd(productionOrderWorkSchedules);
            productionOrderWorkSchedules = CalculateWorkTimeWithParents(productionOrderWorkSchedules);

            var plannableSchedules = new List <ProductionOrderWorkSchedule>();
            var plannedSchedules   = new List <ProductionOrderWorkSchedule>();

            GetInitialPlannables(productionOrderWorkSchedules, plannedSchedules, plannableSchedules);
            while (plannableSchedules.Any())
            {
                //find next element by using the activity slack rule
                //Todo: Remove after testing
                //var shortest = GetHighestPriority(plannableSchedules);
                CalculateActivitySlack(plannableSchedules, currentTime);
                var shortest = GetShortest(plannableSchedules);
                plannableSchedules.Remove(shortest);
                //Add a fix spot on a machine with start/end
                AddMachine(plannedSchedules, shortest, currentTime);
                plannedSchedules.Add(shortest);

                //search for parents and if available and allowed add it to the schedule
                var parents = _context.GetParents(shortest);
                foreach (var parent in parents)
                {
                    if (!plannableSchedules.Contains(parent) && IsTechnologicallyAllowed(parent, plannedSchedules))
                    {
                        plannableSchedules.Add(parent);
                    }
                    _context.SaveChanges();
                }
            }
            if (productionOrderWorkSchedules.Count() != plannedSchedules.Count())
            {
                notplanned = productionOrderWorkSchedules.Where(pows => !plannedSchedules.Contains(pows)).ToList();
            }
        }
Example #2
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();
        }