Пример #1
0
        private void Combo_crisp_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string var = (combo_crisp.SelectedItem as ComboBoxItem).Content.ToString();

            if (var == "Density")
            {
            }
            else if (var == "Valid Distance")
            {
                List <ValidDistanceRow> List = new List <ValidDistanceRow>();
                Point dloc = new Point(100, 100);
                for (int j = 0; j <= 50; j++)
                {
                    Point  iloc   = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100));
                    Point  jloc   = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100));
                    double _Crisp = Crisps.ValidDistance(iloc, jloc, dloc);
                    List.Add(new ValidDistanceRow()
                    {
                        Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc, dloc = dloc
                    });
                }
                dg.ItemsSource = List;
            }
            else if (var == "Transmission Distance")
            {
                List <TransmissionDistanceRow> List = new List <TransmissionDistanceRow>();

                double comrange = 100;
                for (int j = 0; j <= 1000; j++)
                {
                    Point  iloc   = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100));
                    Point  jloc   = new Point(RandomeNumberGenerator.GetUniform(0, 100), RandomeNumberGenerator.GetUniform(0, 100));
                    double _Crisp = Crisps.TransmissionDistance(iloc, jloc, comrange);

                    List.Add(new TransmissionDistanceRow()
                    {
                        Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc
                    });
                }
                dg.ItemsSource = List;
            }
            else if (var == "Speed Difference")
            {
                List <SpeedDifferenceRow> List = new List <SpeedDifferenceRow>();
                double maxSpeed = 100;
                double si       = 5;
                for (int j = 0; j <= 1000; j++)
                {
                    double sj     = RandomeNumberGenerator.GetUniform(0, 100);
                    double _Crisp = Crisps.SpeedDifference(si, sj, maxSpeed);
                    List.Add(new SpeedDifferenceRow()
                    {
                        ID = j, Si = si, Sj = sj, Crisp = _Crisp
                    });
                }

                dg.ItemsSource = List;
            }
            else if (var == "Moving Direction")
            {
                List <MovingDirectionRow> List = new List <MovingDirectionRow>();
                Point dloc = new Point(100, 100);
                for (int j = 0; j <= 1000; j++)
                {
                    Point  iloc   = new Point(RandomeNumberGenerator.GetUniform(0, 500), RandomeNumberGenerator.GetUniform(0, 500));
                    Point  jloc   = new Point(RandomeNumberGenerator.GetUniform(0, 500), RandomeNumberGenerator.GetUniform(0, 500));
                    double _Crisp = Crisps.MovingDirection(iloc, jloc, dloc);
                    List.Add(new MovingDirectionRow()
                    {
                        Crisp = _Crisp, ID = j, iloc = iloc, jloc = jloc, dloc = dloc
                    });
                }
                dg.ItemsSource = List;
            }
        }
Пример #2
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);
        }