コード例 #1
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
        /// <summary>
        /// get the neighbors for the vehicle within the roadSegment. note that the vechile now is not in the roadSegment. This required when the vechile is almost in the junction. so it required to switch to a new road segment.
        /// </summary>
        /// <param name="vehicle">current ve</param>
        /// <param name="Packetdirection"> the packet direction </param>
        /// <param name="selectedNextRoadSegment"> the road segment</param>
        /// <returns>the inter_nei for vehicle</returns>
        public void GetInterNeighbors(VehicleUi vehicle, Direction Packetdirection, RoadSegment selectedNextRoadSegment)
        {
            vehicle.Dispatcher.Invoke((Action) delegate
            {
                vehicle.Inter_Neighbores.Clear();
                List <VehicleUi> allInSameDirection = new List <RoadNet.Components.VehicleUi>();
                foreach (LaneUi lane in selectedNextRoadSegment.Lanes)
                {
                    if (lane.LaneDirection == Packetdirection)
                    {
                        allInSameDirection.AddRange(lane.LaneVehicleAndQueue.LaneVechilesList);
                    }
                }

                int vid = vehicle.VID;
                int rid = selectedNextRoadSegment.RID;

                List <VehicleUi> neibore = new List <RoadNet.Components.VehicleUi>();
                foreach (VehicleUi Inter_vehicle in allInSameDirection)
                {
                    double dis = Computations.Distance(vehicle.InstanceLocation, Inter_vehicle.InstanceLocation);
                    if (dis < Settings.Default.CommunicationRange)
                    {
                        vehicle.Inter_Neighbores.Add(Inter_vehicle);
                        int v_id = Inter_vehicle.VID;
                    }
                }

                // consider the vhicles which are in the front of me and in the same direction too.
                GetIntraNeighborOneWayInfront(vehicle);
                vehicle.Inter_Neighbores.AddRange(vehicle.Intra_Neighbores);
            });
        }
コード例 #2
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
        /// <summary>
        /// get the neighbors for the Currentvehi. in the two ways without consider the direction.
        /// </summary>
        /// <param name="Currentvehi"></param>
        /// <returns></returns>
        public void GetIntraNeighborsTwoWays(VehicleUi Currentvehi)
        {
            if (Currentvehi != null)
            {
                Currentvehi.Dispatcher.Invoke((Action) delegate
                {
                    Currentvehi.Intra_Neighbores.Clear();
                    List <VehicleUi> allInSameDirection = new List <RoadNet.Components.VehicleUi>();
                    foreach (LaneUi lane in Currentvehi.CurrentLane.MyRoadSegment.Lanes)
                    {
                        allInSameDirection.AddRange(lane.LaneVehicleAndQueue.LaneVechilesList);
                    }

                    foreach (VehicleUi Intra_vehicle in allInSameDirection)
                    {
                        // neighbore should be infront of mine and in the same direction and within my range.
                        if (Intra_vehicle != Currentvehi)
                        {
                            double dis = Computations.Distance(Intra_vehicle.InstanceLocation, Currentvehi.InstanceLocation);
                            if (dis < Settings.Default.CommunicationRange)
                            {
                                Currentvehi.Intra_Neighbores.Add(Intra_vehicle);
                            }
                        }
                    }
                });
            }
        }
コード例 #3
0
        /// <summary>
        ///  get the delay: TransmissionDelay + PropagationDelay;
        /// </summary>
        /// <param name="tx"></param>
        /// <param name="rc"></param>
        /// <returns></returns>
        public static double Delay(VehicleUi tx, VehicleUi rc)
        {
            double Distance = Computations.Distance(tx.InstanceLocation, rc.InstanceLocation);
            //https://en.wikipedia.org/wiki/Transmission_delay
            double TransmissionDelay = PublicParamerters.DataPacketLength / PublicParamerters.TransmissionRate;
            //https://en.wikipedia.org/wiki/Propagation_delay
            double PropagationDelay = Distance / PublicParamerters.SpeedOfLight;

            return(TransmissionDelay + PropagationDelay);
        }
コード例 #4
0
        /// <summary>
        /// check if the segment and the junction are overlapped. and check the oreintation of overlapping.
        /// </summary>
        /// <param name="jun"></param>
        /// <param name="rs"></param>
        public static void AreIntersected(Junction jun, RoadSegment rs)
        {
            double offset = -1;

            if (rs.Roadorientation == RoadOrientation.Vertical)
            {
                if (jun.Margin.Top >= rs.Margin.Top)
                {
                    double distance = offset + Computations.Distance(jun.BottomRightCorner, rs.BottomRightCorner);
                    if (distance < jun.Height)
                    {
                        jun.ToNorthRoadSegment         = rs;
                        jun.IncicdentRoadSegmentCount += 1;
                        jun.VerticalGreenValue        += 1;
                        rs.MyJunctions.Add(jun);
                        // return true;
                    }
                }
                else if (jun.Margin.Top < rs.Margin.Top)
                {
                    double distance = offset + Computations.Distance(jun.TopLeftCorner, rs.TopLeftCorner);
                    if (distance <= jun.Height)
                    {
                        jun.ToSouthRoadSegment         = rs;
                        jun.IncicdentRoadSegmentCount += 1;
                        jun.VerticalGreenValue        += 1;
                        rs.MyJunctions.Add(jun);
                        //  return true;
                    }
                }
            }
            else if (rs.Roadorientation == RoadOrientation.Horizontal)
            {
                if (jun.Margin.Left < rs.Margin.Left)
                {
                    double distance = offset + Computations.Distance(jun.TopLeftCorner, rs.TopLeftCorner);
                    if (distance <= jun.Width)
                    {
                        jun.ToEastRoadSegment          = rs;
                        jun.IncicdentRoadSegmentCount += 1;
                        jun.HorizontalGreenValue      += 1;
                        rs.MyJunctions.Add(jun);
                        // return true;
                    }
                }
                else if (jun.Margin.Left > rs.Margin.Left)
                {
                    double distance = offset + Computations.Distance(jun.TopRightCorner, rs.TopRightCorner);
                    if (distance <= jun.Width)
                    {
                        jun.ToWestRoadSegment          = rs;
                        jun.IncicdentRoadSegmentCount += 1;
                        jun.HorizontalGreenValue      += 1;
                        rs.MyJunctions.Add(jun);
                        // return true;
                    }
                }
            }

            //  return false;
        }