コード例 #1
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
        /// <summary>
        /// remove the head.
        /// </summary>
        /// <returns></returns>
        public VehicleUi Dequeue()
        {
            if (Queue.Count > 0)
            {
                if (Queue[0] != null)
                {
                    VehicleUi re = Queue[0];
                    re.lbl_show_info.Foreground = System.Windows.Media.Brushes.Black;
                    LaneUi ulane = re.CurrentLane;

                    RemoveFromLane(re); // from the lane
                    Queue.Remove(re);   // from the queue.
                    List <VehicleUi> back = new List <VehicleUi>();
                    back.AddRange(Queue);
                    Queue.Clear();
                    foreach (VehicleUi ve in back)
                    {
                        Enqueue(ve);
                    }
                    ulane._MainWindow.Dispatcher.Invoke(new Action(() => ulane.lbl_info.Text = ulane.LaneVehicleAndQueue.CountInLane.ToString()), DispatcherPriority.Send);
                    return(re);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
コード例 #2
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);
            });
        }
コード例 #3
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);
                            }
                        }
                    }
                });
            }
        }
コード例 #4
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
        /// <summary>
        /// vehicles which are in the front of me.
        /// </summary>
        /// <param name="Currentvehi"></param>
        /// <returns></returns>
        public void GetIntraNeighborOneWayInfront(VehicleUi Currentvehi)
        {
            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)
                {
                    if (Currentvehi.VehicleDirection == lane.LaneDirection)
                    {
                        allInSameDirection.AddRange(lane.LaneVehicleAndQueue.LaneVechilesList);
                    }
                }

                foreach (VehicleUi fronV in allInSameDirection)
                {
                    if (fronV != Currentvehi)
                    {
                        double traveledDiffrence = fronV.TravelledDistanceInMeter - Currentvehi.TravelledDistanceInMeter;
                        if (traveledDiffrence < Settings.Default.CommunicationRange)
                        {
                            if ((traveledDiffrence > 0) && (traveledDiffrence <= (Currentvehi.Height * 2))) // increase the distance between the vechiles when line up.
                            {
                                Currentvehi.Intra_Neighbores.Add(fronV);
                            }
                        }
                    }
                }
            });
        }
コード例 #5
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
 public List <VehicleUi> LaneVechilesList = new List <VehicleUi>(); // vechile that on the lane right now.
 /// <summary>
 /// add to the lane.
 /// </summary>
 /// <param name="v"></param>
 public void AddToLane(VehicleUi v)
 {
     if (!LaneVechilesList.Contains(v))
     {
         LaneVechilesList.Add(v);
     }
 }
