コード例 #1
0
        /**
         * no confirmations are created and applied
         */
        private void StartTestCycle(SimulationInterval simulationInterval, bool shouldPersist)
        {
            Quantity customerOrderQuantity = new Quantity(ZppConfiguration.CacheManager
                                                          .GetTestConfiguration().CustomerOrderPartQuantity);


            // init transactionData
            ZppConfiguration.CacheManager.ReloadTransactionData();

            _customerOrderCreator = new CustomerOrderCreator(customerOrderQuantity);
            _customerOrderCreator.CreateCustomerOrders(simulationInterval, customerOrderQuantity);

            // execute mrp2
            Zpp.Mrp2.impl.Mrp2 mrp2 = new Zpp.Mrp2.impl.Mrp2(simulationInterval);
            mrp2.StartMrp2();

            DebuggingTools.PrintStateToFiles(simulationInterval,
                                             ZppConfiguration.CacheManager.GetDbTransactionData(), "", true);

            // no confirmations

            // persisting cached/created data
            if (shouldPersist)
            {
                ZppConfiguration.CacheManager.Persist();
            }
        }
コード例 #2
0
        private static void AdaptState(IEnumerable <IScheduleNode> scheduleNodes,
                                       SimulationInterval simulationInterval, Type[] typesToAdapt)
        {
            foreach (var scheduleNode in scheduleNodes)
            {
                // everyEntity must set read-only (to avoid future changes besides delete)
                scheduleNode.SetReadOnly();

                if (typesToAdapt.Contains(scheduleNode.GetType()) == false)
                {
                    continue;
                }

                bool startIsWithinInterval =
                    simulationInterval.IsWithinInterval(scheduleNode.GetStartTimeBackward());
                DueTime endTime = scheduleNode.GetEndTimeBackward();
                bool    endTimeIsWithinIntervalOrBefore =
                    simulationInterval.IsWithinInterval(endTime) ||
                    simulationInterval.IsBeforeInterval(endTime);
                if (startIsWithinInterval)
                {
                    scheduleNode.SetInProgress();
                }

                if (endTimeIsWithinIntervalOrBefore)
                {
                    scheduleNode.SetFinished();
                }
            }
        }
コード例 #3
0
        /**
         * includes demandToProviderGraph, OrderOperationGraph and dbTransactionData
         * forcePrint: force printing even if in performanceMode
         */
        public static void PrintStateToFiles(SimulationInterval simulationInterval,
                                             IDbTransactionData dbTransactionData, string stageName, bool includeOrderOperationGraph,
                                             bool forcePrint = false)
        {
            if (Constants.IsWindows == false || ZppConfiguration.IsInPerformanceMode)
            {
                // skip this in the cloud/IsInPerformanceMode
                if (forcePrint == false)
                {
                    return;
                }
            }

            CleanupOldFiles();

            WriteToFile(
                $"{SimulationFolder}dbTransactionData_interval_{simulationInterval.StartAt}_{stageName}.txt",
                dbTransactionData.ToString());
            WriteToFile(
                $"{SimulationFolder}dbTransactionDataArchive_interval_{simulationInterval.StartAt}_{stageName}.txt",
                ZppConfiguration.CacheManager.GetDbTransactionDataArchive().ToString());
            DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph();

            WriteToFile(
                $"{SimulationFolder}demandToProviderGraph_interval_{simulationInterval.StartAt}_{stageName}.txt",
                demandToProviderGraph.ToString());
            if (includeOrderOperationGraph)
            {
                OrderOperationGraph orderOperationGraph = new OrderOperationGraph();
                WriteToFile(
                    $"orderOperationGraph_interval_{simulationInterval.StartAt}_{stageName}.log",
                    orderOperationGraph.ToString());
            }
        }
コード例 #4
0
 public DemandOrProviders GetDemandsOrProvidersWhereStartTimeIsWithinInterval(
     SimulationInterval simulationInterval, DemandOrProviders demandOrProviders)
 {
     // startTime within interval
     return(new DemandOrProviders(demandOrProviders.GetAll().Where(x =>
                                                                   simulationInterval.IsWithinInterval(x.GetStartTimeBackward()))));
 }
コード例 #5
0
        public static void CreateConfirmations(SimulationInterval simulationInterval)
        {
            /*ISimulator simulator = new Simulator();
             * simulator.ProcessCurrentInterval(simulationInterval, _orderGenerator);*/
            // --> (Martin's impl) does not work correctly, use trivial impl instead TODO: Just an info for you Martin

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


            // 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();
                    }
                }
            }

            // no confirmations: some nodes has no state (PrO) or must be adapted differently (COPs)
            // confirmations only for: stockExchanges, purchaseOrderParts, operations
            Type[] typesToAdapt = new Type[]
            {
                typeof(StockExchangeDemand), typeof(StockExchangeProvider),
                typeof(PurchaseOrderPart), typeof(ProductionOrderOperation)
            };

            // operations
            AdaptState(dbTransactionData.ProductionOrderOperationGetAll(), simulationInterval,
                       typesToAdapt);

            // demands
            AdaptState(dbTransactionData.DemandsGetAll(), simulationInterval, typesToAdapt);

            // provider
            AdaptState(dbTransactionData.ProvidersGetAll(), simulationInterval, typesToAdapt);
        }
コード例 #6
0
 public DemandOrProviders GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
     SimulationInterval simulationInterval, DemandOrProviders demandOrProviders)
 {
     // endTime within interval
     return(new DemandOrProviders(demandOrProviders.GetAll().Where(x =>
     {
         DueTime endTime = x.GetEndTimeBackward();
         return simulationInterval.IsWithinInterval(endTime) ||
         simulationInterval.IsBeforeInterval(endTime);
     })));
 }
