Example #1
0
        public bool IsWithinInterval(DueTime dueTime)
        {
            bool isInInterval = dueTime.GetValue() <= EndAt &&
                                dueTime.GetValue() >= StartAt;

            return(isInInterval);
        }
Example #2
0
        /**
         * SE:I --> satisfy by orders PuOP
         */
        public EntityCollector Satisfy(Demand demand, Quantity demandedQuantity)
        {
            EntityCollector entityCollector = new EntityCollector();
            M_Article       article         = demand.GetArticle();
            DueTime         dueTime         = demand.GetStartTimeBackward();

            if (article.ToBuild)
            {
                throw new MrpRunException(
                          "You try to create a purchaseOrderPart for a articleToBuild.");
            }

            // currently only one businessPartner per article TODO: This could be changing
            M_ArticleToBusinessPartner articleToBusinessPartner =
                _dbMasterDataCache.M_ArticleToBusinessPartnerGetAllByArticleId(article.GetId())[0];
            M_BusinessPartner businessPartner =
                _dbMasterDataCache.M_BusinessPartnerGetById(new Id(articleToBusinessPartner
                                                                   .BusinessPartnerId));
            T_PurchaseOrder purchaseOrder = new T_PurchaseOrder();

            // [Name],[DueTime],[BusinessPartnerId]
            purchaseOrder.DueTime         = dueTime.GetValue();
            purchaseOrder.BusinessPartner = businessPartner;
            purchaseOrder.Name            = $"PurchaseOrder{article.Name} for " +
                                            $"businessPartner {purchaseOrder.BusinessPartner.Id}";

            // init a new purchaseOderPart
            T_PurchaseOrderPart tPurchaseOrderPart = new T_PurchaseOrderPart();

            // [PurchaseOrderId],[ArticleId],[Quantity],[State],[ProviderId]
            tPurchaseOrderPart.PurchaseOrder   = purchaseOrder;
            tPurchaseOrderPart.PurchaseOrderId = purchaseOrder.Id;
            tPurchaseOrderPart.Article         = article;
            tPurchaseOrderPart.ArticleId       = article.Id;
            tPurchaseOrderPart.Quantity        =
                CalculateQuantity(articleToBusinessPartner, demandedQuantity) *
                articleToBusinessPartner
                .PackSize;
            if (tPurchaseOrderPart.Quantity < demandedQuantity.GetValue())
            {
                throw new MrpRunException("You cannot purchase less than you need!");
            }

            tPurchaseOrderPart.State = State.Created;

            PurchaseOrderPart purchaseOrderPart =
                new PurchaseOrderPart(tPurchaseOrderPart, null);

            T_DemandToProvider demandToProvider = new T_DemandToProvider()
            {
                DemandId   = demand.GetId().GetValue(),
                ProviderId = purchaseOrderPart.GetId().GetValue(),
                Quantity   = demandedQuantity.GetValue()
            };

            entityCollector.Add(purchaseOrderPart);
            entityCollector.Add(demandToProvider);
            return(entityCollector);
        }
        public void SetStartTimeBackward(DueTime startTime)
        {
            if (_productionOrderOperation.IsReadOnly)
            {
                throw new MrpRunException("A readOnly entity cannot be changed anymore.");
            }

            DueTime transitionTime =
                new DueTime(TransitionTimer.CalculateTransitionTime(GetDuration()));
            // startBackwards
            DueTime startTimeOfOperation = startTime.Plus(transitionTime);

            _productionOrderOperation.StartBackward = startTimeOfOperation.GetValue();
            // endBackwards
            _productionOrderOperation.EndBackward =
                startTimeOfOperation.GetValue() + GetDuration().GetValue();
        }
 public override void SetStartTimeBackward(DueTime startTime)
 {
     if (_tStockExchangeDemand.IsReadOnly)
     {
         throw new MrpRunException("A readOnly entity cannot be changed anymore.");
     }
     _tStockExchangeDemand.RequiredOnTime = startTime.GetValue();
 }
 public override void SetEndTimeBackward(DueTime endTime)
 {
     if (_stockExchangeProvider.IsReadOnly)
     {
         throw new MrpRunException("A readOnly entity cannot be changed anymore.");
     }
     _stockExchangeProvider.RequiredOnTime = endTime.GetValue();
 }
 public override void SetEndTimeBackward(DueTime endTime)
 {
     if (_productionOrder.IsReadOnly)
     {
         throw new MrpRunException("A readOnly entity cannot be changed anymore.");
     }
     _productionOrder.DueTime = endTime.GetValue();
 }
 public override void SetProvided(DueTime atTime)
 {
     if (_stockExchangeProvider.IsReadOnly)
     {
         throw new MrpRunException("A readOnly entity cannot be changed anymore.");
     }
     _stockExchangeProvider.State = State.Finished;
     _stockExchangeProvider.Time  = atTime.GetValue();
 }
