示例#1
0
文件: GraphNode.cs 项目: J-Jinn/cs262
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        ///
        /// Method adds a new edge to the list of edges incident to the vertex,
        /// if it does not exist already in the list.
        ///
        /// </summary>
        ///
        /// <param name="e">an edge</param>
        public void AddIncidentEdge(GraphEdge e)
        {
            foreach (GraphEdge edge in incidentEdges)
            {
                if (edge.ToString() == e.ToString())
                {
                    return;
                }
            }

            incidentEdges.Add(e);
        }
示例#2
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR METHOD SEPARATOR
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        ///
        /// Method adds a new directed edge, creating endpoint nodes if necessary.
        /// (edge is added to adjacency list of from-to (origin-destination) edges)
        ///
        /// 1.  Create from/origin node if it doesn't exist.
        /// 1.a. Get node reference from dictionary.
        /// 2.  Create to/destination node if it doesn't exist.
        /// 2.a. Get node reference from the dictionary.
        ///
        /// 3.  Create the new edge using the values obtained from the dictionary
        /// and the type of relationship specified.
        ///
        /// 4.  Add the new edge to the list of edges incident to the origin/to node.
        ///
        /// </summary>
        ///
        /// <param name="name1">name to give the from/origin node</param>
        /// <param name="name2">name to give the to/destination node</param>
        /// <param name="relationship">type of relationship the from/to nodes share</param>
        public void AddEdge(string name1, string name2, string relationship)
        {
            AddNode(name1);                     // create the node if it doesn't already exist
            GraphNode n1 = nodeDict[name1];     // now fetch a reference to the node

            AddNode(name2);
            GraphNode n2 = nodeDict[name2];

            GraphEdge e = new GraphEdge(n1, n2, relationship, "unexplored", 1);

            n1.AddIncidentEdge(e);
        }