//#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 AddRoadNode(T key, RoadNode value) /*添加?个顶点 */ { //不允许插入重复值 if (Contains(key)) //哈希值一致就认为顶点一致 { throw new ArgumentException("插入了重复顶点!"); } dicRoadNode.Add(key, value); }
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); } }
protected Cell cellCopy;//用于在不同的函数之间保存之前的状态 /// <summary> /// 边界红绿灯的地方是不更新和移动的或者做判断 /// </summary> /// <param name="rN"></param> /// <param name="cell"></param> internal virtual void Drive(RoadNode rN, Cell cell) { this.innerCell = cell; this.innerCellCopy = cell.Copy(); this.NormalRun(rN, 0); //更新位置 this.Accelerate(rN, 0); //符合条件就加速 this.Decelerate(rN, 0); //否则减速 }
/// <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()); } }
public void RemoveRoadNode(RoadNode value) { if (value != null) { adlistNetWork.RemoveRoadNode(value.GetHashCode()); } else { throw new ArgumentNullException(); } }
public RoadNode FindRoadNode(RoadNode roadNode) { if (roadNode == null) { throw new ArgumentNullException("参数不能为Null"); } if (adlistNetWork.Contains(roadNode.GetHashCode())) { return(adlistNetWork.Find(roadNode.GetHashCode())); } return(null); }
public RoadEdge FindRoadEdge(RoadNode from, RoadNode to) { if (from != null && to != null) { //找到内部的哈希表对应的该节点 RoadNode fromRN = this.FindRoadNode(from); if (fromRN != null) {//查询用户的请求 return(fromRN.FindRoadEdge(to)); } return(null); } else { throw new ArgumentNullException(); } }
public RoadEdge(RoadNode fromRN, RoadNode toRN) { if (fromRN == null && toRN == null) { throw new ArgumentNullException("无法使用空的节点构造边"); } this.rnFrom = fromRN; this.rnTo = toRN; this.synRuleChain = new SynchronicUpdateRuleChain(this); this.asynRuleChain = new AsynchronicUpdateRuleChain(this); ///需要引入工厂模式 this.roadLaneChain = new RoadLaneChain(); //RoadLane rl = new RoadLane(this,LaneType.Straight); //this.roadLaneChain.Add(rl); //this.queWaitedCACell = new Queue<CACell>(); }
/// <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(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()); }
public RoadEdge(RoadNode fromRN, RoadNode toRN, TripCostAnalyzer tripCost) : this(fromRN, toRN) { this._tripCostAnalyzer = tripCost; }
protected abstract void Decelerate(RoadNode rn, int iHeadWay);
protected abstract void NormalRun(RoadNode rn, int iHeadWay);