Example #8
0
 public override void SetEndTimeBackward(DueTime endTime)
 {
     if (_tPurchaseOrderPart.IsReadOnly)
     {
         throw new MrpRunException("A readOnly entity cannot be changed anymore.");
     }
     EnsurePurchaseOrderIsLoaded();
     _tPurchaseOrderPart.PurchaseOrder.DueTime =
         endTime.GetValue();
 }
        public void SetEndTimeBackward(DueTime endTime)
        {
            if (_productionOrderOperation.IsReadOnly)
            {
                throw new MrpRunException("A readOnly entity cannot be changed anymore.");
            }

            // endBackwards
            _productionOrderOperation.EndBackward = endTime.GetValue();
            // startBackwards
            DueTime startTimeOfOperation = endTime.Minus(GetDuration().ToDueTime());

            _productionOrderOperation.StartBackward = startTimeOfOperation.GetValue();
        }
Example #10
0
        private static T_CustomerOrder CreateCustomerOrder(DueTime dueTime)
        {
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            var order = new T_CustomerOrder()
            {
                BusinessPartnerId = dbMasterDataCache.M_BusinessPartnerGetAll()[0].Id,
                DueTime           = dueTime.GetValue(),//,
                CreationTime      = 0,
                Name = $"RandomProductionOrder{random.Next()}",
            };

            return(order);
        }
        public static Demand CreateStockExchangeProductionOrderDemand(M_ArticleBom articleBom, DueTime dueTime)
        {
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Demand;
            stockExchange.Quantity          = articleBom.Quantity;
            stockExchange.State             = State.Created;
            M_Stock stock = dbMasterDataCache.M_StockGetByArticleId(new Id(articleBom.ArticleChildId));

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Withdrawal;

            StockExchangeDemand stockExchangeDemand =
                new StockExchangeDemand(stockExchange);

            return(stockExchangeDemand);
        }
Example #12
0
        /**
         * returns a provider, which can be a stockExchangeProvider, if article can be fulfilled by stock, else
         * a productionOrder/purchaseOrderPart
         */
        private Provider CreateStockExchangeProvider(M_Article article, DueTime dueTime,
                                                     Quantity demandedQuantity)
        {
            if (demandedQuantity == null || demandedQuantity.GetValue() == 0)
            {
                throw new MrpRunException("Quantity is not set.");
            }
            M_Stock         stock         = _dbMasterDataCache.M_StockGetByArticleId(article.GetId());
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Provider;
            stockExchange.Quantity          = demandedQuantity.GetValue(); // TODO: PASCAL .GetValueOrDefault();
            stockExchange.State             = State.Created;

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Withdrawal;
            StockExchangeProvider stockExchangeProvider = new StockExchangeProvider(stockExchange);

            return(stockExchangeProvider);
        }
        public static Demand CreateStockExchangeStockDemand(Id articleId, DueTime dueTime, Quantity quantity)
        {
            if (quantity == null || quantity.GetValue() == null)
            {
                throw new MrpRunException("Quantity is not set.");
            }
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            T_StockExchange stockExchange = new T_StockExchange();

            stockExchange.StockExchangeType = StockExchangeType.Demand;
            stockExchange.Quantity          = quantity.GetValue().GetValueOrDefault();
            stockExchange.State             = State.Created;
            M_Stock stock = dbMasterDataCache.M_StockGetByArticleId(articleId);

            stockExchange.Stock          = stock;
            stockExchange.StockId        = stock.Id;
            stockExchange.RequiredOnTime = dueTime.GetValue();
            stockExchange.ExchangeType   = ExchangeType.Insert;
            StockExchangeDemand stockExchangeDemand =
                new StockExchangeDemand(stockExchange);

            return(stockExchangeDemand);
        }
