/// <summary> /// Get the candidates of the i. /// get the candidate for the jucntion i. /// An Inter-path is a sequence of road intersections that connect the source to the destination, satisfying two key requirements, shorter routing distances, and higher connectivity. To meet these two requirements, we developed a heuristic function with two probability distributions, the connectivity distribution (denoted by ξ ̃_(i,j)) and the shortest distance distribution (denoted by〖 Φ ̃〗_(i,j)). /// </summary> /// <param name="_i"></param> /// <returns></returns> public CandidateJunction CandidateJunction(Junction _i, Junction _des) { string protocol = Settings.Default.RoutingProtocolString; List <CandidateJunction> candidateJunctions = new List <Routing.CandidateJunction>(); ShortestDistanceSelector computer = new ShortestDistanceSelector(); SegmentConnectivitySelector connect = new SegmentConnectivitySelector(); // values: foreach (Junction _j in _i.Adjacentjunctions) { RoadSegment roadSegment = GetRoadSegment(_i, _j); if (roadSegment != null) { switch (protocol) { case "VEFR": { CandidateJunction can = new CandidateJunction(); can.CurrentJunction = _i; can.NextJunction = _j; can.NextJunction = _j; // CAN id. can.DestinationJunction = _des; can.NextRoadSegment = roadSegment; can.RSSInput = new RSSInput(); // new one. can.RSSInput.DensityCrisp = Settings.Default.WeightConnectivity * Crisps.Density(roadSegment.SegmentLength, roadSegment.VehiclesCount, Settings.Default.CommunicationRange, roadSegment.LanesCount); can.RSSInput.ValidDistanceCrisp = Settings.Default.WeightShortestDistance * Crisps.ValidDistance(_i.CenterLocation, _j.CenterLocation, _des.CenterLocation); can.Priority = RSSRuleBase.Aggregate(can.RSSInput); candidateJunctions.Add(can); if (Settings.Default.SaveJunctionsCrisp) { /// } if (_des.JID == _j.JID) { return(can); } } break; case "HERO": { CandidateJunction can = new Routing.CandidateJunction(); can.CurrentJunction = _i; can.NextJunction = _j; can.NextJunction = _j; // CAN id. can.DestinationJunction = _des; can.NextRoadSegment = roadSegment; // values: //1- shortes distance: can.Perpendiculardistance = computer.Perpendiculardistance(_j.CenterLocation, _i.CenterLocation, _des.CenterLocation); if (_des.JID == _j.JID) { can.AngleDotProdection = 1; } else { computer.AngleDotProdection(_i.CenterLocation, _j.CenterLocation, _des.CenterLocation); } can.Length = computer.Length(_i.CenterLocation, _j.CenterLocation); //-2 connectivity. can.Connectivity = connect.SegmentConnectivity(roadSegment.SegmentLength, roadSegment.VehiclesCount, roadSegment.VehicleInterArrivalMean, Settings.Default.CommunicationRange, roadSegment.LanesCount); candidateJunctions.Add(can); } break; } } } switch (protocol) { case "VEFR": { if (candidateJunctions.Count > 0) { CandidateJunction max = candidateJunctions[0]; for (int j = 1; j < candidateJunctions.Count; j++) { if (candidateJunctions[j].Priority > max.Priority) { max = candidateJunctions[j]; } } return(max); } } break; case "HERO": { // get the max priority. if (candidateJunctions.Count > 0) { CandidateJunction max = candidateJunctions[0]; for (int j = 1; j < candidateJunctions.Count; j++) { if (candidateJunctions[j].HeuristicFunction > max.HeuristicFunction) { max = candidateJunctions[j]; } } return(max); } } break; } return(null); }
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; } }