Пример #1
0
        public static void DoWork()
        {
            FooNode a = new FooNode("NodeA");
            FooNode b = new FooNode("NodeB");
            FooNode c = new FooNode("NodeC");
            FooNode d = new FooNode("NodeD");
            FooNode e = new FooNode("NodeE");
            FooNode f = new FooNode("NodeF");

            FooEdge edge1 = new FooEdge(a, d);
            FooEdge edge2 = new FooEdge(d, c);
            FooEdge edge3 = new FooEdge(c, b);
            FooEdge edge4 = new FooEdge(d, b);
            FooEdge edge5 = new FooEdge(d, e);
            FooEdge edge6 = new FooEdge(e, c);
            FooEdge edge7 = new FooEdge(e, f);

            FooGraph graph = new FooGraph();

            graph.AddEdge(edge1);
            graph.AddEdge(edge2);
            graph.AddEdge(edge3);
            graph.AddEdge(edge4);
            graph.AddEdge(edge5);
            graph.AddEdge(edge6);
            graph.AddEdge(edge7);
        }
Пример #2
0
        public bool AddEdge(FooEdge e)
        {
            if (this.Edges.Contains(e))
            {
                return(false);
            }

            if (this.Edges.FirstOrDefault(x => x.NodeA == e.NodeA && x.NodeB == e.NodeB) != null)
            {
                return(false);
            }

            this.Edges.Add(e);

            return(true);
        }
Пример #3
0
        public static List <FooEdge> GetAdjacentEdges(FooEdge e, FooGraph g)
        {
            List <FooEdge> allEdgesExceptCurrent = g.Edges.Where(x => x != e).ToList();
            List <FooEdge> adjacentEdges         = new List <FooEdge>();
            FooNode        nodeA = e.NodeA;
            FooNode        nodeB = e.NodeB;

            foreach (var edge in allEdgesExceptCurrent.Where(x => x.NodeA == nodeA || x.NodeB == nodeA))
            {
                adjacentEdges.Add(edge);
            }

            foreach (var edge in allEdgesExceptCurrent.Where(x => x.NodeA == nodeB || x.NodeB == nodeB))
            {
                adjacentEdges.Add(edge);
            }

            return(adjacentEdges);
        }