Example #14
0
        public List <Provider> GetProvidersForInterval(DueTime from, DueTime to)
        {
            var providers        = _dbTransactionData.StockExchangeProvidersGetAll();
            var currentProviders = providers.GetAll().FindAll(x =>
                                                              x.GetStartTimeBackward().GetValue() >= from.GetValue() &&
                                                              x.GetStartTimeBackward().GetValue() <= to.GetValue());

            return(currentProviders);
        }
Example #15
0
 public bool IsBeforeInterval(DueTime dueTime)
 {
     return(dueTime.GetValue() < StartAt);
 }
Example #16
0
 public void SetIdleStartTime(DueTime nextIdleStartTime)
 {
     _idleStartTime = nextIdleStartTime.GetValue();
 }
        public void ScheduleWithGifflerThompsonAsZaepfel(IPriorityRule priorityRule,
                                                         IDirectedGraph <INode> operationGraph)
        {
            Dictionary <Id, List <Resource> > resourcesByResourceCapabilityId =
                new Dictionary <Id, List <Resource> >();

            foreach (var resourceCapability in _dbMasterDataCache.M_ResourceCapabilityGetAll())
            {
                resourcesByResourceCapabilityId.Add(resourceCapability.GetId(),
                                                    ZppConfiguration.CacheManager.GetAggregator()
                                                    .GetResourcesByResourceCapabilityId(resourceCapability.GetId()));
            }

            // set correct idleStartTimes in resources from operations of last cycle(s)
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IDbTransactionData dbTransactionDataArchive =
                ZppConfiguration.CacheManager.GetDbTransactionDataArchive();

            // TODO: This is a huge performance impact, consider having an T_Resource with new field IdleStartTime
            // so the following collection iterations can be skipped (Archive operations can be huge)
            CorrectIdleStartTimesOfMachines(dbTransactionData.ProductionOrderOperationGetAll(),
                                            resourcesByResourceCapabilityId);
            CorrectIdleStartTimesOfMachines(dbTransactionDataArchive.ProductionOrderOperationGetAll(),
                                            resourcesByResourceCapabilityId);


            /*
             * S: Menge der aktuell einplanbaren Arbeitsvorgänge
             * a: Menge der technologisch an erster Stelle eines Fertigungsauftrags stehenden Arbeitsvorgänge
             * N(o): Menge der technologisch direkt nachfolgenden Arbeitsoperationen von Arbeitsoperation o
             * M(o): Maschine auf der die Arbeitsoperation o durchgeführt wird
             * K: Konfliktmenge (die auf einer bestimmten Maschine gleichzeitig einplanbaren Arbeitsvorgänge)
             * p(o): Bearbeitungszeit von Arbeitsoperation o (=Duration)
             * t(o): Startzeit der Operation o (=Start)
             * d(o): Fertigstellungszeitpunkt von Arbeitsoperation o (=End)
             * d_min: Minimum der Fertigstellungszeitpunkte
             * o_min: Operation mit minimalem Fertigstellungszeitpunkt
             * o1: beliebige Operation aus K (o_dach bei Zäpfel)
             */
            IStackSet <ProductionOrderOperation> S = new StackSet <ProductionOrderOperation>();

            // Bestimme initiale Menge: S = a
            S = CreateS(operationGraph);

            // t(o) = 0 für alle o aus S
            foreach (var o in S)
            {
                int newStart = o.GetStartTimeBackward().GetValue();
                o.SetStartTime(newStart);
            }

            // while S not empty do
            while (S != null && S.Any())
            {
                int d_min = Int32.MaxValue;
                ProductionOrderOperation o_min = null;
                foreach (var o in S)
                {
                    // Berechne d(o) = t(o) + p(o) für alle o aus S
                    int newEnd = o.GetStartTime() + o.GetValue().Duration;
                    o.SetEndTime(newEnd);
                    // Bestimme d_min = min{ d(o) | o aus S }
                    if (o.GetEndTime() < d_min)
                    {
                        d_min = o.GetEndTime();
                        o_min = o;
                    }
                }

                // Bilde Konfliktmenge K = { o | o aus S UND M(o) == M(o_min) UND t(o) < d_min }
                IStackSet <ProductionOrderOperation> K = new StackSet <ProductionOrderOperation>();
                foreach (var o in S)
                {
                    if (o.GetValue().ResourceCapabilityId.Equals(o_min.GetValue().ResourceCapabilityId) &&
                        o.GetStartTime() < d_min)
                    {
                        K.Push(o);
                    }
                }

                // while K not empty do
                if (K.Any())
                {
                    // Entnehme Operation mit höchster Prio (o1) aus K und plane auf nächster freier Resource ein

                    List <ProductionOrderOperation> allO1 = new List <ProductionOrderOperation>();

                    foreach (var machine in resourcesByResourceCapabilityId[o_min.GetResourceCapabilityId()]
                             .OrderBy(x => x.GetIdleStartTime().GetValue()))
                    {
                        if (K.Any() == false)
                        {
                            break;
                        }

                        ProductionOrderOperation o1 = null;
                        o1 = priorityRule.GetHighestPriorityOperation(machine.GetIdleStartTime(),
                                                                      K.GetAll());
                        if (o1 == null)
                        {
                            throw new MrpRunException("This is not possible if K.Any() is true.");
                        }

                        allO1.Add(o1);

                        K.Remove(o1);

                        o1.SetMachine(machine);
                        // correct op's start time if resource's idleTime is later
                        if (machine.GetIdleStartTime().GetValue() > o1.GetStartTime())
                        {
                            int newStart = machine.GetIdleStartTime().GetValue();
                            o1.SetStartTime(newStart);
                            int newEnd = o1.GetStartTime() + o1.GetValue().Duration;
                            o1.SetEndTime(newEnd);
                        }

                        // correct op's start time if op's material is later available
                        DueTime dueTimeOfOperationMaterial = o1.GetEarliestPossibleStartTime();
                        if (dueTimeOfOperationMaterial.GetValue() > o1.GetStartTime())
                        {
                            int newStart = dueTimeOfOperationMaterial.GetValue();
                            o1.SetStartTime(newStart);
                            int newEnd = o1.GetStartTime() + o1.GetValue().Duration;
                            o1.SetEndTime(newEnd);
                        }

                        machine.SetIdleStartTime(new DueTime(o1.GetEndTime()));
                    }


                    // t(o) = d(letzte o1 aus allO1) für alle o aus K (ohne alle o1)
                    foreach (var o in K)
                    {
                        o.SetStartTime(allO1[allO1.Count - 1].GetEndTime());
                    }

                    /*if N(o1) not empty then
                     *  S = S vereinigt N(o1) ohne alle o1
                     */
                    foreach (var o1 in allO1)
                    {
                        INode o1AsNode = new Node(o1);

                        INodes allPredecessorsRecursive =
                            operationGraph.GetPredecessorNodesRecursive(o1AsNode);
                        if (allPredecessorsRecursive != null)
                        {
                            IStackSet <ProductionOrderOperation> N =
                                new StackSet <ProductionOrderOperation>(
                                    allPredecessorsRecursive.Select(x =>
                                                                    (ProductionOrderOperation)x.GetEntity()));

                            // t(o) = d(o1) für alle o aus N(o1)
                            foreach (var n in N)
                            {
                                n.SetStartTime(o1.GetEndTime());
                            }
                        }

                        // prepare for next round
                        operationGraph.RemoveNode(o1AsNode, true);
                    }

                    S = CreateS(operationGraph);
                }
            }
        }