コード例 #7
0
        /**
         * without confirmations
         */
        public void StartMultipleTestCycles()
        {
            const int maxSimulatingTime = 5000;
            int       defaultInterval   =
                ZppConfiguration.CacheManager.GetTestConfiguration().SimulationInterval;

            // for (int i = 0; i * _interval < maxSimulatingTime; i++)
            for (int i = 0; i *defaultInterval < maxSimulatingTime; i++)
            {
                SimulationInterval simulationInterval =
                    new SimulationInterval(i * defaultInterval, defaultInterval - 1);
                StartTestCycle(simulationInterval, true);
            }
        }
コード例 #8
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();*/
        }
コード例 #9
0
        public void StartPerformanceStudy(bool shouldPersist)
        {
            ZppConfiguration.IsInPerformanceMode = true;

            int maxSimulatingTime = ZppConfiguration.CacheManager.GetTestConfiguration()
                                    .SimulationMaximumDuration;
            int defaultInterval =
                ZppConfiguration.CacheManager.GetTestConfiguration().SimulationInterval;
            Quantity customerOrderQuantity = new Quantity(ZppConfiguration.CacheManager
                                                          .GetTestConfiguration().CustomerOrderPartQuantity);

            _customerOrderCreator = new CustomerOrderCreator(customerOrderQuantity);

            string performanceLogCycles = "[";

            for (int i = 0; i *defaultInterval <= maxSimulatingTime; i++)
            {
                SimulationInterval simulationInterval =
                    new SimulationInterval(i * defaultInterval, defaultInterval - 1);

                StartOneCycle(simulationInterval, customerOrderQuantity);

                if (ZppConfiguration.CacheManager.GetDbTransactionDataArchive()
                    .CustomerOrderPartGetAll().Count() > customerOrderQuantity.GetValue())
                {
                    break;
                }
            }
            // TODO: here is no performance measure anymore, remove whole surounding method ?
            // DebuggingTools.PrintStateToFiles(dbTransactionData, true);
            DebuggingTools.WritePerformanceLog(performanceLogCycles);

            // persisting cached/created data
            if (shouldPersist)
            {
                ZppConfiguration.CacheManager.Persist();
            }
        }
コード例 #10
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();
            }
        }
 public ForwardScheduler(OrderOperationGraph orderOperationGraph, SimulationInterval simulationInterval)
 {
     _orderOperationGraph = orderOperationGraph;
     _simulationInterval  = simulationInterval;
 }
コード例 #12
0
        public void CreateCustomerOrders(SimulationInterval interval,
                                         Quantity customerOrderQuantity)
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            TestConfiguration testConfiguration =
                ZppConfiguration.CacheManager.GetTestConfiguration();

            // skip creating COs, if goal has reached
            if (_createdCustomerOrdersCount >= testConfiguration.CustomerOrderPartQuantity)
            {
                return;
            }

            int cycles =
                testConfiguration.SimulationMaximumDuration /
                testConfiguration.SimulationInterval;
            int customerOrdersToCreate;
            int totalCustomerOrdersToCreate =
                (int)customerOrderQuantity.GetValue().GetValueOrDefault();

            if (totalCustomerOrdersToCreate < cycles)
            {
                customerOrdersToCreate = totalCustomerOrdersToCreate;
            }
            else
            {
                customerOrdersToCreate = totalCustomerOrdersToCreate / (cycles + 1);// round up
            }

            List <T_CustomerOrder>     createdCustomerOrders     = new List <T_CustomerOrder>();
            List <T_CustomerOrderPart> createdCustomerOrderParts = new List <T_CustomerOrderPart>();

            while (createdCustomerOrders.Count < customerOrdersToCreate)
            {
                var creationTime     = interval.StartAt;
                var endOrderCreation = interval.EndAt;

                while (creationTime < endOrderCreation)
                {
                    var order = _orderGenerator.GetNewRandomOrder(time: creationTime);
                    foreach (var orderPart in order.CustomerOrderParts)
                    {
                        orderPart.CustomerOrder   = order;
                        orderPart.CustomerOrderId = order.Id;
                        createdCustomerOrderParts.Add(orderPart);
                    }

                    createdCustomerOrders.Add(order);

                    // TODO : Handle this another way
                    creationTime = order.CreationTime;

                    if (createdCustomerOrders.Count >= customerOrdersToCreate)
                    {
                        break;
                    }
                }
            }
            dbTransactionData.CustomerOrderPartAddAll(createdCustomerOrderParts);
            dbTransactionData.CustomerOrderAddAll(createdCustomerOrders);
            _createdCustomerOrdersCount += createdCustomerOrders.Count;
        }
コード例 #13
0
 public Mrp2(PerformanceMonitors performanceMonitors, SimulationInterval simulationInterval)
 {
     _performanceMonitors = performanceMonitors;
     _simulationInterval  = simulationInterval;
 }
コード例 #14
0
 public void StartOneCycle(SimulationInterval simulationInterval)
 {
     StartOneCycle(simulationInterval, null);
 }
コード例 #15
0
        private void ScheduleForward(OrderOperationGraph orderOperationGraph, SimulationInterval simulationInterval)
        {
            IForwardScheduler forwardScheduler = new ForwardScheduler(orderOperationGraph, simulationInterval);

            forwardScheduler.ScheduleForward();
        }
コード例 #16
0
 public Mrp2(SimulationInterval simulationInterval)
 {
     _simulationInterval = simulationInterval;
 }
コード例 #17
0
 public void CreateConfirmations(SimulationInterval simulationInterval)
 {
     ConfirmationCreator.CreateConfirmations(simulationInterval);
 }