private static void ArchiveStockExchangeProvidersWithoutChilds(
            IDbTransactionData dbTransactionData, IAggregator aggregator)
        {
            Providers copyOfStockExchangeProviders = new Providers();

            copyOfStockExchangeProviders.AddAll(dbTransactionData.StockExchangeProvidersGetAll());
            foreach (var stockExchangeProvider in copyOfStockExchangeProviders)
            {
                Demands stockExchangeDemands =
                    aggregator.GetAllChildDemandsOf(stockExchangeProvider);
                if (stockExchangeDemands == null || stockExchangeDemands.Any() == false)
                {
                    ArchiveDemandOrProvider(stockExchangeProvider, dbTransactionData, aggregator,
                                            false);
                }
            }
        }
Ejemplo n.º 2
0
        public void TestBackwardScheduling(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);


            IDbTransactionData dbTransactionData =
                global::Zpp.ZppConfiguration.CacheManager.ReloadTransactionData();

            foreach (var productionOrderOperation in dbTransactionData
                     .ProductionOrderOperationGetAll())
            {
                Assert.True(productionOrderOperation.GetValue().EndBackward != null,
                            $"EndBackward of operation ({productionOrderOperation} is not scheduled.)");
                Assert.True(productionOrderOperation.GetValue().StartBackward != null,
                            $"StartBackward of operation ({productionOrderOperation} is not scheduled.)");
            }
        }
        public void TestJobShopScheduling(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IAggregator        aggregator = ZppConfiguration.CacheManager.GetAggregator();
            IDbTransactionData dbTransactionDataArchive =
                ZppConfiguration.CacheManager.GetDbTransactionDataArchive();
            IAggregator aggregatorArchive = new Aggregator(dbTransactionDataArchive);

            VerifyEveryOperationIsCorrectlyPlanned(dbTransactionData);
            VerifyEveryOperationIsCorrectlyPlanned(dbTransactionDataArchive);

            VerifyEveryMachineHasOnlyOneOperationAtAnyTime(aggregator);
            VerifyEveryMachineHasOnlyOneOperationAtAnyTime(aggregatorArchive);
        }
Ejemplo n.º 4
0
        public void StartOneCycle(SimulationInterval simulationInterval,
                                  Quantity customerOrderQuantity)
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();

            _customerOrderCreator.CreateCustomerOrders(simulationInterval, customerOrderQuantity);

            // Mrp2
            Zpp.Mrp2.impl.Mrp2 mrp2 = new Zpp.Mrp2.impl.Mrp2(simulationInterval);
            mrp2.StartMrp2();
            DebuggingTools.PrintStateToFiles(simulationInterval, dbTransactionData, "1_after_mrp2",
                                             true);

            // CreateConfirmations
            _confirmationManager.CreateConfirmations(simulationInterval);
            DebuggingTools.PrintStateToFiles(simulationInterval, dbTransactionData,
                                             "2_after_create_confirmations", false);

            // ApplyConfirmations
            // TODO: disable these two lines

            /*DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph();
             * string demandToProviderGraphString = demandToProviderGraph.ToString();
             * ZppConfiguration.CacheManager.UseArchiveForGetters();
             * DemandToProviderGraph demandToProviderGraphArchive = new DemandToProviderGraph();
             * string demandToProviderGraphArchiveString = demandToProviderGraphArchive.ToString();
             * ZppConfiguration.CacheManager.UseArchiveForGettersRevert();*/

            _confirmationManager.ApplyConfirmations();

            DebuggingTools.PrintStateToFiles(simulationInterval, dbTransactionData,
                                             "3_after_apply_confirmations", false);

            // TODO: disable following lines

            /* DemandToProviderGraph demandToProviderGraph2 = new DemandToProviderGraph();
             * string demandToProviderGraphString2 = demandToProviderGraph2.ToString();
             * /*ZppConfiguration.CacheManager.UseArchiveForGetters();
             * DemandToProviderGraph demandToProviderGraphArchive2 = new DemandToProviderGraph();
             * string demandToProviderGraphArchiveString2 = demandToProviderGraphArchive2.ToString();
             * ZppConfiguration.CacheManager.UseArchiveForGettersRevert();*/
        }
        public void TestParentsDueTimeIsGreaterThanOrEqualToChildsDueTime(
            string testConfigurationFileName)
        {
            // init
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            foreach (var demandToProvider in dbTransactionData.DemandToProviderGetAll())
            {
                Demand parentDemand =
                    dbTransactionData.DemandsGetById(demandToProvider.GetDemandId());
                if (parentDemand.GetType() == typeof(CustomerOrderPart))
                {
                    continue;
                }

                Provider childProvider =
                    dbTransactionData.ProvidersGetById(demandToProvider.GetProviderId());


                DueTime parentDueTime = parentDemand.GetStartTimeBackward();
                DueTime childDueTime  = childProvider.GetEndTimeBackward();

                Assert.True(parentDueTime.IsGreaterThanOrEqualTo(childDueTime),
                            "ParentDemand's dueTime cannot be smaller than childProvider's dueTime.");
            }

            foreach (var providerToDemand in dbTransactionData.ProviderToDemandGetAll())
            {
                Provider parentProvider =
                    dbTransactionData.ProvidersGetById(providerToDemand.GetProviderId());
                Demand childDemand =
                    dbTransactionData.DemandsGetById(providerToDemand.GetDemandId());

                DueTime parentDueTime = parentProvider.GetStartTimeBackward();
                DueTime childDueTime  = childDemand.GetEndTimeBackward();

                Assert.True(parentDueTime.IsGreaterThanOrEqualTo(childDueTime),
                            "ParentProvider's dueTime cannot be smaller than childDemand's dueTime.");
            }
        }
