public void AddEdge(IEdge edge)
        {
            INode      edgeTail = edge.TailNode;
            INode      edgeHead = edge.HeadNode;
            IGraphNode tail;
            IGraphNode head;

            if (_nodes.Contains(edgeTail.GetId()) == false)
            {
                tail = new GraphNode(edgeTail);
                _nodes.Push(tail);
            }
            else
            {
                tail = _nodes.GetById(edgeTail.GetId());
            }

            if (_nodes.Contains(edgeHead.GetId()) == false)
            {
                head = new GraphNode(edgeHead);
                _nodes.Push(head);
            }
            else
            {
                head = _nodes.GetById(edgeHead.GetId());
            }

            head.AddPredecessor(tail);
            tail.AddSuccessor(head);
        }
        private void TraverseDemandToProviderGraph(INode node,
                                                   IStackSet <INode> visitedProductionOrders)
        {
            if (node.GetEntity().GetType() == typeof(ProductionOrderBom))
            {
                // remove, ProductionOrderBoms will be ignored and replaced by operations
                RemoveNode(node, true);
            }
            else if (node.GetEntity().GetType() == typeof(ProductionOrder) &&
                     visitedProductionOrders.Contains(node) == false)
            {
                // insert it like it is in ProductionOrderToOperationGraph

                OperationGraph operationGraph =
                    new OperationGraph((ProductionOrder)node.GetEntity());
                ReplaceNodeByDirectedGraph(node, operationGraph);
                visitedProductionOrders.Push(node);
            }

            INodes successorNodes = GetSuccessorNodes(node);

            if (successorNodes == null)
            {
                return;
            }

            foreach (var successor in successorNodes)
            {
                TraverseDemandToProviderGraph(successor, visitedProductionOrders);
            }
        }
Beispiel #3
0
        public void TestGetEdges()
        {
            IDirectedGraph <INode> directedGraph = new DirectedGraph();

            INode[] nodes = EntityFactory.CreateDummyNodes(3);
            INode   a     = nodes[0];
            INode   b     = nodes[1];
            INode   c     = nodes[2];
            // create a -> b -> c
            IEdge ab = new Edge(a, b);
            IEdge bc = new Edge(b, c);

            directedGraph.AddEdge(ab);
            directedGraph.AddEdge(bc);
            List <IEdge> expectedEdges = new List <IEdge>();

            expectedEdges.Add(ab);
            expectedEdges.Add(bc);

            IStackSet <IEdge> actualEdges = directedGraph.GetEdges();

            foreach (var actualEdge in actualEdges)
            {
                Assert.True(expectedEdges.Contains(actualEdge),
                            $"I have not added this edge {actualEdge}. Where comes that from?");
            }

            foreach (var expectedEdge in expectedEdges)
            {
                Assert.True(actualEdges.Contains(expectedEdge),
                            $"This edge {expectedEdge} was not returned.");
            }
        }
 public bool Contains(T t)
 {
     return(StackSet.Contains(t));
 }