Exemplo n.º 1
0
 public void AddNode(GraphNode x)
 {
     if (Count < 30)
     {
         vertices[Count] = x;
         Count++;
     }
     else
     {
         Console.WriteLine("Graph full");
     }
 }
Exemplo n.º 2
0
 public void AddAdjacent(GraphNode x)
 {
     if (AdjacentCount < 30)
     {
         adjacent[AdjacentCount] = x;
         AdjacentCount++;
     }
     else
     {
         Console.WriteLine("No more adjacent can be added");
     }
 }
Exemplo n.º 3
0
        public void testWeightedRemoveVertex()
        {
            WeightedGraph<int> graph = new WeightedGraph<int>();
            int num1 = 1;
            int num2 = 2;
            int num3 = 3;
            int num4 = 4;
            int num5 = 5;

            graph.addEdge(num1, num2);
            graph.addEdge(num2, num3);
            graph.addEdge(num3, num4);
            graph.addEdge(num4, num5);
            graph.addEdge(num1, num3);
            GraphNode<int> node = new GraphNode<int>(num1);

            graph.deleteVertex(num1);
            graph.deleteVertex(num4);
            Assert.IsFalse(graph.AdjacencyList.ContainsKey(num1));
            Assert.IsFalse(graph.AdjacencyList.ContainsKey(num4));
            Assert.IsTrue(graph.numVertices == 3);
            Assert.IsFalse(graph.AdjacencyList[num2].Contains(node));
        }
Exemplo n.º 4
0
        private NodeList<MCNodeData> splitAllChild(NodeList<MCNodeData> rem, GraphNode<MCNodeData> src, int loc)
        {
            for (int i = 0; i < src.Neighbors.Count; i++)
            {
                int locDest = src.Costs[i] == 1 ? 1 - loc : loc;
                if (!Subsets[0].Contains(src.Neighbors[i].Value) && !Subsets[1].Contains(src.Neighbors[i].Value))
                {
                    Subsets[locDest].Add(src.Neighbors[i].Value);
                    _repop.Add(src.Neighbors[i]);
                    rem.Remove((GraphNode<MCNodeData>)src.Neighbors[i]);
                    if (((GraphNode<MCNodeData>)src.Neighbors[i]).Neighbors.Count > 1)
                        rem = splitAllChild(rem, (GraphNode<MCNodeData>)src.Neighbors[i], locDest);
                }
                else
                {
                    _repop.Add(src.Neighbors[i]);
                    rem.Remove((GraphNode<MCNodeData>)src.Neighbors[i]);
                }
            }

            return rem;
        }