Beispiel #1
0
        /// <summary>
        /// generate data packet from this vechile to the TargetVehicle.
        /// </summary>
        /// <param name="DestinationVehicle"></param>
        public void GeneratePacket(VehicleUi DestinationVehicle)
        {
            Dispatcher.Invoke((Action) delegate
            {
                Packet packet = new Packet();

                packet.Type = PacketType.Data;
                PublicStatistics.GeneratedPacketsCount += 1;
                packet.PID          = PublicStatistics.GeneratedPacketsCount;
                packet.PacketLength = PublicParamerters.DataPacketLength;

                packet.TravelledRoadSegmentString += CurrentLane.MyRoadSegment.RID; // add the first rs.
                packet.VehiclesString             += VID;                           // start by current sender.
                packet.SRID = CurrentLane.MyRoadSegment.RID;
                // set source and distination:
                packet.SourceVehicle      = this;
                packet.DestinationVehicle = DestinationVehicle;
                packet.Direction          = DestinationVehicle.CurrentLane.LaneDirection;
                packet.CurrentRoadSegment = CurrentLane.MyRoadSegment;                                                   // the segment of the vechile.

                packet.EuclideanDistance = Computations.Distance(InstanceLocation, DestinationVehicle.InstanceLocation); // the intial distance
                packet.RoutingDistance   = packet.EuclideanDistance;
                packet.SVID = VID;
                packet.DVID = DestinationVehicle.VID;

                this.SetNotationSign(NotationsSign.HasPacket);
                DestinationVehicle.SetNotationSign(NotationsSign.Destination);
                DestinationVehicle.WaitingPacketsIDsList.Add(packet.PID); // flage

                // start count the delay.
                PacketQueue.Enqueue(packet);                                                                  // add the packet to the queue.
                PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after...
                PacketQueueTimer.Start();                                                                     // start the timer.
            });
        }
Beispiel #2
0
        /// <summary>
        /// Perpendicular distance distribution ψ ̃_(i,j) allocates higher probability for the junctions that are closer to the central line  l_(s,b)(i.e., a virtual line linking the source junction v_s and the destination v_b). See Fig.2. The perpendicular distance ψ_j from the node 〖 v〗_j to the line l_(s,b) is defined by Eq. (18).  For the source junction〖 v〗_i, we define the normalized perpendicular-distance random variable ψ ̅_i=(ψ ̅_(i,1),ψ ̅_(i,3),…ψ ̅_(i,b_i ) )  by Eq. (19). Furthermore, we define the perpendicular-distance probability distribution, denoted by ψ ̃_i=(ψ ̃_(i,1),ψ ̃_(i,2)…ψ ̃_(i,b_i ) ), by Eq. (20).
        /// </summary>
        /// <param name="j"></param>
        /// <param name="s"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public double Perpendiculardistance(Point pj, Point psource, Point pdistanction)
        {
            double past   = Math.Abs(((pdistanction.Y - psource.Y) * pj.X) - ((pdistanction.X - psource.X) * pj.Y) + (pdistanction.X * psource.Y) - (pdistanction.Y * psource.X));
            double sbDis  = Computations.Distance(psource, pdistanction);
            double perDis = past / sbDis;

            // dist: if there is a mistake, then we should consider the normalization.
            double pr = Math.Exp(-perDis);

            return(pr);
        }
Beispiel #3
0
        /// <summary>
        /// x=√((x ̌_j-x ̌_i )^2+(y ̌_j-y ̌_i )^2 )⁄δ
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="comrange"></param>
        /// <returns></returns>
        public static double TransmissionDistance(Point i, Point j, double comrange)
        {
            double dis = Computations.Distance(i, j);

            if (dis <= comrange)
            {
                return(dis / comrange);
            }
            else
            {
                return(1);
            }
        }
Beispiel #4
0
        /// <summary>
        /// get the junction when the packet is justc generated.
        /// </summary>
        /// <returns></returns>
        public Junction GetIntializedJunction(Packet packet)
        {
            Junction desveheadingJunct = packet.DestinationJunction;
            double   disToStartJun     = Computations.Distance(desveheadingJunct.CenterLocation, StartJunction.CenterLocation);
            double   disToEndJun       = Computations.Distance(desveheadingJunct.CenterLocation, EndJunction.CenterLocation);

            if (disToStartJun > disToEndJun)
            {
                return(EndJunction);
            }
            else
            {
                return(StartJunction);
            }
        }
Beispiel #5
0
        /// <summary>
        ///  is in the front
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="d">destination</param>
        /// <returns></returns>
        public static double MovingDirection(Point i, Point j, Point d)
        {
            double axb      = ((j.X - i.X) * (d.X - i.X)) + ((j.Y - i.Y) * (d.Y - i.Y));
            double disMul   = Computations.Distance(i, d) * Computations.Distance(i, j);
            double angale   = Math.Acos(axb / disMul);
            double norAngle = angale / Math.PI;

            if (norAngle <= 0.5)
            {
                return(norAngle);
            }
            else
            {
                return(1);
            }
        }
Beispiel #6
0
        /// <summary>
        /// d should be the heading distance of v.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        private static double AngleDotProdection(Point i, Point j, Point d)
        {
            double axb      = ((j.X - i.X) * (d.X - i.X)) + ((j.Y - i.Y) * (d.Y - i.Y));
            double disMul   = Computations.Distance(i, d) * Computations.Distance(i, j);
            double angale   = Math.Acos(axb / disMul);
            double norAngle = angale / Math.PI;

            if (norAngle <= 0.5)
            {
                return(norAngle);
            }
            else
            {
                return(1); // behind.
            }
        }
