public void TestBackwardSchedulingTransitionTimeForeachOperationIsCorrect(
            string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            foreach (var productionOrderBomAsDemand in dbTransactionData.ProductionOrderBomGetAll())
            {
                ProductionOrderBom productionOrderBom =
                    (ProductionOrderBom)productionOrderBomAsDemand;
                int expectedStartBackward = productionOrderBom.GetStartTimeBackward().GetValue() +
                                            TransitionTimer.GetTransitionTimeFactor() *
                                            productionOrderBom.GetDurationOfOperation().GetValue();
                int actualStartBackward = productionOrderBom.GetStartTimeOfOperation().GetValue();
                Assert.True(expectedStartBackward.Equals(actualStartBackward),
                            $"The transition time before operationStart is not correct: " +
                            $"expectedStartBackward: {expectedStartBackward}, actualStartBackward {actualStartBackward}");

                int expectedEndBackward = productionOrderBom.GetStartTimeOfOperation().GetValue() +
                                          productionOrderBom.GetDurationOfOperation().GetValue();
                int actualEndBackward = productionOrderBom.GetEndTimeBackward().GetValue();
                Assert.True(expectedEndBackward.Equals(actualEndBackward),
                            $"EndBackward is not correct: " +
                            $"expectedEndBackward: {expectedEndBackward}, actualEndBackward {actualEndBackward}");
            }
        }
예제 #2
0
        public string GetGraphizString(ProductionOrderBom productionOrderBom)
        {
            // Demand(CustomerOrder);20;Truck

            string graphizString;
            ProductionOrderOperation productionOrderOperation =
                productionOrderBom.GetProductionOrderOperation();

            if (productionOrderOperation != null)
            {
                T_ProductionOrderOperation tProductionOrderOperation =
                    productionOrderOperation.GetValue();
                graphizString = $"D: ProductionOrderBom;{ToGraphizString(productionOrderBom)}"
                                // + $"bs({tProductionOrderOperation.StartBackward});" +
                                // $"be({tProductionOrderOperation.EndBackward});" +
                                // $"\\nOperationName: {tProductionOrderOperation}"
                ;
            }
            else
            {
                throw new MrpRunException("Every productionOrderBom must have exact one operation.");
            }

            return(graphizString);
        }
예제 #3
0
        public override void Remove(Demand t)
        {
            ProductionOrderBom productionOrderBom = (ProductionOrderBom)t;
            Id operationId = productionOrderBom.GetProductionOrderOperationId();

            _operationToBom[operationId].Remove(t.GetId());

            base.Remove(t);
        }
예제 #4
0
        public DueTime GetEarliestPossibleStartTimeOf(ProductionOrderBom productionOrderBom)
        {
            DueTime   earliestStartTime = productionOrderBom.GetStartTimeBackward();
            Providers providers         = ZppConfiguration.CacheManager.GetAggregator()
                                          .GetAllChildProvidersOf(productionOrderBom);

            if (providers.Count() > 1)
            {
                throw new MrpRunException("A productionOrderBom can only have one provider !");
            }


            Provider stockExchangeProvider = providers.GetAny();

            if (earliestStartTime.IsGreaterThanOrEqualTo(
                    stockExchangeProvider.GetStartTimeBackward()))
            {
                earliestStartTime = stockExchangeProvider.GetStartTimeBackward();
            }
            else
            {
                throw new MrpRunException("A provider of a demand cannot have a later dueTime.");
            }

            Demands stockExchangeDemands = ZppConfiguration.CacheManager.GetAggregator()
                                           .GetAllChildDemandsOf(stockExchangeProvider);

            if (stockExchangeDemands.Any() == false)
            // StockExchangeProvider has no childs (stockExchangeDemands),
            // take that from stockExchangeProvider
            {
                DueTime childDueTime = stockExchangeProvider.GetStartTimeBackward();
                if (childDueTime.IsGreaterThan(earliestStartTime))
                {
                    earliestStartTime = childDueTime;
                }
            }
            else
            // StockExchangeProvider has childs (stockExchangeDemands)
            {
                foreach (var stockExchangeDemand in stockExchangeDemands)
                {
                    DueTime stockExchangeDemandDueTime = stockExchangeDemand.GetStartTimeBackward();
                    if (stockExchangeDemandDueTime.IsGreaterThan(earliestStartTime))
                    {
                        earliestStartTime = stockExchangeDemandDueTime;
                    }
                }
            }

            return(earliestStartTime);
        }
        public Demands CreateProductionOrderBomsForArticleBom(
            M_ArticleBom articleBom, Quantity quantity,
            ProductionOrder parentProductionOrder)
        {
            Demands newProductionOrderBoms = new Demands();
            ProductionOrderOperation productionOrderOperation = null;

            if (articleBom.OperationId == null)
            {
                throw new MrpRunException(
                          "Every PrOBom must have an operation. Add an operation to the articleBom.");
            }

            // load articleBom.Operation
            if (articleBom.Operation == null)
            {
                articleBom.Operation =
                    _dbMasterDataCache.M_OperationGetById(
                        new Id(articleBom.OperationId.GetValueOrDefault()));
            }

            // don't create an productionOrderOperation twice, take existing
            if (_alreadyCreatedProductionOrderOperations.ContainsKey(articleBom.Operation))
            {
                productionOrderOperation =
                    _alreadyCreatedProductionOrderOperations[articleBom.Operation];
            }

            ProductionOrderBom newProductionOrderBom =
                ProductionOrderBom.CreateTProductionOrderBom(articleBom, parentProductionOrder,
                                                             productionOrderOperation, quantity);

            if (newProductionOrderBom.HasOperation() == false)
            {
                throw new MrpRunException(
                          "Every PrOBom must have an operation. Add an operation to the articleBom.");
            }

            if (_alreadyCreatedProductionOrderOperations.ContainsKey(articleBom.Operation) == false)
            {
                _alreadyCreatedProductionOrderOperations.Add(articleBom.Operation,
                                                             newProductionOrderBom.GetProductionOrderOperation());
            }

            newProductionOrderBoms.Add(newProductionOrderBom);


            return(newProductionOrderBoms);
        }
