示例#1
0
        /// <summary>
        ///shows all of a persons descendants, depth first order right now....
        /// </summary>
        /// <param name="name"></param> name of person of whom descendants will be found
        private static void Descendants(string name)
        {
            //start at name
            GraphNode n = rg.GetNode(name);
            //look for children edges
            List <GraphEdge> childEdges = n.GetEdges("child");

            foreach (GraphEdge e in childEdges)
            {
                //recurse through the other end of the child edge using To()
                Descendants(e.To());
            }
            Console.WriteLine(n.Name());     //prints the name of the first name, which it shouldn't
        }
示例#2
0
        /// <summary>
        ///shows all of a persons descendants as children, grandchildren, great grandchildren..
        /// </summary>
        /// <param name="name"></param> name of person of whom descendants will be found
        private static void Descendants(string name)
        {
            //start at name
            GraphNode n = rg.GetNode(name);

            //look for children edges
            List <GraphEdge> childEdges = n.GetEdges("child");

            foreach (GraphEdge e in childEdges)
            {
                //refference a name through an edge...
                Descendants(e.To());    //does this work?
            }

            Console.WriteLine(n.Name());     //does this work?
        }
示例#3
0
        //List the descendants of an indvidual
        private static void ListDescendants(string name)
        {
            GraphNode node             = rg.GetNode(name);  //Get the node from the Relationship Graph of the name of the individual
            int       generation_count = 0;                 //Set the generation count to be zero

            //If the individual that the user is searching for does not exist in the current Relationship Graph
            if (node == null)
            {
                Console.Write("{0} not found\n", name);
            }

            else if (node.GetEdges("hasChild").Count == 0)       //If the node has no hasChild edge, print that there are no descendants
            {
                Console.Write("{0} has no descendants\n", name);
            }

            //Else, list out the descendants of the individual
            else
            {
                List <GraphEdge> descendantsList = node.GetEdges("hasChild");       //Get the edges hasChild of the individual

                List <GraphNode> nextDescendants    = new List <GraphNode>();       //Create two new lists of GraphNodes, one for the current generation of
                List <GraphNode> currentDescendants = new List <GraphNode>();       //descendants, and one for the following generation of descendants

                foreach (GraphEdge edge in descendantsList)                         //For every edge hasChild, add the node that the edge is directed towards
                {                                                                   //to the current descendants list of individuals
                    currentDescendants.Add(rg.GetNode(edge.To()));
                }

                while (currentDescendants.Count > 0)                                //As long as the currentDescendants List is not zero
                {
                    //The following if, if-else, and else statements determine the label of descendants to write to the console
                    if (generation_count == 0)
                    {
                        Console.Write(node.Name() + " Children:\n");
                    }

                    else if (generation_count == 1)
                    {
                        Console.Write(node.Name() + " Grandchildren:\n");
                    }

                    else
                    {
                        Console.Write(node.Name());
                        for (int i = 0; i < generation_count; i++)
                        {
                            Console.Write(" Great");
                        }
                        Console.Write(" GrandChildren:\n");
                    }

                    //For each node in the current descendants list
                    foreach (GraphNode descendant in currentDescendants)
                    {
                        Console.Write("{0}\n", descendant.Name());              //Write out the name of the descendant to the console
                        descendantsList = descendant.GetEdges("hasChild");      //Get a list of the edges hasChild from that descendant

                        foreach (GraphEdge edge1 in descendantsList)            //For each of those edges hasChild of the current descendant
                        {
                            nextDescendants.Add(rg.GetNode(edge1.To()));        //Add the node that the edge hasChild is directed towards
                        }
                    }

                    currentDescendants = nextDescendants;                       //Copy the nextDescendant List nodes to the currentDescandents List
                    nextDescendants    = new List <GraphNode>();                //Clear our the nextDescendant List
                    generation_count++;                                         //Increment the generation counter to be used for future labeling of descendants
                }
            }
        }
示例#4
0
        // return string form of edge
        public override string ToString()
        {
            string result = fromNode.Name() + " --(" + label + ")--> " + toNode.Name();

            return(result);
        }