public RoadNode FindRoadNode(RoadNode roadNode) { if (roadNode == null) { throw new ArgumentNullException("参数不能为Null"); } if (adlistNetWork.Contains(roadNode.GetHashCode())) { return(adlistNetWork.Find(roadNode.GetHashCode())); } return(null); }
//#region ITrafficEntity 成员 //public EntityType EntityType //{ // get // { // return this._entityType; // } // set // { // this._entityType = value; // } //} //public EntityStatus EntityStatus //{ // get // { // throw new System.NotImplementedException(); // } // set // { // throw new System.NotImplementedException(); // } //} //public MyPoint Postion //{ // get // { // return this._netWorkPosition; // } // set // { // this._netWorkPosition = value; // } //} //#endregion #region INetWork 成员 public void AddRoadNode(RoadNode value) { if (value != null) { adlistNetWork.AddRoadNode(value.GetHashCode(), value); } }
public void RemoveRoadNode(RoadNode value) { if (value != null) { adlistNetWork.RemoveRoadNode(value.GetHashCode()); } else { throw new ArgumentNullException(); } }
public void RemoveEdge(RoadNode fromRoadNode, RoadNode ToRoadNode) { if (fromRoadNode != null && ToRoadNode != null) { RoadEdge re = new RoadEdge(fromRoadNode, ToRoadNode); //邻接矩阵中删除边 adlistNetWork.RemoveDirectedEdge(fromRoadNode.GetHashCode(), new RoadEdge(fromRoadNode, ToRoadNode)); //上下文路段字典中删除边 this.dicRoadEdge.Remove(re.GetHashCode()); } }
public void AddRoadEdge(RoadNode fromRoadNode, RoadNode ToRoadNode) { if (fromRoadNode != null && ToRoadNode != null) { if (this.FindRoadNode(fromRoadNode) != null && this.FindRoadNode(ToRoadNode) != null) { //创建边 RoadEdge re = new RoadEdge(fromRoadNode, ToRoadNode); //将RoadEdge添加到仿真上下文han字典 this.dicRoadEdge.Add(re.GetHashCode(), re); //将边添加到添加邻接矩阵网络中 adlistNetWork.AddDirectedEdge(fromRoadNode.GetHashCode(), re); } else { throw new ArgumentException("没有在网络中添加创建道路边的节点"); } } else { throw new ArgumentNullException("无法用空节点添加边"); } }
/// <summary> /// 静态的哈希函数,用来计算某条边的哈希值 /// </summary> public static int GetHashCode(RoadNode rnFrom, RoadNode rnTo) { return(string.Concat(rnFrom.GetHashCode().ToString(), rnTo.GetHashCode().ToString()).GetHashCode()); }
/// <summary> /// 根据起始节点和结束节点计算边的哈希值 /// </summary> /// <returns></returns> public override int GetHashCode() { return(string.Concat(rnFrom.GetHashCode().ToString(), rnTo.GetHashCode().ToString()).GetHashCode()); }