Ejemplo n.º 6
0
        public void TestAllDemandsAreSatisfiedWithinProviderTable()
        {
            IZppSimulator zppSimulator = new global::Master40.SimulationMrp.impl.ZppSimulator();

            zppSimulator.StartTestCycle();

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            Demands   demands            = dbTransactionData.DemandsGetAll();
            Providers providers          = dbTransactionData.ProvidersGetAll();
            Demands   unsatisfiedDemands = providers.CalculateUnsatisfiedDemands(demands);

            foreach (var unsatisfiedDemand in unsatisfiedDemands)
            {
                Assert.True(false,
                            $"The demand {unsatisfiedDemand} should be satisfied, but it is NOT.");
            }
        }
        private void CreateGraph(IDbTransactionData dbTransactionData)
        {
            foreach (var demandToProvider in dbTransactionData.DemandToProviderGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(new Id(demandToProvider.DemandId));
                Provider provider =
                    dbTransactionData.ProvidersGetById(new Id(demandToProvider.ProviderId));
                if (demand == null || provider == null)
                {
                    throw new MrpRunException("Demand/Provider should not be null.");
                }

                INode fromNode = new Node(demand);
                INode toNode   = new Node(provider);
                IEdge edge     = new Edge(demandToProvider, fromNode, toNode);
                AddEdge(edge);
                _originalEdges.Add(edge);
            }

            foreach (var providerToDemand in dbTransactionData.ProviderToDemandGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(providerToDemand.GetDemandId());
                Provider provider =
                    dbTransactionData.ProvidersGetById(providerToDemand.GetProviderId());
                if (demand == null || provider == null)
                {
                    // provider == null can be the case for archive of transactionData, when a
                    // stockExchangeProvider has more than one child stockExchangeDemand
                    // and one of the stockExchangeDemand is archived, but the
                    // stockExchangeProvider cannot be archived yet (because the
                    // stockExchangeProvider is still needed by the other stockExchangeDemand
                    // to correctly calculate the open quantity of a stockExchangeDemand)
                    throw new MrpRunException("Demand/Provider should not be null.");
                }

                INode fromNode = new Node(provider);
                INode toNode   = new Node(demand);
                IEdge edge     = new Edge(providerToDemand, fromNode, toNode);
                AddEdge(edge);
                _originalEdges.Add(edge);
            }
        }
        public void TestForwardScheduling(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);


            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            foreach (var productionOrderOperation in dbTransactionData
                     .ProductionOrderOperationGetAll())
            {
                T_ProductionOrderOperation tProductionOrderOperation =
                    productionOrderOperation.GetValue();
                if (tProductionOrderOperation.StartBackward < 0)
                {
                    Assert.True(
                        tProductionOrderOperation.StartForward != null &&
                        tProductionOrderOperation.EndForward != null,
                        $"Operation ({tProductionOrderOperation}) is not scheduled forward.");
                    Assert.True(
                        tProductionOrderOperation.StartForward >= 0 &&
                        tProductionOrderOperation.EndForward >= 0,
                        "Forward schedule times of operation ({productionOrderOperation}) are negative.");
                }
            }

            List <DueTime> dueTimes = new List <DueTime>();

            foreach (var demand in dbTransactionData.DemandsGetAll())
            {
                dueTimes.Add(demand.GetStartTimeBackward());
                Assert.True(demand.GetStartTimeBackward().GetValue() >= 0,
                            $"DueTime of demand ({demand}) is negative.");
            }

            foreach (var provider in dbTransactionData.ProvidersGetAll())
            {
                dueTimes.Add(provider.GetStartTimeBackward());
                Assert.True(provider.GetStartTimeBackward().GetValue() >= 0,
                            $"DueTime of provider ({provider}) is negative.");
            }
        }
        public void TestGraphIsComplete(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                global::Zpp.ZppConfiguration.CacheManager.ReloadTransactionData();

            IDirectedGraph <INode> operationGraph =
                new OperationGraph(new OrderOperationGraph());

            IEnumerable <ProductionOrderOperation> productionOrderOperations =
                operationGraph.GetNodes().Select(x => (ProductionOrderOperation)x.GetNode().GetEntity());

            foreach (var productionOrderOperation in dbTransactionData
                     .ProductionOrderOperationGetAll())
            {
                Assert.True(productionOrderOperations.Contains(productionOrderOperation),
                            $"{productionOrderOperation} is missing.");
            }
        }
