Пример #1
0
        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.");
        }
Пример #2
0
        StackSet <char> Subject()
        {
            var subject = new StackSet <char>();

            subject.Push('a');
            subject.Push('b');
            subject.Push('c');
            subject.Push('d');
            return(subject);
        }
Пример #3
0
        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.");
        }
Пример #4
0
        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.");
        }
Пример #5
0
        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.");
        }
Пример #6
0
        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);
        }
Пример #7
0
        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.");
        }
        /*
         *  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);
            }
        }
Пример #9
0
        /**
         * @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);
        }
        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);
        }
Пример #11
0
        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}'");
        }
Пример #13
0
        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);
        }
Пример #14
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);
                }
            }
        }
Пример #15
0
        public void ItCanPush()
        {
            var subject = new StackSet <char>();

            subject.Push('a').Should().Be(1);
        }