예제 #6
0
        public override void Add(Demand item)
        {
            if (base.Contains(item))
            {
                return;
            }
            ProductionOrderBom productionOrderBom = (ProductionOrderBom)item;
            Id operationId = productionOrderBom.GetProductionOrderOperationId();

            if (_operationToBom.ContainsKey(operationId) == false)
            {
                _operationToBom.Add(operationId, new Ids());
            }
            _operationToBom[operationId].Add(productionOrderBom.GetId());
            base.Add(item);
        }
예제 #7
0
        /***
         * Requirements
         * */
        /*
         * /// <summary>
         * /// Creates stock reservation if possible
         * /// </summary>
         * /// <param name="stock"></param>
         * /// <param name="demand"></param>
         * public void TryCreateStockReservation(Stock stock, IDemandToProvider demand)
         * {
         * var stockReservations = GetReserved(demand.ArticleId);
         * var bought = GetAmountBought(demand.ArticleId);
         * //get the current amount of free available articles
         * var current = stock.Current + bought - stockReservations;
         * decimal quantity;
         * //either reserve all that are in stock or the amount needed
         * quantity = demand.Quantity > current ? current : demand.Quantity;
         * if (quantity == 0) return;
         * var demandProviderStock = new DemandProviderStock()
         * {
         *     ArticleId = stock.ArticleForeignKey,
         *     Quantity = quantity,
         *     DemandRequesterId = demand.DemandRequesterId ?? demand.Id,
         *     StockId = stock.Id
         * };
         * Demands.Add(demandProviderStock);
         * SaveChanges();
         * }*/

        public List <ProductionOrder> CreateChildProductionOrders(IDemandToProvider demand, decimal amount, int simulationId)
        {
            ProductionOrderBom bom = null;

            if (demand.GetType() == typeof(DemandProductionOrderBom))
            {
                bom = ProductionOrderBoms.FirstOrDefault(a => a.Id == ((DemandProductionOrderBom)demand).ProductionOrderBomId);
            }

            var lotsize          = SimulationConfigurations.Single(a => a.Id == simulationId).Lotsize;
            var productionOrders = new List <ProductionOrder>();

            /*decimal bomQuantity;
             * if (bom != null)
             *  bomQuantity = ArticleBoms.AsNoTracking().Single(a => a.ArticleChildId == demand.ArticleId &&
             *      a.ArticleParentId == bom.ProductionOrderParent.ArticleId).Quantity * lotsize;
             * else
             *  bomQuantity = ArticleBoms.AsNoTracking().Single(a =>a.ArticleChildId == demand.ArticleId &&
             *      a.ArticleParentId == null).Quantity * lotsize;
             */
            while (amount > 0)// || bomQuantity > 0)
            {
                var productionOrder = CreateProductionOrder(demand, GetDueTimeByOrder(demand), simulationId);
                if (amount > 0)
                {
                    var demandProviderProductionOrder = CreateDemandProviderProductionOrder(demand, productionOrder,
                                                                                            amount > lotsize ? lotsize : amount);

                    //if the article has a parent create a relationship
                    if (bom != null)
                    {
                        demandProviderProductionOrder.DemandRequesterId = demand.Id;
                        Demands.Update(demandProviderProductionOrder);
                    }
                }
                SaveChanges();
                amount -= lotsize;
                //bomQuantity -= lotsize;
                productionOrders.Add(productionOrder);
            }

            return(productionOrders);
        }
예제 #8
0
        public ProductionOrderBom TryCreateProductionOrderBoms(IDemandToProvider demand, ProductionOrder parentProductionOrder, int simulationId)
        {
            if (parentProductionOrder == null)
            {
                return(null);
            }
            var lotsize  = SimulationConfigurations.Single(a => a.Id == simulationId).Lotsize;
            var quantity = demand.Quantity > lotsize ? lotsize : demand.Quantity;
            var pob      = new ProductionOrderBom()
            {
                Quantity = quantity,
                ProductionOrderParentId = parentProductionOrder.Id
            };

            Add(pob);
            SaveChanges();
            if (demand.GetType() == typeof(DemandProductionOrderBom))
            {
                AssignDemandProviderToProductionOrderBom((DemandProductionOrderBom)demand, pob);
            }
            return(pob);
        }