Ejemplo n.º 10
0
        public void TestGeneratedQuantity()
        {
            ICentralPlanningConfiguration testConfiguration =
                ZppConfiguration.CacheManager.GetTestConfiguration();
            int cycles = testConfiguration.SimulationMaximumDuration /
                         testConfiguration.SimulationInterval;
            int totalCustomerOrdersToCreate = 500;
            int customerOrdersToCreate      = totalCustomerOrdersToCreate / (cycles + 1); // round up


            CustomerOrderCreator og = new CustomerOrderCreator(null);

            og.CreateCustomerOrders(new SimulationInterval(0, 20160),
                                    new Quantity(totalCustomerOrdersToCreate));
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            var orders = dbTransactionData.CustomerOrderGetAll();

            Assert.InRange(orders.Count(), customerOrdersToCreate, customerOrdersToCreate + 10);
        }
Ejemplo n.º 11
0
        public void TestAllDemandsAreInDemandToProviderTable()
        {
            IZppSimulator zppSimulator = new global::Master40.SimulationMrp.impl.ZppSimulator();

            zppSimulator.StartTestCycle();

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            Demands allDbDemands = dbTransactionData.DemandsGetAll();
            LinkDemandAndProviderTable demandToProviderTable =
                dbTransactionData.DemandToProviderGetAll();

            foreach (var demand in allDbDemands)
            {
                bool isInDemandToProviderTable = demandToProviderTable.Contains(demand);
                Assert.True(isInDemandToProviderTable,
                            $"Demand {demand} is NOT in demandToProviderTable.");
            }
        }
        private static void ArchiveDemandOrProvider(IDemandOrProvider demandOrProvider,
                                                    IDbTransactionData dbTransactionData, IAggregator aggregator, bool includeArrows)
        {
            if (demandOrProvider == null)
            {
                throw new MrpRunException("Given demandOrProvider cannot be null.");
            }

            IDbTransactionData dbTransactionDataArchive =
                ZppConfiguration.CacheManager.GetDbTransactionDataArchive();

            if (includeArrows)
            {
                ArchiveArrowsToAndFrom(demandOrProvider, dbTransactionData,
                                       dbTransactionDataArchive, aggregator);
            }

            dbTransactionDataArchive.AddA(demandOrProvider);
            dbTransactionData.DeleteA(demandOrProvider);
        }
        private static void ArchiveFinishedCustomerOrderPartsAndDeleteTheirArrows(
            IDbTransactionData dbTransactionData, IAggregator aggregator)
        {
            Demands copyOfCustomerOrderParts = new Demands();

            copyOfCustomerOrderParts.AddAll(dbTransactionData.CustomerOrderPartGetAll());
            foreach (var demand in copyOfCustomerOrderParts)
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                if (customerOrderPart.IsFinished())
                {
                    ArchiveCustomerOrder(customerOrderPart.GetCustomerOrderId());
                    // archive cop
                    List <ILinkDemandAndProvider> arrows =
                        aggregator.GetArrowsFrom(customerOrderPart);
                    dbTransactionData.DeleteAllFrom(arrows);
                    ArchiveDemandOrProvider(customerOrderPart, dbTransactionData, aggregator,
                                            false);
                }
            }
        }
        public void TestBackwardSchedulingTransitionTimeBetweenOperationsIsCorrect(
            string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            IDirectedGraph <INode> operationGraph =
                new OperationGraph(new OrderOperationGraph());

            IStackSet <INode> innerLeafs =
                operationGraph.GetLeafNodes().ToStackSet();
            IStackSet <INode> traversedNodes = new StackSet <INode>();

            foreach (var leaf in innerLeafs)
            {
                INodes predecessorNodesRecursive =
                    operationGraph.GetPredecessorNodesRecursive(leaf);
                IStackSet <ProductionOrderOperation> newPredecessorNodes =
                    new StackSet <ProductionOrderOperation>(
                        predecessorNodesRecursive.Select(x =>
                                                         (ProductionOrderOperation)x.GetEntity()));

                ProductionOrderOperation
                    lastOperation = (ProductionOrderOperation)leaf.GetEntity();
                ValidatePredecessorOperationsTransitionTimeIsCorrect(newPredecessorNodes,
                                                                     lastOperation, operationGraph, traversedNodes);
                traversedNodes.Push(leaf);
            }

            int expectedTraversedOperationCount =
                new Stack <ProductionOrderOperation>(
                    dbTransactionData.ProductionOrderOperationGetAll()).Count();
            int actualTraversedOperationCount = traversedNodes.Count();

            Assert.True(actualTraversedOperationCount.Equals(expectedTraversedOperationCount),
                        $"expectedTraversedOperationCount {expectedTraversedOperationCount} " +
                        $"doesn't equal actualTraversedOperationCount {actualTraversedOperationCount}'");
        }
        public ProductionOrder GetProductionOrder()
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();

            if (_productionOrderBom.ProductionOrderParent == null)
            {
                var productionOrder =
                    dbTransactionData
                    .ProductionOrderGetById(new Id(_productionOrderBom.ProductionOrderParentId))
                    .ToIProvider() as T_ProductionOrder;
                if (productionOrder == null)
                {
                    throw new Exception("ProductionOrderBom must have one ProductionOrderParent");
                }

                _productionOrderBom.ProductionOrderParent = productionOrder;
            }


            return(new ProductionOrder(_productionOrderBom.ProductionOrderParent));
        }
