/// <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(); } } } } }
public static double GetDoubleValue(double min, double max) { double v = min + RandomeNumberGenerator.GetUniform() * (max - min); bool IsAntithetic = true; // check this. if (IsAntithetic) { return(min + (max - v)); } else { return(v); } }
/*--------------------Onboad unit--------------------------*/ #region Onboad unit /// <summary> /// select the the DestinationVehicle randomly. /// </summary> public void RandomDestinationVehicle() { Dispatcher.Invoke((Action) delegate { int max = CurrentLane._MainWindow.MyVehicles.Count; if (max >= 2) { int rand = Convert.ToInt16(RandomeNumberGenerator.GetUniform(max - 1)); if (rand != VID) { VehicleUi DestinationVehicle = CurrentLane._MainWindow.MyVehicles[rand]; GeneratePacket(DestinationVehicle); } } }); }
/*--------------------Moblity--------------------------*/ #region Moblity public void SetInstansSpeed(AccellerationType accellerationType) { if (accellerationType == AccellerationType.LimmitedToSegmementMaxSpeed) { // double instan = RandomeNumberGenerator.GetUniform(Settings.Default.MaxSpeed, Settings.Default.MinSpeed); InstantaneousSpeed = Computations.RandomTimeInterval(CurrentLane.MyRoadSegment); // this according to the lane // InstantaneousSpeed = UnitsConverter.KmphToTimerInterval(instan); } else if (accellerationType == AccellerationType.RandomSpeed) { // double rand = RandomeNumberGenerator.GetNormal(Settings.Default.MaxSpeed, PublicParamerters.SpeedStandardDeviation); double instan = RandomeNumberGenerator.GetUniform(Settings.Default.MaxSpeed, Settings.Default.MinSpeed); InstantaneousSpeed = UnitsConverter.KmphToTimerInterval(instan); } else if (accellerationType == AccellerationType.NormalDistrubution) { // double rand = RandomeNumberGenerator.GetNormal(Settings.Default.MaxSpeed, PublicParamerters.SpeedStandardDeviation); double instan = RandomeNumberGenerator.GetNormal((Settings.Default.MaxSpeed + Settings.Default.MaxSpeed) / 2, PublicParamerters.SpeedStandardDeviation); InstantaneousSpeed = UnitsConverter.KmphToTimerInterval(instan); } }
public static double GetUniformSleepSec(double max) { Thread.Sleep(TimeSpan.FromMilliseconds(1)); return(max * RandomeNumberGenerator.GetUniform()); }
public static double GetUniform(double max) { return(max * RandomeNumberGenerator.GetUniform()); }
private static double RdmGenerator(double max) { return(max * RandomeNumberGenerator.GetUniform()); }
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; } }