コード例 #6
0
ファイル: MainWindow.xaml.cs プロジェクト: howbani/VSIM
        /// <summary>
        /// select the source vehicle randomly.
        /// </summary>
        public void RandomlySourceVechicle(bool isDistance, double distance)
        {
            // select random vehicle:
            if (Settings.Default.IsIntialized)
            {
                if (MyVehicles.Count > 0)
                {
                    // select the source:

                    int max = MyVehicles.Count;
                    if (max >= 2)
                    {
                        // consider the distance
                        if (isDistance)
                        {
                            int       rand = Convert.ToInt16(RandomeNumberGenerator.GetUniform(max - 1));
                            VehicleUi src  = MyVehicles[rand];
                            VehicleUi des  = GetDestinationWithinAdistance(src, distance);
                            if (des != null)
                            {
                                src.GeneratePacket(des);
                            }
                        }
                        else
                        {
                            int rand = Convert.ToInt16(RandomeNumberGenerator.GetUniform(max - 1));
                            MyVehicles[rand].RandomDestinationVehicle();
                        }
                    }
                }
            }
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
 /// <summary>
 /// add to the tail.
 /// </summary>
 /// <param name="veh"></param>
 public void Enqueue(VehicleUi veh)
 {
     veh.Dispatcher.Invoke((Action) delegate
     {
         if (!Queue.Contains(veh))
         {
             Queue.Add(veh);
             veh.IndexInQueue             = Queue.Count;
             veh.lbl_show_info.Foreground = System.Windows.Media.Brushes.OrangeRed;
         }
     });
 }
コード例 #9
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
 /// <summary>
 /// retuen the ve that very close to me.
 /// inputVe should be infront of outVE.
 /// </summary>
 /// <returns></returns>
 public VehicleUi GetMyFrontVehicle(VehicleUi Currentvehi)
 {
     foreach (VehicleUi fronV in Currentvehi.CurrentLane.LaneVehicleAndQueue.LaneVechilesList)
     {
         if (fronV != Currentvehi)
         {
             double traveledDiffrence = fronV.TravelledDistanceInMeter - Currentvehi.TravelledDistanceInMeter;
             if ((traveledDiffrence > 0) && (traveledDiffrence <= (Currentvehi.Height * 1.3))) // increase the distance between the vechiles when line up.
             {
                 return(fronV);
             }
         }
     }
     return(null);
 }
コード例 #10
0
ファイル: MainWindow.xaml.cs プロジェクト: howbani/VSIM
        public VehicleUi GetDestinationWithinAdistance(VehicleUi src, double dis)
        {
            foreach (VehicleUi des in MyVehicles)
            {
                double accualdistance   = Computations.Distance(src.InstanceLocation, des.InstanceLocation);
                double thesould         = 2 * Math.Sqrt(dis);
                double uper_tollerance  = dis + thesould;
                double lower_tollerance = dis - thesould;
                if (accualdistance >= lower_tollerance && accualdistance <= uper_tollerance)
                {
                    return(des);
                }
            }

            return(null);
        }
コード例 #11
0
ファイル: LaneQueue.cs プロジェクト: howbani/VSIM
 /// <summary>
 /// remove from the lane
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public bool RemoveFromLane(VehicleUi v)
 {
     return(LaneVechilesList.Remove(v));
 }
コード例 #12
0
ファイル: IntraRouting.cs プロジェクト: fissehateju/VEFR
        /// <summary>
        /// isRouted= true when both the sender and the dest vechiles are in the same segment.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="MyroadSegment"></param>
        /// <returns></returns>
        public CandidateVehicle GetCandidateVehicleUis(VehicleUi i, List <VehicleUi> NodesList, VehicleUi desVehicle, bool isRouted)
        {
            string protocol = Settings.Default.RoutingProtocolString;
            List <CandidateVehicle> candidates = new List <CandidateVehicle>();
            List <CandidateVehicle> neighbors  = new List <CandidateVehicle>();

            double sum = 0;

            if (NodesList.Count > 0)
            {
                foreach (VehicleUi j in NodesList)
                {
                    if (isRouted)
                    {
                        switch (protocol)
                        {
                        case "VEFR":
                        {
                            // des and sender vehicles both are in the same raod segment.
                            CandidateVehicle jcan = new CandidateVehicle();
                            jcan.SVID            = i.VID;
                            jcan.SelectedVehicle = j;
                            jcan.RVSInput        = new RVSInput();
                            if (Settings.Default.SaveVehiclesCrisp)
                            {
                                jcan.RVSInput.ID                     = PublicParamerters.sessionID;
                                jcan.RVSInput.DesVehlocation         = desVehicle.InstanceLocation;
                                jcan.RVSInput.CurrentVehlocation     = i.InstanceLocation;
                                jcan.RVSInput.CandidateVehlocation   = j.InstanceLocation;
                                jcan.RVSInput.CurrentVehSpeedInKMH   = i.GetSpeedInKMH;
                                jcan.RVSInput.CandidateVehSpeedInKMH = j.GetSpeedInKMH;
                                PublicParamerters.RVSInputList.Add(jcan.RVSInput);         // print.. this can be removed
                            }

                            jcan.RVSInput.MovingDirectionCrisp      = Crisps.MovingDirection(i.InstanceLocation, j.InstanceLocation, desVehicle.InstanceLocation);
                            jcan.RVSInput.SpeedDifferenceCrisp      = Crisps.SpeedDifference(i.GetSpeedInKMH, j.GetSpeedInKMH, Settings.Default.MaxSpeed);     // make sure of this i.GetSpeedInKMH
                            jcan.RVSInput.TransmissionDistanceCrisp = Crisps.TransmissionDistance(i.InstanceLocation, j.InstanceLocation, Settings.Default.CommunicationRange);
                            jcan.Priority = jcan.RVSInput.Priority;
                            sum          += jcan.Priority;

                            neighbors.Add(jcan);

                            if (j == desVehicle)
                            {
                                return(jcan);
                            }
                        }
                        break;

                        case "HERO":
                        {
                            // des and sender vehicles both are in the same raod segment.
                            CandidateVehicle jcan = new CandidateVehicle();
                            jcan.SVID                        = i.VID;
                            jcan.SelectedVehicle             = j;
                            jcan.BufferSizeDistribution      = BufferSizeDistribution(j.PacketQueue.Count, PublicParamerters.BufferSize);
                            jcan.SignalFadingDistribution    = SignalFadingDistribution(Computations.Distance(i.InstanceLocation, j.InstanceLocation), Settings.Default.CommunicationRange);
                            jcan.SpeedDifferenceDistribution = SpeedDifferenceDistribution(i.GetSpeedInKMH, j.GetSpeedInKMH, roadSegment.MaxAllowedSpeed);
                            jcan.MovingDirection             = MovingDirectionDis(i.InstanceLocation, j.InstanceLocation, desVehicle.InstanceLocation);

                            sum += jcan.HeursticFunction;
                            neighbors.Add(jcan);
                            if (j == desVehicle)
                            {
                                return(jcan);
                            }
                        }
                        break;
                        }
                    }
                    else
                    {
                        // not in the same segment:
                        switch (protocol)
                        {
                        case "VEFR":
                        {
                            CandidateVehicle jcan = new CandidateVehicle();
                            jcan.SVID            = i.VID;
                            jcan.SelectedVehicle = j;
                            jcan.RVSInput        = new RVSInput();

                            if (Settings.Default.SaveVehiclesCrisp)
                            {
                                jcan.RVSInput.ID                     = PublicParamerters.sessionID;
                                jcan.RVSInput.DesVehlocation         = desVehicle.InstanceLocation;
                                jcan.RVSInput.CurrentVehlocation     = i.InstanceLocation;
                                jcan.RVSInput.CandidateVehlocation   = j.InstanceLocation;
                                jcan.RVSInput.CurrentVehSpeedInKMH   = i.GetSpeedInKMH;
                                jcan.RVSInput.CandidateVehSpeedInKMH = j.GetSpeedInKMH;
                                PublicParamerters.RVSInputList.Add(jcan.RVSInput);         // print.. this can be removed
                            }

                            jcan.RVSInput.MovingDirectionCrisp      = Crisps.MovingDirection(i.InstanceLocation, j.InstanceLocation, desVehicle.EndJunction.CenterLocation); // make sure of this.                                                                                                                                               //  {
                            jcan.RVSInput.SpeedDifferenceCrisp      = Crisps.SpeedDifference(i.GetSpeedInKMH, j.GetSpeedInKMH, Settings.Default.MaxSpeed);                   // make sure of this i.GetSpeedInKMH
                            jcan.RVSInput.TransmissionDistanceCrisp = Crisps.TransmissionDistance(i.InstanceLocation, j.InstanceLocation, Settings.Default.CommunicationRange);
                            jcan.Priority = jcan.RVSInput.Priority;
                            sum          += jcan.RVSInput.Priority;

                            neighbors.Add(jcan);
                        }
                        break;

                        case "HERO":
                        {
                            // not in the same segment:
                            CandidateVehicle jcan = new CandidateVehicle();
                            jcan.SVID                        = i.VID;
                            jcan.SelectedVehicle             = j;
                            jcan.BufferSizeDistribution      = BufferSizeDistribution(j.PacketQueue.Count, PublicParamerters.BufferSize);
                            jcan.SignalFadingDistribution    = SignalFadingDistribution(Computations.Distance(i.InstanceLocation, j.InstanceLocation), Settings.Default.CommunicationRange);
                            jcan.SpeedDifferenceDistribution = SpeedDifferenceDistribution(i.GetSpeedInKMH, j.GetSpeedInKMH, roadSegment.MaxAllowedSpeed);
                            jcan.MovingDirection             = MovingDirectionDis(i.InstanceLocation, j.InstanceLocation, desVehicle.EndJunction.CenterLocation);

                            sum += jcan.HeursticFunction;
                            neighbors.Add(jcan);
                        }
                        break;
                        }
                    }
                }



                switch (protocol)
                {
                case "VEFR":
                {
                    if (neighbors.Count > 0)
                    {
                        // get max:
                        CandidateVehicle max = neighbors[0];
                        if (max != null)
                        {
                            for (int j = 1; j < neighbors.Count; j++)
                            {
                                if (neighbors[j].Priority > max.Priority)
                                {
                                    max = neighbors[j];
                                }
                            }
                            return(max);
                        }
                    }
                }
                break;

                case "HERO":
                {
                    if (neighbors.Count > 0)
                    {
                        double average             = (1 / Convert.ToDouble((neighbors.Count)));
                        double Priority_threshould = average;
                        foreach (CandidateVehicle jcan in neighbors)
                        {
                            double x = jcan.HeursticFunction / sum;
                            jcan.Priority = x;
                            if (jcan.Priority >= Priority_threshould)
                            {
                                candidates.Add(jcan);
                            }
                        }

                        // get max:
                        if (candidates.Count == 0)
                        {
                            return(null);
                        }
                        else if (candidates.Count == 1)
                        {
                            return(candidates[0]);
                        }
                        else
                        {
                            // get max:
                            CandidateVehicle max = candidates[0];
                            if (max != null)
                            {
                                for (int j = 1; j < candidates.Count; j++)
                                {
                                    if (candidates[j].Priority > max.Priority)
                                    {
                                        max = candidates[j];
                                    }
                                }
                                return(max);
                            }
                        }
                    }
                }
                break;
                }
            }
            return(null);
        }