Ejemplo n.º 16
0
        public Demands GetUnsatisfiedCustomerOrderParts()
        {
            Demands unsatisfiedCustomerOrderParts = new Demands();

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

            Demands customerOrderParts = dbTransactionData.CustomerOrderPartGetAll();

            foreach (var customerOrderPart in customerOrderParts)
            {
                Providers customerOrderPartChilds =
                    aggregator.GetAllChildProvidersOf(customerOrderPart);
                if (customerOrderPartChilds == null || customerOrderPartChilds.Any() == false)
                {
                    unsatisfiedCustomerOrderParts.Add(customerOrderPart);
                }
            }

            return(unsatisfiedCustomerOrderParts);
        }
Ejemplo n.º 17
0
        public void StartMrp1()
        {
            // init
            int MAX_DEMANDS_IN_QUEUE = 100000;

            FastPriorityQueue <DemandQueueNode> demandQueue =
                new FastPriorityQueue <DemandQueueNode>(MAX_DEMANDS_IN_QUEUE);

            IProviderManager providerManager = new ProviderManager();

            foreach (var demand in dbDemands)
            {
                demandQueue.Enqueue(new DemandQueueNode(demand), demand.GetStartTimeBackward().GetValue());
            }

            EntityCollector allCreatedEntities = new EntityCollector();

            while (demandQueue.Count != 0)
            {
                DemandQueueNode firstDemandInQueue = demandQueue.Dequeue();

                EntityCollector response =
                    MaterialRequirementsPlanningForOneDemand(firstDemandInQueue.GetDemand(), providerManager);
                allCreatedEntities.AddAll(response);

                foreach (var demand in response.GetDemands())
                {
                    demandQueue.Enqueue(new DemandQueueNode(demand),
                                        demand.GetStartTimeBackward().GetValue());
                }
            }

            // write data to _dbTransactionData
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();

            dbTransactionData.AddAllFrom(allCreatedEntities);
            // End of MaterialRequirementsPlanning
        }
        public void TestJobShopScheduling(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            foreach (var productionOrderOperation in dbTransactionData
                     .ProductionOrderOperationGetAll())
            {
                T_ProductionOrderOperation tProductionOrderOperation =
                    productionOrderOperation.GetValue();
                Assert.True(tProductionOrderOperation.Start != tProductionOrderOperation.End,
                            $"{productionOrderOperation} was not scheduled.");
                Assert.True(tProductionOrderOperation.ResourceId != null,
                            $"{productionOrderOperation} was not scheduled.");
                Assert.True(
                    tProductionOrderOperation.Start >= productionOrderOperation
                    .GetEarliestPossibleStartTime().GetValue(),
                    "A productionOrderOperation cannot start before its material is available.");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="article"></param>
        /// <param name="dbTransactionData"></param>
        /// <param name="dbMasterDataCache"></param>
        /// <param name="parentProductionOrder"></param>
        /// <param name="quantity">of production article to produce
        /// --> is used for childs as: articleBom.Quantity * quantity</param>
        /// <returns></returns>
        public static Demands CreateProductionOrderBoms(M_Article article,
                                                        Provider parentProductionOrder, Quantity quantity)
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();

            M_Article readArticle = dbTransactionData.M_ArticleGetById(article.GetId());

            if (readArticle.ArticleBoms != null && readArticle.ArticleBoms.Any())
            {
                List <Demand> newDemands = new List <Demand>();
                IProductionOrderBomCreator productionOrderBomCreator = new ProductionOrderBomCreator();

                foreach (M_ArticleBom articleBom in readArticle.ArticleBoms)
                {
                    newDemands.AddRange(
                        productionOrderBomCreator.CreateProductionOrderBomsForArticleBom(articleBom,
                                                                                         quantity, (ProductionOrder)parentProductionOrder));
                }

                // backwards scheduling
                OperationBackwardsSchedule lastOperationBackwardsSchedule = null;

                IEnumerable <ProductionOrderOperation> sortedProductionOrderOperations = newDemands
                                                                                         .Select(x => ((ProductionOrderBom)x).GetProductionOrderOperation())
                                                                                         .OrderByDescending(x => x.GetValue().HierarchyNumber);

                foreach (var productionOrderOperation in sortedProductionOrderOperations)
                {
                    lastOperationBackwardsSchedule = productionOrderOperation.ScheduleBackwards(
                        lastOperationBackwardsSchedule, parentProductionOrder.GetStartTimeBackward());
                }

                return(new ProductionOrderBoms(newDemands));
            }

            return(null);
        }
        /*
         *  foreach sed in beendeten und geschlossenen StockExchangeDemands
         *      Archiviere sed und seine parents (StockExchangeProvider)
         *        und die Pfeile dazwischen
         */
        private static void ArchiveClosedStockExchangeDemandsAndItsParents(
            IDbTransactionData dbTransactionData, IAggregator aggregator)
        {
            IStackSet <IDemandOrProvider> stockExchangesToArchive =
                new StackSet <IDemandOrProvider>();

            foreach (var stockExchangeDemand in dbTransactionData.StockExchangeDemandsGetAll())
            {
                bool isOpen = OpenDemandManager.IsOpen((StockExchangeDemand)stockExchangeDemand);

                if (isOpen == false && stockExchangeDemand.IsFinished())
                {
                    stockExchangesToArchive.Push(stockExchangeDemand);

                    // parent (StockExchangeProviders)
                    Providers stockExchangeProviders =
                        aggregator.GetAllParentProvidersOf(stockExchangeDemand);
                    foreach (var stockExchangeProvider in stockExchangeProviders)
                    {
                        if (aggregator.GetAllChildDemandsOf(stockExchangeProvider).Count() == 1)
                        {
                            stockExchangesToArchive.Push(stockExchangeProvider);
                        }
                        else
                        {
                            // stockExchangeProvider must stay
                        }
                    }
                }
            }

            // archive collected stockexchanges
            foreach (var demandOrProviderToArchive in stockExchangesToArchive)
            {
                ArchiveDemandOrProvider(demandOrProviderToArchive, dbTransactionData, aggregator,
                                        true);
            }
        }
Ejemplo n.º 21
0
        public void TestEveryQuantityOnArrowIsPositive()
        {
            IZppSimulator zppSimulator = new global::Master40.SimulationMrp.impl.ZppSimulator();

            zppSimulator.StartTestCycle();

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.ReloadTransactionData();

            List <ILinkDemandAndProvider>
            demandAndProviderLinks = new List <ILinkDemandAndProvider>();

            demandAndProviderLinks.AddRange(dbTransactionData.DemandToProviderGetAll());
            demandAndProviderLinks.AddRange(dbTransactionData.ProviderToDemandGetAll());

            foreach (var demandAndProviderLink in demandAndProviderLinks)
            {
                Assert.False(
                    demandAndProviderLink.GetQuantity().IsNegative() ||
                    demandAndProviderLink.GetQuantity().IsNull(),
                    $"A quantity on arrow ({demandAndProviderLink}) cannot be negative or null.");
            }
        }
        private static void ArchivedPurchaseOrdersWithoutPurchaseOrderParts()
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();


            Ids purchaseOrderIds = new Ids();

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

            foreach (var purchaseOrder in dbTransactionData.PurchaseOrderGetAll())
            {
                bool purchaseOrderHasNoPurchaseOrderParts =
                    purchaseOrderIds.Contains(purchaseOrder.GetId()) == false;
                if (purchaseOrderHasNoPurchaseOrderParts)
                {
                    ArchivePurchaseOrder(purchaseOrder);
                }
            }
        }
        private static void ArchiveFinishedPurchaseOrderPartsAndDeleteTheirArrows(
            IDbTransactionData dbTransactionData, IAggregator aggregator)
        {
            Providers copyOfPurchaseOrderParts = new Providers();

            copyOfPurchaseOrderParts.AddAll(dbTransactionData.PurchaseOrderPartGetAll());
            foreach (var purchaseOrderPart in copyOfPurchaseOrderParts)
            {
                if (purchaseOrderPart.IsFinished())
                {
                    // delete arrow
                    List <ILinkDemandAndProvider> arrows =
                        aggregator.GetArrowsFrom(purchaseOrderPart);
                    if (arrows != null)
                    {
                        dbTransactionData.DeleteAllFrom(arrows);
                    }

                    // archive purchaseOrderPart
                    ArchiveDemandOrProvider(purchaseOrderPart, dbTransactionData, aggregator,
                                            false);
                }
            }
        }
        private static void ArchivedCustomerOrdersWithoutCustomerOrderParts()
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();


            Ids customerOrderIds = new Ids();

            foreach (var demand in dbTransactionData.CustomerOrderPartGetAll())
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                customerOrderIds.Add(customerOrderPart.GetCustomerOrderId());
            }

            foreach (var customerOrder in dbTransactionData.CustomerOrderGetAll())
            {
                bool customerOrderHasNoCustomerOrderPart =
                    customerOrderIds.Contains(customerOrder.GetId()) == false;
                if (customerOrderHasNoCustomerOrderPart)
                {
                    ArchiveCustomerOrder(customerOrder.GetId());
                }
            }
        }
