public void DemandsAddAll(Demands demands) { foreach (var demand in demands) { DemandsAdd(demand); } // T_ProductionOrderOperation IStackSet <ProductionOrderOperation> tProductionOrderOperations = new StackSet <ProductionOrderOperation>(); foreach (var productionOrderBom in _productionOrderBoms) { T_ProductionOrderBom tProductionOrderBom = (T_ProductionOrderBom)productionOrderBom.ToIDemand(); if (tProductionOrderBom != null) { ((ProductionOrderBom)productionOrderBom).EnsureOperationIsLoadedIfExists(); if (tProductionOrderBom.ProductionOrderOperation == null) { throw new MrpRunException( "Every tProductionOrderBom must have an operation."); } tProductionOrderOperations.Push(new ProductionOrderOperation( tProductionOrderBom.ProductionOrderOperation)); } } _productionOrderOperations.AddAll(tProductionOrderOperations); }
public override void Add(ILinkDemandAndProvider item) { if (item == null) { return; } if (item.Quantity == null || item.Quantity <= 0) { throw new MrpRunException($"Quantity is not correct: {item.Quantity}"); } // a set contains the element only once, else skip adding if (StackSet.Contains(item) == false) { if (_indexDemandId.ContainsKey(item.GetDemandId()) == false) { _indexDemandId.Add(item.GetDemandId(), new Ids()); } _indexDemandId[item.GetDemandId()].Add(item.GetId()); if (_indexProviderId.ContainsKey(item.GetProviderId()) == false) { _indexProviderId.Add(item.GetProviderId(), new Ids()); } _indexProviderId[item.GetProviderId()].Add(item.GetId()); base.Add(item); } }
/** * traverse top-down and remove ProductionOrderBom, replace ProductionOrder by operationGraph */ private void CreateGraph2() { IStackSet <INode> visitedProductionOrders = new StackSet <INode>(); foreach (var rootNode in GetRootNodes()) { TraverseDemandToProviderGraph(rootNode, visitedProductionOrders); } }
StackSet <char> Subject() { var subject = new StackSet <char>(); subject.Push('a'); subject.Push('b'); subject.Push('c'); subject.Push('d'); return(subject); }
public void TestCount() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); IScheduleNode testNumber = new DummyNode(1); IScheduleNode testNumber2 = new DummyNode(5); stackSet.Push(testNumber); stackSet.Push(testNumber2); Assert.True(stackSet.Count().Equals(2), "PopAny didn't work."); }
private void PrintArea(StackSet <Node> stack, HashSet <string> clay, Dictionary <string, Node> seen, Node current, bool flowing) { return; if (current == null) { return; } var sb = new StringBuilder(); var yRange = 30; var xRange = 60; for (var y = current.Location.Y - yRange; y < current.Location.Y + yRange; y++) { for (var x = current.Location.X - xRange; x < current.Location.X + xRange; x++) { if (stack.Contains($"{x},{y}")) { sb.Append('q'); } else if (current.Location.X == x && current.Location.Y == y) { sb.Append('@'); } else if (clay.Contains($"{x},{y}")) { sb.Append('#'); } else if (seen.ContainsKey($"{x},{y}")) { if (seen[$"{x},{y}"].Flowing) { sb.Append('~'); } else { sb.Append('|'); } } else { sb.Append('.'); } } sb.Append($"{y}".PadLeft(5)); sb.AppendLine(); } sb.AppendLine($"Flowing: {flowing}"); Console.SetCursorPosition(0, 0); Console.WriteLine(sb.ToString()); }
public void TestAny() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); Assert.False(stackSet.Any(), "Set should not contain any."); IScheduleNode testNumber = new DummyNode(1); stackSet.Push(testNumber); Assert.True(stackSet.Any(), "Set should contain any."); }
public void TestAdd() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); IScheduleNode testNumber = new DummyNode(1); stackSet.Push(testNumber); stackSet.Push(testNumber); Assert.True(stackSet.Count().Equals(1), "Set contains a duplicate."); Assert.True(stackSet.PopAny().Equals(new DummyNode(new Id(1))), "Value was not correctly added."); }
private void CreateGraph2() { INodes roots = GetRootNodes(); StackSet <IEdge> newEdges = new StackSet <IEdge>(); foreach (var rootNode in roots) { newEdges.PushAll(CreateGraphFor(rootNode, typeof(ProductionOrder), this)); } Clear(); AddEdges(newEdges); }
public IStackSet <INode> GetAllUniqueNodes() { IStackSet <INode> uniqueNodes = new StackSet <INode>(); uniqueNodes.PushAll(_nodes.Select(x => x.GetNode())); if (uniqueNodes.Any() == false) { return(null); } return(uniqueNodes); }
public void TestRemove() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); IScheduleNode testNumber = new DummyNode(1); IScheduleNode testNumber2 = new DummyNode(5); stackSet.Push(testNumber); stackSet.Push(testNumber2); stackSet.Remove(testNumber); Assert.True(stackSet.GetAny().Equals(testNumber2) && stackSet.Count() == 1, "Remove didn't work."); stackSet.Remove(testNumber2); Assert.True(stackSet.Any() == false && stackSet.Count() == 0, "Remove didn't work."); }
public OperationGraph(OrderOperationGraph orderOperationGraph) : base() { IStackSet <IGraphNode> nodes = new StackSet <IGraphNode>(orderOperationGraph.GetNodes()); foreach (var graphNode in nodes) { if (graphNode.GetNode().GetEntity().GetType() != typeof(ProductionOrderOperation)) { orderOperationGraph.RemoveNode(graphNode.GetNode(), true); } } _nodes = orderOperationGraph.GetNodes(); }
public void TestGetAny() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); IScheduleNode testNumber = new DummyNode(1); IScheduleNode testNumber2 = new DummyNode(5); stackSet.Push(testNumber); stackSet.Push(testNumber2); IScheduleNode poppedElement = stackSet.GetAny(); Assert.True( (poppedElement.Equals(testNumber2) || poppedElement.Equals(testNumber)) && stackSet.Count() == 2, "PopAny didn't work."); }
/** * Bottom-Up-Traversal */ private void ValidatePredecessorOperationsTransitionTimeIsCorrect( IStackSet <ProductionOrderOperation> predecessorOperations, ProductionOrderOperation lastOperation, IDirectedGraph <INode> operationGraph, IStackSet <INode> traversedOperations) { if (predecessorOperations == null) { return; } foreach (var currentPredecessor in predecessorOperations) { if (currentPredecessor.GetType() == typeof(ProductionOrderOperation)) { ProductionOrderOperation currentOperation = currentPredecessor; traversedOperations.Push(new Node(currentPredecessor)); // transition time MUST be before the start of Operation int expectedStartBackwardLowerLimit = lastOperation.GetValue().EndBackward.GetValueOrDefault() + TransitionTimer.GetTransitionTimeFactor() * currentOperation.GetValue().Duration; int actualStartBackward = currentOperation.GetValue().StartBackward .GetValueOrDefault(); Assert.True(actualStartBackward >= expectedStartBackwardLowerLimit, $"The transition time between the operations is not correct: " + $"expectedStartBackward: {expectedStartBackwardLowerLimit}, actualStartBackward {actualStartBackward}"); INodes predecessorNodesRecursive = operationGraph.GetPredecessorNodesRecursive(new Node(currentPredecessor)); if (predecessorNodesRecursive != null) { IStackSet <ProductionOrderOperation> newPredecessorNodes = new StackSet <ProductionOrderOperation>( predecessorNodesRecursive.Select(x => (ProductionOrderOperation)x.GetEntity())); ValidatePredecessorOperationsTransitionTimeIsCorrect(newPredecessorNodes, currentOperation, operationGraph, traversedOperations); } } else { throw new MrpRunException( "ProductionOrderToOperationGraph should only contain productionOrders/operations."); } } }
/** * @return: all leafs of all operationGraphs */ private IStackSet <ProductionOrderOperation> CreateS( IDirectedGraph <INode> operationGraph) { INodes leafs = operationGraph.GetLeafNodes(); IStackSet <ProductionOrderOperation> S = new StackSet <ProductionOrderOperation>(); if (leafs != null) { foreach (var leaf in leafs) { S.Push((ProductionOrderOperation)leaf.GetEntity()); } } return(S); }
private void MarkFlowing(Node n, StackSet <Node> stack, HashSet <string> clay, Dictionary <string, Node> seen) { n.Flowing = true; PrintArea(stack, clay, seen, n, true); if (n.Left != null && !n.Left.Flowing && n.Left.Visited) { MarkFlowing(n.Left, stack, clay, seen); } if (n.Right != null && !n.Right.Flowing && n.Right.Visited) { MarkFlowing(n.Right, stack, clay, seen); } if (n.Previous != null && !n.Previous.Flowing) { MarkFlowing(n.Previous, stack, clay, seen); } }
public IStackSet <IEdge> GetEdges() { IStackSet <IEdge> edges = new StackSet <IEdge>(); // one is enough either all successors or all predecessors foreach (var node in _nodes) { foreach (var successor in node.GetSuccessors()) { edges.Push(new Edge(node.GetNode(), successor.GetNode())); } } if (edges.Any() == false) { return(null); } return(edges); }
public void TestGetById() { IStackSet <IScheduleNode> stackSet = new StackSet <IScheduleNode>(); int countNodes = 10; for (int i = 0; i < countNodes; i++) { IScheduleNode testNumber = new DummyNode(i); stackSet.Push(testNumber); } for (int i = countNodes - 1; i > 0; i--) { IScheduleNode scheduleNode = new DummyNode(i); Assert.True( stackSet.GetById(new Id(i)).Equals(scheduleNode) && stackSet.Count() == i + 1, "GetById() didn't work."); stackSet.Remove(scheduleNode); } }
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}'"); }
/* * 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); } }
private int DFS(HashSet <string> clay, Node spring, int ymax, int ymin, Dictionary <string, Node> seen) { var stack = new StackSet <Node>(); stack.Push(spring); var answer = 0; while (stack.Any()) { var current = stack.Pop(); seen[current.Location.Hash] = current; if (current.Location.Y <= ymax && current.Location.Y >= ymin && !current.Visited) { current.Visited = true; answer++; } if (current.Location.Y > ymax) { MarkFlowing(current, stack, clay, seen); continue; } PrintArea(stack, clay, seen, current, false); // down if (!clay.Contains(current.Location.Down.Hash)) { if (!seen.ContainsKey(current.Location.Down.Hash)) { var node = new Node(current.Location.Down, current); stack.Push(node); continue; } else if (seen[current.Location.Down.Hash].Flowing) { MarkFlowing(current, stack, clay, seen); continue; } } var leftAdded = false; var rightAdded = false; // check left if (!clay.Contains(current.Location.Left.Hash)) { if (!seen.ContainsKey(current.Location.Left.Hash)) { var newLeft = new Node(current.Location.Left, current) { Right = current }; current.Left = newLeft; stack.Push(newLeft); leftAdded = true; } else if (seen[current.Location.Left.Hash].Flowing) { current.Flowing = true; } } // check Right if (!clay.Contains(current.Location.Right.Hash)) { if (!seen.ContainsKey(current.Location.Right.Hash)) { var newRight = new Node(current.Location.Right, current) { Left = current }; current.Right = newRight; stack.Push(newRight); rightAdded = true; } else if (seen[current.Location.Right.Hash].Flowing) { current.Flowing = true; } } if (!leftAdded && !rightAdded && current.Previous != null) { stack.Push(current.Previous); } } return(answer); }
public void ItCanPush() { var subject = new StackSet <char>(); subject.Push('a').Should().Be(1); }
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); } } }