/** * 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()); } }
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); }
/** * No need to traverse --> graph is ready, just do some modifications: * remove ProductionOrderBoms, replace ProductionOrder by operationGraph, ... */ private DemandToProviderGraph CreateGraph3() { IDbTransactionData dbTransactionData = ZppConfiguration.CacheManager.GetDbTransactionData(); DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph(); // replace ProductionOrder by operationGraph foreach (var productionOrder in dbTransactionData.ProductionOrderGetAll()) { if (productionOrder.IsReadOnly() == false) { var productionOrderBomNode = new Node(productionOrder); if (demandToProviderGraph.Contains(productionOrderBomNode)) { OperationGraph operationGraph = new OperationGraph((ProductionOrder)productionOrder); INodes leafOfOperationGraph = operationGraph.GetLeafNodes(); demandToProviderGraph.ReplaceNodeByDirectedGraph(productionOrderBomNode, operationGraph); /*// remove all arrows from leaf, since material must be ready to the * // corresponding operation not to first operation * INodes successorsOfLeaf = * demandToProviderGraph.GetSuccessorNodes(leafOfOperationGraph.GetAny()); * foreach (var successor in successorsOfLeaf) * { * demandToProviderGraph.RemoveEdge(leafOfOperationGraph.GetAny(), successor); * }*/// --> somehow not neccessary } } } // connect every ProductionOrderBom successor to its operation foreach (var productionOrderBom in dbTransactionData.ProductionOrderBomGetAll()) { if (productionOrderBom.IsReadOnly() == false) { var productionOrderBomNode = new Node(productionOrderBom); if (demandToProviderGraph.Contains(productionOrderBomNode)) { ProductionOrderOperation productionOrderOperation = ((ProductionOrderBom)productionOrderBom).GetProductionOrderOperation(); INodes successorNodes = demandToProviderGraph.GetSuccessorNodes(productionOrderBom.GetId()); demandToProviderGraph.RemoveNode(productionOrderBomNode.GetId(), false); foreach (var successor in successorNodes) { demandToProviderGraph.AddEdge( new Edge(new Node(productionOrderOperation), successor)); } } } } return(demandToProviderGraph); }
public OrderOperationGraph() : base() { // Don't try to remove subgraphs that rootType != customerOrderPart, // it's nearly impossible to correctly identify those (with performance in mind) // CreateGraph(dbTransactionData, aggregator); DemandToProviderGraph demandToProviderGraph = CreateGraph3(); _nodes = demandToProviderGraph.GetNodes(); if (IsEmpty()) { return; } }
private void AssertGraphsAreNotEmpty(OrderOperationGraph orderOperationGraph) { if (ZppConfiguration.IsInPerformanceMode) { return; } DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph(); if (demandToProviderGraph.IsEmpty()) { throw new MrpRunException("How could the demandToProviderGraph be empty ?"); } if (orderOperationGraph.IsEmpty()) { throw new MrpRunException("How could the orderOperationGraph be empty ?"); } }
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(); } }