예제 #9
0
 public void AssignDemandProviderToProductionOrderBom(DemandProductionOrderBom demand, ProductionOrderBom pob)
 {
     if (pob.DemandProductionOrderBoms == null)
     {
         pob.DemandProductionOrderBoms = new List <DemandProductionOrderBom>();
     }
     pob.DemandProductionOrderBoms.Add(demand);
     demand.ProductionOrderBomId = pob.Id;
     Update(demand);
     Update(pob);
     SaveChanges();
 }
        public void TestApplyConfirmations(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IAggregator aggregator = ZppConfiguration.CacheManager.GetAggregator();

            // Ein CustomerOrderParts darf kein Kind haben und darf nicht beendet sein
            Ids customerOrderIds = new Ids();

            foreach (var demand in dbTransactionData.CustomerOrderPartGetAll())
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                customerOrderIds.Add(customerOrderPart.GetCustomerOrderId());
                Providers childs = aggregator.GetAllChildProvidersOf(customerOrderPart);
                Assert.False(childs.Any());
                Assert.False(customerOrderPart.IsFinished());
            }

            // Ein PurchaseOrderPart darf kein Elter haben und darf nicht beendet sein.
            Ids purchaseOrderIds = new Ids();

            foreach (var demand in dbTransactionData.PurchaseOrderPartGetAll())
            {
                PurchaseOrderPart purchaseOrderPart = (PurchaseOrderPart)demand;
                purchaseOrderIds.Add(purchaseOrderPart.GetPurchaseOrderId());

                Assert.False(purchaseOrderPart.IsFinished());
                Demands demands = aggregator.GetAllParentDemandsOf(demand);
                Assert.True(demands == null || demands.Any() == false);
            }

            // Für jede CustomerOrder muss es mind. noch ein CustomerOrderPart geben.
            foreach (var customerOrder in dbTransactionData.CustomerOrderGetAll())
            {
                Assert.True(customerOrderIds.Contains(customerOrder.GetId()));
            }

            // Für jede PurchaseOrder muss es mind. noch ein PurchaseOrderPart geben.
            foreach (var purchaseOrder in dbTransactionData.PurchaseOrderGetAll())
            {
                Assert.True(purchaseOrderIds.Contains(purchaseOrder.GetId()));
            }

            // Ein StockExchangeProvider muss mind. ein Kind haben.
            foreach (var stockExchangeProvider in dbTransactionData.StockExchangeProvidersGetAll())
            {
                Demands childs = aggregator.GetAllChildDemandsOf(stockExchangeProvider);
                Assert.True(childs.Any());
            }

            // Ein StockExchangeDemand darf nicht beendet und geschlossen sein.
            foreach (var stockExchangeDemand in dbTransactionData.StockExchangeDemandsGetAll())
            {
                bool isOpen = OpenDemandManager.IsOpen((StockExchangeDemand)stockExchangeDemand);
                Assert.False(stockExchangeDemand.IsFinished() && isOpen == false);
            }

            // Eine ProductionOrder darf nicht beendet sein und für eine ProductionOrder
            // muss es mind. eine  Operation geben.
            Ids productionOrderIds = new Ids();
            Ids operationIds       = new Ids();

            foreach (var operation in dbTransactionData.ProductionOrderOperationGetAll())
            {
                Id productionOrderId = operation.GetProductionOrderId();
                if (productionOrderIds.Contains(productionOrderId) == false)
                {
                    productionOrderIds.Add(productionOrderId);
                }

                operationIds.Add(operation.GetId());
            }
            foreach (var provider in dbTransactionData.ProductionOrderGetAll())
            {
                ProductionOrder productionOrder = (ProductionOrder)provider;
                Assert.False(productionOrder.DetermineProductionOrderState()
                             .Equals(State.Finished));
                Assert.True(productionOrderIds.Contains(productionOrder.GetId()));
            }

            // Für jede ProductionOrderBom muss die dazugehörige Operation da sein.
            foreach (var demand in dbTransactionData.ProductionOrderBomGetAll())
            {
                ProductionOrderBom productionOrderBom = (ProductionOrderBom)demand;
                operationIds.Contains(productionOrderBom.GetProductionOrderOperationId());
            }

            // Für jeden DemandToProvider und ProviderToDemand müssen die dazugehörigen
            // Demands und Provider existieren.
            foreach (var demandToProvider in dbTransactionData.DemandToProviderGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(demandToProvider.GetDemandId());
                Provider provider =
                    dbTransactionData.ProvidersGetById(demandToProvider.GetProviderId());
                Assert.NotNull(demand);
                Assert.NotNull(provider);
            }

            foreach (var providerToDemand in dbTransactionData.ProviderToDemandGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(providerToDemand.GetDemandId());
                Provider provider =
                    dbTransactionData.ProvidersGetById(providerToDemand.GetProviderId());
                Assert.NotNull(demand);
                Assert.NotNull(provider);
            }
        }