internal void AddConnection(Node targetNode, double distance, bool twoWay) { if (targetNode == null) throw new ArgumentNullException("targetNode"); if (targetNode == this) throw new ArgumentException("Node may not connect to itself."); if (distance <= 0) throw new ArgumentException("Distance must be positive."); connections.Add(new Edge(targetNode, distance)); if (twoWay) targetNode.AddConnection(this, distance, false); }
private void ProcessNode(Node node, List<Node> queue) { var connections = node.Connections.Where(c => queue.Contains(c.Target)); foreach (var connection in connections) { double distance = node.DistanceFromStart + connection.Distance; if (distance < connection.Target.DistanceFromStart) connection.Target.DistanceFromStart = distance; } }
public void AddNode(string name) { var node = new Node(name); this.Nodes.Add(name, node); }
internal Edge(Node target, double distance) { Target = target; Distance = distance; }