Ejemplo n.º 25
0
 public static void PrintStateToFiles(IDbTransactionData dbTransactionData, bool forcePrint)
 {
     // interval and end is not used anyway, so the second 1 is here a random number
     PrintStateToFiles(new SimulationInterval(0, 1), dbTransactionData, "", false, forcePrint);
 }
        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);
            }
        }
Ejemplo n.º 27
0
        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);
                }
            }
        }
Ejemplo n.º 28
0
        public static void CreateConfirmationsOld(SimulationInterval simulationInterval)
        {
            /*ISimulator simulator = new Simulator();
             * simulator.ProcessCurrentInterval(simulationInterval, _orderGenerator);*/
            // --> does not work correctly, use trivial impl instead

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

            // stockExchanges, purchaseOrderParts, operations(use PrBom instead):
            // set in progress when startTime is within interval
            DemandOrProviders demandOrProvidersToSetInProgress = new DemandOrProviders();

            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.PurchaseOrderPartGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.StockExchangeDemandsGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.StockExchangeProvidersGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.ProductionOrderBomGetAll())));

            foreach (var demandOrProvider in demandOrProvidersToSetInProgress)
            {
                demandOrProvider.SetInProgress();
                demandOrProvider.SetReadOnly();
            }

            // stockExchanges, purchaseOrderParts, operations(use PrBom instead):
            // set finished when endTime is within interval
            DemandOrProviders demandOrProvidersToSetFinished = new DemandOrProviders();

            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.PurchaseOrderPartGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.StockExchangeDemandsGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.StockExchangeProvidersGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.ProductionOrderBomGetAll())));
            foreach (var demandOrProvider in demandOrProvidersToSetFinished)
            {
                demandOrProvider.SetFinished();
                demandOrProvider.SetReadOnly();
            }

            // customerOrderParts: set finished if all childs are finished
            DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph();
            INodes rootNodes = demandToProviderGraph.GetRootNodes();

            foreach (var rootNode in rootNodes)
            {
                if (rootNode.GetEntity().GetType() == typeof(CustomerOrderPart))
                {
                    CustomerOrderPart customerOrderPart = (CustomerOrderPart)rootNode.GetEntity();
                    customerOrderPart.SetReadOnly();

                    bool allChildsAreFinished = true;
                    foreach (var stockExchangeProvider in aggregator.GetAllChildProvidersOf(
                                 customerOrderPart))
                    {
                        if (stockExchangeProvider.IsFinished() == false)
                        {
                            allChildsAreFinished = false;
                            break;
                        }
                    }

                    if (allChildsAreFinished)
                    {
                        customerOrderPart.SetFinished();
                    }
                }
            }

            // set operations readonly
            foreach (var operation in dbTransactionData.ProductionOrderOperationGetAll())
            {
                operation.SetReadOnly();
            }

            // set productionOrders readonly
            foreach (var productionOrder in dbTransactionData.ProductionOrderGetAll())
            {
                productionOrder.SetReadOnly();
            }

            // future SEs are still not readonly, set it so
            foreach (var stockExchangeDemand in dbTransactionData.StockExchangeDemandsGetAll())
            {
                stockExchangeDemand.SetReadOnly();
            }

            foreach (var stockExchangeProvider in dbTransactionData.StockExchangeProvidersGetAll())
            {
                stockExchangeProvider.SetReadOnly();
            }
        }
        private static void HandleProductionOrderIsInStateCreated(ProductionOrder productionOrder,
                                                                  IAggregator aggregator, IDbTransactionData dbTransactionData)
        {
            // delete all operations
            List <ProductionOrderOperation> operations =
                aggregator.GetProductionOrderOperationsOfProductionOrder(productionOrder);

            dbTransactionData.ProductionOrderOperationDeleteAll(operations);

            // collect entities and demandToProviders/providerToDemands to delete
            List <IDemandOrProvider> demandOrProvidersToDelete =
                CreateProductionOrderSubGraph(true, productionOrder, aggregator);

            // delete all collected entities
            IOpenDemandManager openDemandManager =
                ZppConfiguration.CacheManager.GetOpenDemandManager();

            foreach (var demandOrProvider in demandOrProvidersToDelete)
            {
                // don't forget to delete it from openDemands
                if (demandOrProvider.GetType() == typeof(StockExchangeDemand))
                {
                    if (openDemandManager.Contains((Demand)demandOrProvider))
                    {
                        openDemandManager.RemoveDemand((Demand)demandOrProvider);
                    }
                }

                List <ILinkDemandAndProvider> demandAndProviderLinks =
                    aggregator.GetArrowsToAndFrom(demandOrProvider);
                dbTransactionData.DeleteAllFrom(demandAndProviderLinks);

                dbTransactionData.DeleteA(demandOrProvider);
            }
        }
        private static void ArchiveArrowsToAndFrom(IDemandOrProvider demandOrProvider,
                                                   IDbTransactionData dbTransactionData, IDbTransactionData dbTransactionDataArchive,
                                                   IAggregator aggregator)
        {
            List <ILinkDemandAndProvider> demandAndProviderLinks =
                aggregator.GetArrowsToAndFrom(demandOrProvider);

            foreach (var demandAndProviderLink in demandAndProviderLinks)
            {
                dbTransactionDataArchive.AddA(demandAndProviderLink);
                dbTransactionData.DeleteA(demandAndProviderLink);
            }
        }