示例#1
0
        private void getSinkInterval()
        {
            int    MaxSinkSpeed = Settings.Default.SinkSpeed;
            double speedInKmph  = RandomeNumberGenerator.uniformMaxSpeed(MaxSinkSpeed);

            sinkInterval = Operations.kmphToTimerInterval(speedInKmph);
            if (sinkInterval > 0)
            {
                timer_move.Interval = TimeSpan.FromSeconds(sinkInterval);
            }
        }
示例#2
0
            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);
                }
            }
示例#3
0
        //start moving the sink here

        //Changes the interval between each one pixel move of the sink

        public void startMoving()
        {
            RandomeNumberGenerator.SetSeedFromSystemTime();

            timer_changeInter.Interval = TimeSpan.FromSeconds(3);
            timer_changeInter.Start();
            timer_changeInter.Tick += timer_tick_speed;
            //Moves the sink according to its speed and direction
            timer_move.Interval = TimeSpan.FromSeconds(0.5);
            timer_move.Start();
            timer_move.Tick += timer_tick_move;
            //Changes the direction of the sink
            timer_changeDir.Interval = TimeSpan.FromSeconds(2);
            timer_changeDir.Start();
            timer_changeDir.Tick += timer_tick_direction;
        }
示例#4
0
        /*--------------------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);
                    }
                }
            });
        }
示例#5
0
 /*--------------------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);
     }
 }
示例#6
0
 public void startMoving()
 {
     RandomeNumberGenerator.SetSeedFromSystemTime();
     myNearCluster = getNearestCluster();
     sinkDirection = GetUniformDirection();
     PastDirections.Push(sinkDirection);
     if (Settings.Default.SinkSpeed > 0)
     {
         timer_changeInter.Interval = TimeSpan.FromSeconds(3);
         timer_changeInter.Start();
         timer_changeInter.Tick += timer_tick_speed;
         //Moves the sink according to its speed and direction
         timer_move.Interval = TimeSpan.FromSeconds(0.5);
         timer_move.Start();
         timer_move.Tick += timer_tick_move;
         //Changes the direction of the sink
         timer_checkSinkGoingOut.Interval = TimeSpan.FromSeconds(1);
         timer_checkSinkGoingOut.Tick    += timer_tick_direction;
         timer_checkSinkGoingOut.Start();
         timer_getNewDirection.Interval = TimeSpan.FromSeconds(getDirectionInterval());
         timer_getNewDirection.Tick    += timer_getNewDirection_Tick;
         timer_getNewDirection.Start();
     }
 }
示例#7
0
 public static double GetUniformSleepSec(double max)
 {
     Thread.Sleep(TimeSpan.FromMilliseconds(1));
     return(max * RandomeNumberGenerator.GetUniform());
 }
示例#8
0
 public static double GetUniform(double max)
 {
     return(max * RandomeNumberGenerator.GetUniform());
 }
示例#9
0
 private static double RdmGenerator(double max)
 {
     return(max * RandomeNumberGenerator.GetUniform());
 }
示例#10
0
 private void changeDirection()
 {
     sinkAngle     = RandomeNumberGenerator.uniformMaxDirection(directionMean);
     sinkDirection = Operations.ConvertAngleToDirection(sinkAngle);
     changeDirectionMean();
 }
示例#11
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;
            }
        }
示例#12
0
        private void checkTheNewDirection()
        {
            bool didChange = false;
            int  dir;
            int  counter            = 0;
            bool CheckTwoDirections = (PastDirections.Count > 1);
            int  currentDirection   = 0;

            if (PastDirections.Count > 1)
            {
                currentDirection = PastDirections.Pop();
            }
            else
            {
                currentDirection = sinkDirection;
            }
            int oldDirection = 0;

            if (CheckTwoDirections)
            {
                oldDirection = PastDirections.Pop();
            }
            do
            {
                counter++;
                sinkAngle = RandomeNumberGenerator.uniformMaxDirection(directionMean);
                //sinkDirection = Operations.ConvertAngleToDirection(sinkAngle);
                dir = Operations.ConvertAngleToDirection(sinkAngle);


                if (dir % 2 == 0)
                {
                    if ((dir - 1) != sinkDirection)
                    {
                        if (CheckTwoDirections)
                        {
                            if ((dir - 1) != oldDirection)
                            {
                                sinkDirection = dir;
                                didChange     = true;
                            }
                        }
                        else
                        {
                            sinkDirection = dir;
                            didChange     = true;
                        }
                    }
                }
                else if ((dir + 1) != sinkDirection)
                {
                    if (CheckTwoDirections)
                    {
                        if ((dir + 1) != oldSinkDirection)
                        {
                            didChange     = true;
                            sinkDirection = dir;
                        }
                    }
                    else
                    {
                        didChange     = true;
                        sinkDirection = dir;
                    }
                }
            } while ((!didChange) && counter < 3);
            PastDirections.Push(currentDirection);
            if (didChange)
            {
                //  int hold = PastDirections[(PastDirections.Count-1)];
                PastDirections.Clear();
                PastDirections.Push(currentDirection);
                PastDirections.Push(sinkDirection);

                switch (dir)
                {
                case 1:
                    directionMean = 360;
                    break;

                case 2:
                    directionMean = 180;
                    break;

                case 3:
                    directionMean = 90;
                    break;

                case 4:
                    directionMean = 270;
                    break;

                case 5:
                    directionMean = 45;
                    break;

                case 6:
                    directionMean = 225;
                    break;

                case 7:
                    directionMean = 135;
                    break;

                case 8:
                    directionMean = 315;
                    break;

                case 0:
                    directionMean = 0;
                    break;

                default:
                    break;
                }
            }
        }
示例#13
0
 public static double GetValue(double m_mean, double m_variance)
 {
     return(RandomeNumberGenerator.GetNormal(m_mean, m_variance));
 }