public Track(Track PreviousTrack, Arc Transition) { if (_Target==null) throw new InvalidOperationException("You must specify a target Node for the Track class."); Queue = PreviousTrack; _Cost = Queue.Cost + Transition.Cost; _NbArcsVisited = Queue._NbArcsVisited + 1; EndNode = Transition.EndNode; }
/// <summary> /// Directly Adds an arc to the graph. /// </summary> /// <exception cref="ArgumentException">Cannot add an arc if one of its extremity nodes does not belong to the graph.</exception> /// <param name="NewArc">The arc to add.</param> /// <returns>'true' if it has actually been added / 'false' if the arc is null or if it is already in the graph.</returns> public bool AddArc(Arc NewArc) { if ( NewArc==null || LA.Contains(NewArc) ) return false; if ( !LN.Contains(NewArc.StartNode) || !LN.Contains(NewArc.EndNode) ) throw new ArgumentException("Cannot add an arc if one of its extremity nodes does not belong to the graph."); LA.Add(NewArc); return true; }
/// <summary> /// Removes a node from the graph as well as the linked arcs. /// </summary> /// <param name="ArcToRemove">The arc to remove.</param> /// <returns>'true' if succeeded / 'false' otherwise.</returns> public bool RemoveArc(Arc ArcToRemove) { if ( ArcToRemove==null ) return false; try { LA.Remove(ArcToRemove); ArcToRemove.StartNode.OutgoingArcs.Remove(ArcToRemove); ArcToRemove.EndNode.IncomingArcs.Remove(ArcToRemove); } catch { return false; } return true; }
public bool AddArcWithNoChk(Node StartNode, Node EndNode, float Weight) { Arc NewArc = new Arc(StartNode, EndNode); NewArc.Weight = Weight; LA.Add(NewArc); return true; }
/// <summary> /// Creates an arc between two nodes that are already registered in the graph, adds it to the graph and returns its reference. /// </summary> /// <exception cref="ArgumentException">Cannot add an arc if one of its extremity nodes does not belong to the graph.</exception> /// <param name="StartNode">Start node for the arc.</param> /// <param name="EndNode">End node for the arc.</param> /// <param name="Weight">Weight for the arc.</param> /// <returns>The reference of the new arc / null if the arc is already in the graph.</returns> public Arc AddArc(Node StartNode, Node EndNode, float Weight) { Arc NewArc = new Arc(StartNode, EndNode); NewArc.Weight = Weight; return AddArc(NewArc) ? NewArc : null; }