Beispiel #1
0
 public EdgeToNeighbor(Node neighbor, int cost)
 {
     this.cost = cost;
     this.neighbor = neighbor;
 }
Beispiel #2
0
 /// <summary>
 /// Determines if a node exists within the graph.
 /// </summary>
 /// <param name="n">The node to check for in the graph.</param>
 /// <returns><b>True</b> if the node <b>n</b> exists in the graph, <b>False</b> otherwise.</returns>
 public virtual bool Contains(Node n)
 {
     return Contains(n.Key);
 }
Beispiel #3
0
 public EdgeToNeighbor(Node neighbor)
     : this(neighbor, 0)
 {
 }
Beispiel #4
0
 /// <summary>
 /// Adds an undirected edge from one node to another.
 /// </summary>
 /// <remarks>If the passed-in nodes do not exist in the graph, an <b>ArgumentException</b>
 /// exception is thrown.</remarks>
 public virtual void AddUndirectedEdge(Node u, Node v)
 {
     AddUndirectedEdge(u, v, 0);
 }
Beispiel #5
0
 /// <summary>
 /// Adds an undirected, weighted edge from one node to another.
 /// </summary>
 /// <param name="cost">The weight of the edge.</param>
 /// <remarks>If the passed-in nodes do not exist in the graph, an <b>ArgumentException</b>
 /// exception is thrown.</remarks>
 public virtual void AddUndirectedEdge(Node u, Node v, int cost)
 {
     // Make sure u and v are Nodes in this graph
     if (nodes.ContainsKey(u.Key) && nodes.ContainsKey(v.Key))
     {
         // Add an edge from u -> v and from v -> u
         u.AddDirected(v, cost);
         v.AddDirected(u, cost);
     }
     else
         // one or both of the nodes were not found in the graph
         throw new ArgumentException("One or both of the nodes supplied were not members of the graph.");
 }
Beispiel #6
0
 public virtual Node AddNode(string key, object data,int XCoordinate, int YCoordinate,int TransmissionRange)
 {
     // Make sure the key is unique
     if (!nodes.ContainsKey(key))
     {
         Node n = new Node(key, data);
         n.XCoordinate = XCoordinate;
         n.YCoordinate = YCoordinate;
         n.TransmissionRange = TransmissionRange;
         nodes.Add(n);
         return n;
     }
     else
         throw new ArgumentException("There already exists a node in the graph with key " + key);
 }
Beispiel #7
0
 /// <summary>
 /// Adds a new node to the graph.
 /// </summary>
 /// <param name="n">A node instance to add to the graph</param>
 /// <remarks>If there already exists a node in the graph with the same <b>key</b> value as <b>n</b> then an
 /// <b>ArgumentException</b> exception will be thrown.</remarks>
 public virtual void AddNode(Node n)
 {
     // Make sure this node is unique
     if (!nodes.ContainsKey(n.Key))
         nodes.Add(n);
     else
         throw new ArgumentException("There already exists a node in the graph with key " + n.Key);
 }
Beispiel #8
0
        /// <summary>
        /// Adds a new node to the graph.
        /// </summary>
        /// <param name="key">The key value of the node to add.</param>
        /// <param name="data">The data of the node to add.</param>
        /// <returns>A reference to the Node that was created and added to the graph.</returns>
        /// <remarks>If there already exists a node in the graph with the same <b>key</b> value then an
        /// <b>ArgumentException</b> exception will be thrown.</remarks>
        public virtual Node AddNode(string key, object data)
        {
            // Make sure the key is unique
            if (!nodes.ContainsKey(key))
            {
                Node n = new Node(key, data);

                nodes.Add(n);
                return n;
            }
            else
                throw new ArgumentException("There already exists a node in the graph with key " + key);
        }
Beispiel #9
0
 /// <summary>
 /// Removes a Node from the NodeList.
 /// </summary>
 public virtual void Remove(Node n)
 {
     data.Remove(n.Key);
 }
Beispiel #10
0
 /// <summary>
 /// Adds a new Node to the NodeList.
 /// </summary>
 public virtual void Add(Node n)
 {
     data.Add(n.Key, n);
 }
Beispiel #11
0
 /// <summary>
 /// Adds a weighted, directed edge from this node to the passed-in Node n.
 /// </summary>
 /// <param name="cost">The weight of the edge.</param>
 protected internal virtual void AddDirected(Node n, int cost)
 {
     AddDirected(new EdgeToNeighbor(n, cost));
 }
Beispiel #12
0
 /// <summary>
 /// Adds an unweighted, directed edge from this node to the passed-in Node n.
 /// </summary>
 protected internal virtual void AddDirected(Node n)
 {
     AddDirected(new EdgeToNeighbor(n));
 }