/// <summary> /// 找到边 从this到toNode节点的边,出边表 /// </summary> /// <param name="fromRN"></param> internal void RemoveEdge(RoadEdge re) { if (re == null) { throw new ArgumentNullException(); } dicEdge.Remove(RoadEdge.GetHashCode(this, re.rnTo)); }
internal void RemoveEdge(RoadNode toRN) { if (toRN == null) { throw new ArgumentNullException(); } dicEdge.Remove(RoadEdge.GetHashCode(this, toRN)); }
public void RemoveDirectedEdge(T roadNodeHash, RoadEdge edge) { RoadNode rn = this.Find(roadNodeHash); if (rn != null) { rn.RemoveEdge(edge.GetHashCode()); } }
/// <summary> /// 添加有向边 /// </summary> /// <param name="fromRoadNodeHash">要将将边添加到RoadNode哈希表中的RoadNode</param> /// <param name="Edge">要添加的边</param> public void AddDirectedEdge(T fromRoadNodeHash, RoadEdge Edge) { RoadNode rn = this.Find(fromRoadNodeHash); if (rn != null) { rn.AddRoadEdge(Edge); } }
/// <summary> /// 查找方法,新的结构采用出边表 /// </summary> /// <param name="toRoadNode">出节点</param> /// <returns></returns> internal RoadEdge FindRoadEdge(RoadNode toRoadNode) { int iHashkey = RoadEdge.GetHashCode(this, toRoadNode); if (dicEdge.ContainsKey(iHashkey)) { return(dicEdge[iHashkey]); } return(null); }
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()); } }
/// <summary> /// 要行进的车辆元胞, /// </summary> /// <param name="cell">要行进的车辆元胞</param> internal virtual void Drive(RoadEdge re, Cell cell) { //不对副本进行操作,利用副本保存原始记录为函数提供参考 this.innerCell = cell; this.innerCellCopy = cell.Copy(); int iHeadWay = 0; int iAheadSpace = cell.rltPos.Y + cell.cmCarModel.iSpeed - rl.iLength; //6-5-1 if (iAheadSpace > 0) ///车辆应当驾驶出了车道 { //超出了车道范围,进入了交叉口 RoadNode toRoadNode = rl.parEntity.to; //如果车道的出口被堵塞 if (toRoadNode.IsLaneBlocked(rl) == false) { //填充车辆的转向之类的东西,为交接做准备 cell.FillTrack(rl); //前进的距离比车头时距大。进入交叉口,并且交叉口没有元胞 toRoadNode.AddCell(cell); rl.cells.Dequeue(); } else //交叉口被堵塞,可能是信号灯。可能是车辆 {//如果是第一辆车并且被堵塞,就移动到车道的头上进行等待, //不是第一辆车,前面有车堵在了车道上,就安排进入前一辆车的位置(更新后)减去安全位置 if (cell.nextCell == null) { cell.rltPos.Y = rl.iLength; } else { cell.rltPos.Y = cell.nextCell.rltPos.Y - SimContext.SimSettings.iSafeHeadWay; //第五个元胞 } } } else //没有驾驶出车道,新的位置在车道内部 { iHeadWay = cell.nextCell == null ? rl.iLength : cell.nextCell.rltPos.Y;//第六个车和第五个车,车头时距为0 iHeadWay -= (cell.rltPos.Y + 1); //6-5 this.ShiftLane(rl, iHeadWay); //换道 this.NormalRun(rl, iHeadWay); //更新位置 this.Accelerate(rl, iHeadWay); //符合条件就加速 this.Decelerate(rl, iHeadWay); //否则减速 } }
public void AddRoadEdge(RoadEdge re) { if (re.rnFrom == null || re.rnTo != null) { if (this.FindRoadNode(re.rnFrom) != null && this.FindRoadNode(re.rnFrom) != null) { //将RoadEdge添加到字典 this.dicRoadEdge.Add(re.GetHashCode(), re); //将边添加到添加邻接矩阵网络中 adlistNetWork.AddDirectedEdge(re.rnFrom.GetHashCode(), re); } else { throw new ArgumentException("没有在网络中添加创建道路边的节点"); } } else { throw new ArgumentNullException("无法用空节点添加边"); } }
/// <summary> /// 注意在出边表中,保持roadedge的from字段是this节点,否则函数抛出异常 /// </summary> /// <param name="roadEdge"></param> internal void AddRoadEdge(RoadEdge roadEdge) { if (roadEdge != null) { if (!Contains(roadEdge.GetHashCode())) { //加入判断是否是当前点的出边的信息防止出错 if (roadEdge.rnFrom != this) { throw new Exception("添加了不属于该顶点的边"); } dicEdge.Add(roadEdge.GetHashCode(), roadEdge); } else { throw new ArgumentException("添加了重复的边!"); } } else { throw new ArgumentNullException(); } }
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("无法用空节点添加边"); } }
public RoadLane(RoadEdge re, LaneType lt) { parentEntity = re; this.laneType = lt; }
public RoadLane(RoadEdge re) { parentEntity = re; this.laneType = LaneType.Straight;//默认为直行车道 }