Beispiel #7
0
        /// <summary>
        /// Direction Angle: The direction angle θ_(i,j)between the junction v_i  and the potential forwarder v_j towards the destination junction v_b  is modeled as a dot production of two vectors a ⃗.c ⃗, such that a ⃗=(x_j-x_i,y_j-y_i ) and  c ⃗=(x_b-x_i,y_b-y_i )  and normalized to π  by Eq. (16). The normalized-direction θ ̅_i=(θ ̅_(i,1),θ ̅_(i,2),…θ ̅_(i,b_i )) are injected to the mass function Eq. (17) to obtain the random variable (θ_i ) ̃=(θ ̃_(i,1),θ ̃_(i,2)…θ ̃_(i,b_i ) ). Direction distribution assigns higher probability for the normalized angles 0≤θ ̅_(i,j)≤1/2 that ensure higher routing progress.
        /// </summary>
        /// <param name="isender"></param>
        /// <param name="jcandidate"></param>
        /// <param name="bDestination"></param>
        /// <returns></returns>

        public double AngleDotProdection(Point i, Point j, Point d)
        {
            double axb      = (j.X - i.X) * (d.X - i.X) + (j.Y - i.Y) * (d.Y - i.Y);
            double disMul   = Computations.Distance(i, d) * Computations.Distance(i, j);
            double angale   = Math.Acos(axb / disMul);
            double norAngle = angale / Math.PI;

            if (norAngle <= 0.5)
            {
                return(Math.Pow(((1 - (norAngle * Math.Exp(norAngle))) / (1 + (norAngle * Math.Exp(norAngle)))), 1));  // heigher pri
            }
            else
            {
                return(Math.Pow(((1 - (norAngle * Math.Exp(norAngle))) / (1 + (norAngle * Math.Exp(norAngle)))), 3));  // smaller pri
            }
        }
Beispiel #8
0
 /// <summary>
 /// forward the packet to the NEXT
 /// </summary>
 /// <param name="packet"></param>
 /// <param name="next"></param>
 public void RelayPacket(Packet packet, VehicleUi next)
 {
     Dispatcher.Invoke((Action) delegate
     {
         packet.PathWaitingTimes += packet.HopWaitingTimes; // save the path waiting time and clear the hop.
         packet.HopWaitingTimes   = 0;                      // re-intilize the hop-waiting.
         packet.PropagationAndTransmissionDelay += DelayModel.Delay(this, next);
         packet.HopsVehicles    += 1;
         packet.RoutingDistance += Computations.Distance(InstanceLocation, next.InstanceLocation);
         packet.VehiclesString  += "-" + next.VID;
         next.RecievePacket(packet);
         PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after...
         next.SetNotationSign(NotationsSign.HasPacket);
         SetNotationSign(NotationsSign.HasNoPacket);
     });
 }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        /// <summary>
        ///  the instance location of the the three vechiles. sender , next hop and the destination.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        private double MovingDirectionDis(Point i, Point j, Point d)
        {
            double axb      = (j.X - i.X) * (d.X - i.X) + (j.Y - i.Y) * (d.Y - i.Y);
            double disMul   = Computations.Distance(i, d) * Computations.Distance(i, j);
            double angale   = Math.Acos(axb / disMul);
            double norAngle = angale / Math.PI;

            if (norAngle <= 0.5)
            {
                // smaller angle means closer to the destination.
                double bast   = norAngle * Math.Exp(norAngle);
                double mak    = 1 + (norAngle * Math.Exp(norAngle));
                double mikdar = bast / mak;
                double re     = Math.Pow(1 - mikdar, Settings.Default.IntraVehiForwardDirectionPar); // smaller IntraVehiForwardDirectionPar value means heigher pri for the forward dir

                return(re);
            }
            else
            {
                return(Math.Pow(((1 - (norAngle * Math.Exp(norAngle))) / (1 + (norAngle * Math.Exp(norAngle)))), Settings.Default.IntraVehiBackwardDirectionPar));   // heigher IntraVehiBackwardDirectionPar smaller prioiry for the node which not in the direction.
            }
        }
Beispiel #11
0
 /// <summary>
 /// Givvs heigher priorit to the shortest.
 /// Road Segment Length: This distribution allocates higher probability to the longer segment. Longer segments are more preferable to avoid frequent segment switching that leads to delay the packet.  For the source junction〖 v〗_i, we define the normalized segment length random variable L ̅_i=(L ̅_(i,1),L ̅_(i,3),…L ̅_(i,b_i ) )  by Eq. (21). Furthermore, we define the segment length probability distribution, denoted by L ̃_i=(L ̃_(i,1),L ̃_(i,2)…L ̃_(i,b_i ) ), by the mass function as formulated in Eq. (22).
 /// </summary>
 /// <param name="i"></param>
 /// <param name="j"></param>
 /// <returns></returns>
 public static double Length(Point i, Point j)
 {
     return(1 - (1 / Math.Log10(Computations.Distance(i, j))));
 }
Beispiel #12
0
        /// <summary>
        /// Road Segment Length: This distribution allocates higher probability to the longer segment. Longer segments are more preferable to avoid frequent segment switching that leads to delay the packet.  For the source junction〖 v〗_i, we define the normalized segment length random variable L ̅_i=(L ̅_(i,1),L ̅_(i,3),…L ̅_(i,b_i ) )  by Eq. (21). Furthermore, we define the segment length probability distribution, denoted by L ̃_i=(L ̃_(i,1),L ̃_(i,2)…L ̃_(i,b_i ) ), by the mass function as formulated in Eq. (22).
        /// </summary>
        /// <param name="i"></param>
        /// <param name="j"></param>
        /// <returns></returns>
        public double Length(Point i, Point j)
        {
            double len = Computations.Distance(i, j);

            return(1 - Math.Sqrt(Math.Exp(-len)));
        }
Beispiel #13
0
        /// <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);
        }