Пример #1
0
        private Func <double> CreateRandomFunc()
        {
            var random = this.ConfigObject.Seed == 0 ? DefaultRandom.Value : new Random(this.ConfigObject.Seed);

            switch (this.ConfigObject.Distribution)
            {
            case RandomNumberDistribution.Triangular:
                return(() => this.TriangularNumber(random.NextDouble()));

            case RandomNumberDistribution.Normal:
                var normal = new Normal(this.ConfigObject.Average, this.ConfigObject.StandardDeviation, random);
                return(() => normal.Sample());

            case RandomNumberDistribution.LogNormal:
                var logNormal = new LogNormal(
                    this.ConfigObject.Average,
                    this.ConfigObject.StandardDeviation,
                    random);
                return(() => logNormal.Sample());

            case RandomNumberDistribution.Uniform:
                return(() => random.NextDouble() * (this.ConfigObject.Maximum - this.ConfigObject.Minimum)
                       + this.ConfigObject.Minimum);
            }

            return(() => double.NaN);
        }
Пример #2
0
        internal override void GenerateCurve()
        {
            //create the senseCurve, the start of the curve and start populating it with random values
            List <SensitivityPoint> sensCurve  = new List <SensitivityPoint>();
            SensitivityPoint        firstPoint = new SensitivityPoint(0, sensMean);

            sensCurve.Add(firstPoint);
            //Random rnd = SystemRandomSource.Default;
            var logNormal = new LogNormal(0, sigma);

            for (double timecode = curveTimestep; timecode < this.lenght; timecode += curveTimestep)
            {
                double randomSens;
                do //keep trying to create a random sens within the set min/max boundries
                {
                    randomSens = logNormal.Sample();
                } while (randomSens > sensMax || randomSens < sensMin);
                SensitivityPoint sensPoint = new SensitivityPoint(timecode, randomSens);
                sensCurve.Add(sensPoint);
            }
            SensitivityPoint finalSensPoint = new SensitivityPoint(this.lenght, 1);//Make sure the curve ends at base sens

            sensCurve.Add(finalSensPoint);
            base.sensCurve = sensCurve;
        }
Пример #3
0
        /// <summary>
        /// Returns LogNormal-distributed worktime.
        /// </summary>
        /// <param name="duration"></param>
        /// <returns></returns>
        public long GetRandomWorkTime(long duration)
        {
            long newDuration;

            while (true)
            {
                newDuration = (long)Math.Round(value: duration * _distribution.Sample(), mode: MidpointRounding.AwayFromZero);
                if (newDuration <= 3 * duration)
                {
                    break;
                }
            }
            return(newDuration > 1 ? newDuration : 1);
        }
Пример #4
0
        /// <summary>
        /// Returns LogNormal-distributed worktime.
        /// </summary>
        /// <param name="duration"></param>
        /// <returns></returns>
        public int GetRandomWorkTime(int duration)
        {
            int newDuration;

            while (true)
            {
                newDuration = (int)Math.Round(duration * _distribution.Sample(), MidpointRounding.AwayFromZero);
                if (newDuration <= 3 * duration)
                {
                    break;
                }
            }
            if (duration != newDuration)
            {
                var a = 1;
            }
            return(newDuration > 0 ? newDuration : 0);
        }
Пример #5
0
        public void TestMeanAndVariacneConsistency()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            LogNormal   logNormal = new LogNormal();

            rs.Clear();
            mean = 2; stdev = 5;

            for (int i = 0; i < numSamples; ++i)
            {
                logNormal.Mean = mean;
                logNormal.StandardDeviation = stdev;
                rs.Push(logNormal.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("logNormal", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Пример #6
0
 /// <summary>
 /// The estimated driving time between stations.
 /// This could either be a simplified version for validation, or a lognormal distribution.
 /// </summary>
 /// <param name="averageForPart">Average driving time for this section</param>
 /// <returns></returns>
 public static int drivingTime(int averageForPart)
 {
     if (Config.c.simplifiedDrivingTimes)
     {
         var x = DiscreteUniform.Sample(0, 100);
         if (x <= 40)
         {
             return((int)(0.8 * averageForPart));
         }
         if (x <= 70)
         {
             return(averageForPart);
         }
         if (x <= 90)
         {
             return((int)(1.2 * averageForPart));
         }
         return((int)(1.4 * averageForPart));
     }
     return((int)LogNormal.Sample(Math.Log(averageForPart), Config.c.sdDrivingTimes));
 }
Пример #7
0
        public void TestMeanAndVariacneConsistency_MuSigma()
        {
            const int   numSamples = 100000;
            double      mean, stdev;
            RunningStat rs        = new RunningStat();
            Random      defaultrs = new Random();
            LogNormal   logNormal = new LogNormal();

            rs.Clear();
            mean = 2; stdev = 5;
            var muTemp    = Math.Log(mean) - 0.5 * Math.Log(1 + stdev * stdev / mean / mean);
            var sigmaTemp = Math.Sqrt(Math.Log(1 + stdev * stdev / mean / mean));

            for (int i = 0; i < numSamples; ++i)
            {
                logNormal.Mu    = muTemp;
                logNormal.Sigma = sigmaTemp;

                rs.Push(logNormal.Sample(defaultrs));
            }
            PrintResult.CompareMeanAndVariance("logNormal", mean, stdev * stdev, rs.Mean(), rs.Variance());
        }
Пример #8
0
        public static List <double> TestUniformDistribution(int amount)
        {
            /*var samples = new List<double>();
             * for (var i = 0; i < amount; i++)
             * {
             * samples.Add(MathNet.Numerics.Distributions.DiscreteUniform.Sample(0, 1000)/1000.00);
             * }
             * return samples;*/
            var samples = new List <double>();
            var dist    = new LogNormal(0, 0.125);

            for (int i = 0; i < amount; i++)
            {
                var sample = dist.Sample();
                var round  = Math.Round(sample * 5, MidpointRounding.AwayFromZero);
                if (sample < 5 || sample > 5)
                {
                    var a = 1;
                }
                samples.Add((int)round);
            }
            return(samples);
        }
Пример #9
0
 public void FailSampleStatic()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => { var d = LogNormal.Sample(new Random(), 0.0, -1.0); });
 }
Пример #10
0
        public void CanSample()
        {
            var n = new LogNormal(1.0, 2.0);

            n.Sample();
        }
Пример #11
0
 public void FailSampleStatic()
 {
     Assert.That(() => { var d = LogNormal.Sample(new Random(0), 0.0, -1.0); }, Throws.ArgumentException);
 }
Пример #12
0
 public void CanSampleStatic()
 {
     LogNormal.Sample(new Random(), 0.0, 1.0);
 }
Пример #13
0
 public void FailSampleStatic()
 {
     var d = LogNormal.Sample(new Random(), 0.0, -1.0);
 }
Пример #14
0
        public static void Excuting_Event()
        {
            //Khoi tao request cap kenh cho M-UE
            for (int i = 0; i < Input.List_MBS[0].ListUE.Count; i++)
            {
                Request new_Request = new Request(Input.List_MBS[0].ListUE[i]);
                Input.List_MBS[0].ListRequest.Add(new_Request);
            }
            //MBS xu li cap kenh cho M-UE
            RequestProcess.processRequest();
            //Tinh Pmax tren moi kenh
            for (int i = 0; i < Input.List_MBS[0].ListUE.Count; i++)
            {
                double linkgain, pathloss, shadowing;
                var    lognormal = new LogNormal(0, 1);
                shadowing = lognormal.Sample();
                pathloss  = Input.List_MBS[0].ListUE[i].PassLoss_Indoor(Input.List_MBS[0].Position);

                //pathloss = 127 + 30 * Math.Log10(Input.MBSCover * Math.Pow(10, -3)); ;

                linkgain = pathloss + shadowing;
                Input.List_MBS[0].ListUE[i].Shadowing = shadowing;
                Input.List_MBS[0].ListUE[i].Linkgain  = Input.List_MBS[0].ListUE[i].PassLoss_Indoor(Input.List_MBS[0].Position) + shadowing;
                //Console.WriteLine("Linkgain is MUE: " + linkgain);*/
                Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].MaxPower = Input.Max_PowerTr - linkgain - Input.SINR_threshold;
                //Console.WriteLine("Total Interference permit: " + Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].MaxPower);
            }

            /*//S-UE chon ngau nhien s kenh
             * for (int i = 0; i < Input.List_SBS.Count; i++)
             * {
             *  for (int j = 0; j < Input.s; j++)
             *  {
             *      double linkgain;
             *      double pathloss, shadowing;
             *      pathloss = Input.List_SBS[i].ListUE[0].PassLoss(Input.List_MBS[0].Position);
             *      var lognormal = new LogNormal(0, 1);
             *      shadowing = lognormal.Sample();
             *      linkgain = pathloss + shadowing;
             *      Random rd = new Random(Guid.NewGuid().GetHashCode());
             *      int channel_id = rd.Next(1, Input.NumberofChannel);
             *      UE ue = new UE();
             *      //Check id da dk lay hay chua
             *      if (Input.List_SBS[i].ListUE[0].ListChannel_Id == null || Input.List_SBS[i].ListUE[0].ListChannel_Id.Contains(channel_id) == false)
             *      {
             *          Input.List_SBS[i].ListUE[0].Linkgain = linkgain;
             *          ue.UE_Id = Input.List_SBS[i].ListUE[0].UE_Id;
             *          ue.Position = Input.List_SBS[i].ListUE[0].Position;
             *          ue.Linkgain = linkgain;
             *          Input.List_SBS[i].ListUE[0].ListChannel_Id.Add(channel_id);
             *          Input.List_MBS[0].ListChannel[channel_id - 1].ListSUE.Add(ue);
             *      }
             *      else
             *      {
             *          //Neu lay r thi chon lai id khac
             *          while (Input.List_SBS[i].ListUE[0].ListChannel_Id.Contains(channel_id) == true)
             *          {
             *              channel_id = rd.Next(1, Input.NumberofChannel);
             *          }
             *          Input.List_SBS[i].ListUE[0].Linkgain = linkgain;
             *          ue.UE_Id = Input.List_SBS[i].ListUE[0].UE_Id;
             *          ue.Position = Input.List_SBS[i].ListUE[0].Position;
             *          ue.Linkgain = linkgain;
             *          Input.List_SBS[i].ListUE[0].ListChannel_Id.Add(channel_id);
             *          Input.List_MBS[0].ListChannel[channel_id - 1].ListSUE.Add(ue);
             *      }
             *  }
             * }*/
            //Cap kenh moi Pair
            //Cap theo linkgain
            if (Input.Type == 1)
            {
                for (int i = 0; i < Input.List_MBS[0].ListPair.Count; i++)
                {
                    //Tinh Linkgain cua UE tren moi kenh
                    for (int j = 0; j < Input.List_MBS[0].ListChannel.Count; j++)
                    {
                        double linkgain;
                        double pathloss, shadowing;
                        pathloss = Input.List_MBS[0].ListPair[i].UE_t.PassLoss_Outdoor(Input.List_MBS[0].ListPair[i].UE_r.Position);
                        var lognormal = new LogNormal(0, 1);
                        shadowing = lognormal.Sample();
                        linkgain  = pathloss + shadowing;
                        Channel channel = new Channel();
                        channel.channel_id = Input.List_MBS[0].ListChannel[j].channel_id;
                        channel.LinkGain   = linkgain;
                        channel.Shadowing  = shadowing;
                        //Add vao list xong xoa sau
                        Input.List_MBS[0].ListPair[i].UE_t.List_channel.Add(channel);
                    }

                    //Chon r kenh co linkgain cao nhat
                    //Sort lon dan linkgain
                    Input.List_MBS[0].ListPair[i].UE_t.quickSort(Input.List_MBS[0].ListPair[i].UE_t.List_channel, 0, Input.NumberofChannel - 1);
                    int numberofchannel_UE = Input.List_MBS[0].ListPair[i].UE_t.List_channel.Count;
                    //delete/chose r channel higher linkgain
                    for (int j = 0; j < numberofchannel_UE - Input.r; j++)
                    {
                        Input.List_MBS[0].ListPair[i].UE_t.List_channel.RemoveAt(0);
                    }

                    for (int j = 0; j < Input.List_MBS[0].ListPair[i].UE_t.List_channel.Count; j++)
                    {
                        UE ue = new UE();
                        ue.UE_Id    = Input.List_MBS[0].ListPair[i].UE_t.UE_Id;
                        ue.Position = Input.List_MBS[0].ListPair[i].UE_t.Position;
                        // ue.Shadowing = Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].Shadowing;
                        int indexChannel = Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].channel_id - 1;
                        Input.List_MBS[0].ListChannel[indexChannel].List_device.Add(ue);
                    }
                    Console.WriteLine("*********************************************************");
                }
            }
            else
            {
                int IndexChannel = 0;
                for (int i = 0; i < Input.List_MBS[0].ListPair.Count; i++)
                {
                    if (IndexChannel == Input.NumberofChannel)
                    {
                        IndexChannel = 0;
                    }
                    //Tinh Linkgain cua UE tren moi kenh
                    double linkgain;
                    double pathloss, shadowing;
                    pathloss = Input.List_MBS[0].ListPair[i].UE_t.PassLoss_Outdoor(Input.List_MBS[0].ListPair[i].UE_r.Position);
                    var lognormal = new LogNormal(0, 1);
                    shadowing = lognormal.Sample();
                    linkgain  = pathloss + shadowing;
                    Channel channel = new Channel();
                    channel.channel_id = IndexChannel + 1;
                    channel.LinkGain   = linkgain;
                    channel.Shadowing  = shadowing;
                    //Add vao list xong xoa sau
                    Input.List_MBS[0].ListPair[i].UE_t.List_channel.Add(channel);
                    IndexChannel++;
                    for (int j = 0; j < Input.List_MBS[0].ListPair[i].UE_t.List_channel.Count; j++)
                    {
                        UE ue = new UE();
                        ue.UE_Id    = Input.List_MBS[0].ListPair[i].UE_t.UE_Id;
                        ue.Position = Input.List_MBS[0].ListPair[i].UE_t.Position;
                        // ue.Shadowing = Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].Shadowing;
                        int indexChannel = Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].channel_id - 1;
                        Input.List_MBS[0].ListChannel[indexChannel].List_device.Add(ue);
                    }
                    Console.WriteLine("*********************************************************");
                }
            }
            //Gioi han cong suat phat tren moi kenh doi voi cac device va SUE
            int sum = 0;

            for (int i = 0; i < Input.List_MBS[0].ListChannel.Count; i++)
            {
                double ratio  = Input.proportion_Allow_Power;
                double PU_max = Input.List_MBS[0].ListChannel[i].MaxPower;
                int    N_d2d  = Input.List_MBS[0].ListChannel[i].List_device.Count;
                int    N_sue  = Input.List_MBS[0].ListChannel[i].ListSUE.Count;
                sum += N_d2d;
                if (N_d2d != 0)
                {
                    Input.List_MBS[0].ListChannel[i].D2D_MaxPower = (10 * Math.Log10(ratio) + PU_max) - (10 * Math.Log10(N_d2d));
                    Console.WriteLine("Interference each device=" + Input.List_MBS[0].ListChannel[i].D2D_MaxPower);
                }
                if (N_sue != 0)
                {
                    Input.List_MBS[0].ListChannel[i].SUE_MaxPower = (10 * Math.Log10(1 - ratio) + PU_max) - (10 * Math.Log10(N_sue));
                    Console.WriteLine("Interference each SUE=" + Input.List_MBS[0].ListChannel[i].SUE_MaxPower);
                }
            }
            Console.WriteLine("Sum device=" + sum);
            //UE dieu chinh cong suat phat
            for (int i = 0; i < Input.List_MBS[0].ListChannel.Count; i++)
            {
                //Cho D2D
                if (Input.List_MBS[0].ListChannel[i].List_device.Count > 0)
                {
                    for (int j = 0; j < Input.List_MBS[0].ListChannel[i].List_device.Count; j++)
                    {
                        double linkgain, Power_cal;
                        double pathloss, shadowing;
                        var    lognormal = new LogNormal(0, 1);
                        shadowing = lognormal.Sample();
                        pathloss  = Input.List_MBS[0].ListChannel[i].List_device[j].PassLoss_Outdoor(Input.List_MBS[0].Position);
                        linkgain  = pathloss + shadowing;
                        Input.List_MBS[0].ListChannel[i].List_device[j].Linkgain = linkgain;
                        Power_cal = (Input.List_MBS[0].ListChannel[i].D2D_MaxPower + linkgain);
                        Console.WriteLine("Linkgain from device to MBS=" + pathloss);
                        Input.List_MBS[0].ListChannel[i].List_device[j].PowerTr = Math.Min(Input.D2D_Max_PowerTr, (Power_cal));
                    }
                }
                //Cho SUE
                for (int k = 0; k < Input.List_MBS[0].ListChannel[i].ListSUE.Count; k++)
                {
                    double linkgain, Power_cal;
                    linkgain  = Input.List_MBS[0].ListChannel[i].ListSUE[k].Linkgain;
                    Power_cal = Input.List_MBS[0].ListChannel[i].SUE_MaxPower + linkgain;
                    Console.WriteLine("Linkgain from SUE to MBS=" + Input.List_MBS[0].ListChannel[i].ListSUE[k].PassLoss_Outdoor(Input.List_MBS[0].Position));
                    Input.List_MBS[0].ListChannel[i].ListSUE[k].PowerTr = Math.Min(Input.SUE_Max_PowerTr, (Power_cal));
                }
            }
        }
Пример #15
0
        public static void Output()
        {
            //Tinh SINR tung M-UE
            double       tPutMUE        = 0;
            string       path10         = Input.path + "\\MUEthroughput_each_device_Paper_" + Input.NumberofSBS + ".txt";
            FileStream   fs10           = new FileStream(path10, FileMode.Create);
            StreamWriter sw10           = new StreamWriter(fs10);
            string       distanceDevice = Input.path + "\\Distance_Device_reuse_channel_Paper_" + Input.NumberofSBS + ".txt";
            FileStream   dtDv           = new FileStream(distanceDevice, FileMode.Create);
            StreamWriter DistanceDevice = new StreamWriter(dtDv);

            Console.WriteLine("MUE");
            // double devicecollision = 0;

            for (int i = 0; i < Input.List_MBS[0].ListUE.Count; i++)
            {
                Console.WriteLine("*********************************");
                Console.WriteLine("MUE_" + Input.List_MBS[0].ListUE[i].UE_Id);
                int    channel_id = Input.List_MBS[0].ListUE[i].channel_id - 1;
                double I_total = 0;
                double linkgain, pathloss, shadowing;
                var    lognormal = new LogNormal(0, 1);
                shadowing = lognormal.Sample();
                linkgain  = Input.List_MBS[0].ListUE[i].PassLoss_Indoor(Input.List_MBS[0].Position) + shadowing;

                double P_r = Input.List_MBS[0].ListUE[i].PowerTr - linkgain;
                double SINR;
                double M_Capacity = 0;
                //Xet SUE
                for (int j = 0; j < Input.List_MBS[0].ListChannel[channel_id].ListSUE.Count; j++)
                {
                    UE     ue_t     = Input.List_MBS[0].ListChannel[channel_id].ListSUE[j];
                    double Linkgain = ue_t.Linkgain;
                    I_total += Math.Pow(10, (ue_t.PowerTr / 10) - (Linkgain / 10));
                    Console.WriteLine("DeviceSUE " + ue_t.UE_Id + " has power=" + ue_t.PowerTr);
                }
                //Xet D2D
                for (int j = 0; j < Input.List_MBS[0].ListChannel[channel_id].List_device.Count; j++)
                {
                    UE     ue_t     = Input.List_MBS[0].ListChannel[channel_id].List_device[j];
                    double Linkgain = ue_t.Linkgain;
                    I_total += Math.Pow(10, (ue_t.PowerTr / 10) - (Linkgain / 10));
                    Console.WriteLine("DevicePair " + ue_t.UE_Id + " has power=" + ue_t.PowerTr);
                    // devicecollision += 1;
                }
                if (I_total != 0)
                {
                    I_total = 10 * Math.Log10(I_total);
                    SINR    = P_r - I_total;
                }
                else
                {
                    SINR = P_r - Input.N0;
                }
                //Capacity
                {
                    Console.WriteLine("SINR=" + SINR);
                    double C;
                    if (SINR < 0.5 && SINR > Input.SINR_outage)
                    {
                        C = 0.25 * Input.B;
                    }
                    else if (SINR > 0.5 && SINR < 3.5)
                    {
                        C = 0.5 * Input.B;
                    }
                    else if (SINR > 3.5 && SINR < 6.5)
                    {
                        C = 1 * Input.B;
                    }
                    else if (SINR > 6.5 && SINR < 9)
                    {
                        C = 1.5 * Input.B;
                    }
                    else if (SINR > 9 && SINR < 12.5)
                    {
                        C = 2 * Input.B;
                    }
                    else if (SINR > 12.5 && SINR < 14.5)
                    {
                        C = 3 * Input.B;
                    }
                    else if (SINR > 14.5 && SINR < 16.5)
                    {
                        C = 3 * Input.B;
                    }
                    else if (SINR > 16.5 && SINR < 18.5)
                    {
                        C = 4 * Input.B;
                    }
                    else if (SINR >= 18.5)
                    {
                        C = 4.5 * Input.B;
                    }
                    else
                    {
                        C = 0;
                    }
                    M_Capacity += C;
                }
                sw10.WriteLine(M_Capacity.ToString().Replace(",", "."));
                Input.List_MBS[0].ListUE[i].SINR = SINR;
                tPutMUE += M_Capacity;
            }
            // Console.WriteLine("So device trung kenh: " + devicecollision);
            sw10.Close();

            //Tinh SINR tung pair
            Console.WriteLine("SINR pair--------------------------");
            double       throughput = 0;
            double       maxpower   = 0;
            string       path11     = Input.path + "\\D2DSINR_each_device_Paper_" + Input.NumberofSBS + ".txt";
            FileStream   fs11       = new FileStream(path11, FileMode.Create);
            StreamWriter sw11       = new StreamWriter(fs11);
            string       path111    = Input.path + "\\D2Dthroughput_each_device_Paper_" + Input.NumberofSBS + ".txt";
            FileStream   fs111      = new FileStream(path111, FileMode.Create);
            StreamWriter sw111      = new StreamWriter(fs111);

            for (int i = 0; i < Input.List_MBS[0].ListPair.Count; i++)
            {
                UE ue_t = Input.List_MBS[0].ListPair[i].UE_t;
                UE ue_r = Input.List_MBS[0].ListPair[i].UE_r;
                // Console.WriteLine("Device" + ue_t.UE_Id);
                double Capacity = 0;
                for (int j = 0; j < ue_t.List_channel.Count; j++)
                {
                    double  P_r;
                    double  I_total = 0;
                    double  SINR, C;
                    Channel channel = Input.List_MBS[0].ListChannel[ue_t.List_channel[j].channel_id - 1];
                    //Tim ue trong list_device
                    int index = 0;
                    while (channel.List_device[index].UE_Id != ue_t.UE_Id)
                    {
                        index++;
                    }
                    P_r = channel.List_device[index].PowerTr - ue_t.List_channel[j].LinkGain;
                    for (int k = 0; k < channel.ListMUE.Count; k++)
                    {
                        double pathloss  = channel.ListMUE[k].PassLoss_Outdoor(ue_r.Position);
                        var    lognormal = new LogNormal(0, 1);
                        double shadowing = lognormal.Sample();
                        double linkgain  = pathloss + shadowing;
                        I_total += Math.Pow(10, (channel.ListMUE[k].PowerTr / 10) - (linkgain / 10));
                    }
                    for (int k = 0; k < channel.List_device.Count; k++)
                    {
                        double pathloss  = channel.List_device[k].PassLoss_Outdoor(ue_r.Position);
                        var    lognormal = new LogNormal(0, 1);
                        double shadowing = lognormal.Sample();
                        double linkgain  = pathloss + shadowing;
                        if (channel.List_device[k].UE_Id != ue_t.UE_Id)
                        {
                            I_total += Math.Pow(10, (channel.List_device[k].PowerTr / 10) - (linkgain / 10));
                        }
                        DistanceDevice.WriteLine(ue_t.Position.distance(channel.List_device[k].Position, ue_r.Position).ToString().Replace(",", "."));
                    }
                    for (int k = 0; k < channel.ListSUE.Count; k++)
                    {
                        double pathloss  = channel.ListSUE[k].PassLoss_Outdoor(ue_r.Position);
                        var    lognormal = new LogNormal(0, 1);
                        double shadowing = lognormal.Sample();
                        double linkgain  = pathloss + shadowing;
                        I_total += Math.Pow(10, (channel.ListSUE[k].PowerTr / 10) - (linkgain / 10));
                    }

                    if (I_total != 0)
                    {
                        I_total = 10 * Math.Log10(I_total);
                        SINR    = P_r - I_total;
                        //Console.WriteLine("=> SINR_" + ue_r.UE_Id + " = " + SINR + "   (dB)");
                    }
                    else
                    {
                        SINR = P_r - Input.N0;
                    }
                    {
                        if (SINR < 0.5 && SINR > Input.SINR_outage)
                        {
                            C = 0.25 * Input.B;
                        }
                        else if (SINR > 0.5 && SINR < 3.5)
                        {
                            C = 0.5 * Input.B;
                        }
                        else if (SINR > 3.5 && SINR < 6.5)
                        {
                            C = 1 * Input.B;
                        }
                        else if (SINR > 6.5 && SINR < 9)
                        {
                            C = 1.5 * Input.B;
                        }
                        else if (SINR > 9 && SINR < 12.5)
                        {
                            C = 2 * Input.B;
                        }
                        else if (SINR > 12.5 && SINR < 14.5)
                        {
                            C = 3 * Input.B;
                        }
                        else if (SINR > 14.5 && SINR < 16.5)
                        {
                            C = 3 * Input.B;
                        }
                        else if (SINR > 16.5 && SINR < 18.5)
                        {
                            C = 4 * Input.B;
                        }
                        else if (SINR >= 18.5)
                        {
                            C = 4.5 * Input.B;
                        }
                        else
                        {
                            C = 0;
                        }
                    }
                    //Tinh Capacity cua Device
                    Capacity += C;
                    sw111.WriteLine(Capacity.ToString().Replace(",", "."));
                    sw11.WriteLine(SINR.ToString().Replace(",", "."));
                }
                // Console.WriteLine("Capacity=" + Capacity);
                throughput += Capacity;
            }
            sw11.Close();
            sw111.Close();
            DistanceDevice.Close();

            /*double powerSUE = 0;
             * for (int i = 0; i < Input.List_SBS.Count; i++)
             * {
             *
             *  powerSUE += Input.List_SBS[i].ListUE[0].PowerTr;
             * }
             * Console.WriteLine("MAX POWER D2D = " + maxpower);
             * Console.WriteLine("MAX POWER SUE = " + powerSUE);*/
            Console.WriteLine("Throughput of MUE=" + tPutMUE);
            Console.WriteLine("throughputPair=" + throughput);
            Input.List_MBS[0].ListTP.Add(throughput);
            //Check so luong device trong channel
            double totaldevice = 0;

            for (int i = 0; i < Input.List_MBS[0].ListChannel.Count; i++)
            {
                double sum = Input.List_MBS[0].ListChannel[i].List_device.Count + Input.List_MBS[0].ListChannel[i].ListSUE.Count;
                //   Console.WriteLine("Channel_" + i + "has " + sum);
                totaldevice += sum;
            }
            Console.WriteLine("Total device=" + totaldevice);
            Console.WriteLine("CENTRALIZE");

            /*    Console.WriteLine("------------------------------------------------------");
             *  Console.WriteLine("Total D2D_pair = " + Input.List_Pair.Count);
             *  Console.WriteLine("------------------------------------------------------");
             *  Console.WriteLine("L = 127 + 30*Log(d*10^-3) (dB) (distance: met)");
             *  Console.WriteLine("Total interference = (P_tr1/L1) + (P_tr2/L2) + ... + (P_tr10/L10)" +
             *   "= 10^[(P_tr1(dBm)-L1(dB))/10] + 10^[(P_tr2(dBm)-L2(dB))/10] + ... + 10^[(P_tr10(dBm)-L10(dB))/10] ");
             *  Console.WriteLine("SINR(dB) = (P_tr-L)(dBm) - 10log_10_(I)(dB)");
             *  Console.WriteLine("------------------------------------------------------");*/
            /*    for (int i = 0; i < Input.List_MBS[0].ListUE.Count; i++)
             *  {
             *      Console.WriteLine("UE" + Input.List_MBS[0].ListUE[i].UE_Id + "use channel:" + Input.List_MBS[0].ListUE[i].channel_id);
             *  }
             *  for (int i = 0; i < Input.List_SBS.Count; i++)
             *  {
             *      Console.WriteLine("Id S-UE" + Input.List_SBS[i].ListUE[0].UE_Id);
             *      for (int j = 0; j < Input.List_SBS[i].ListUE[0].List_channel_id.Count; j++)
             *      {
             *          Console.WriteLine(Input.List_SBS[i].ListUE[0].List_channel_id[j]);
             *      }
             *  }
             *  for (int i = 0; i < Input.List_MBS[0].ListChannel.Count; i++)
             *  {
             *      Console.WriteLine("Channel " + (i + 1));
             *      for (int j = 0; j < Input.List_MBS[0].ListChannel[i].ListUE.Count; j++)
             *      {
             *          Console.WriteLine(Input.List_MBS[0].ListChannel[i].ListUE[j].UE_Id);
             *      }
             *//*     }*//*
             * for(int i = 0; i < Input.List_MBS[0].ListPair.Count; i++)
             * {
             *  Console.WriteLine("------------------------------------");
             *  Console.WriteLine("Chose r channel higher linkgain");
             *  for (int j = 0; j < Input.List_MBS[0].ListPair[i].UE_t.List_channel.Count; j++)
             *  {
             *      Console.WriteLine("Channel" + Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].channel_id + " has linkgain:" + Input.List_MBS[0].ListPair[i].UE_t.List_channel[j].LinkGain);
             *  }
             *  Console.WriteLine("*********************************************************");
             * }*/
            /* string path1 = Input.path + "\\Input with Power" + Input.D2D_Max_PowerTr + "_" + Input.SUE_Max_PowerTr + ".txt";
             * StreamWriter sw1 = new StreamWriter(path1, false);
             * sw1.WriteLine("L = 127 + 30*Log(d*10^-3) (dB) (distance: met)");
             * sw1.WriteLine("Total interference = (P_tr1/L1) + (P_tr2/L2) + ... + (P_tr10/L10)" +
             * "= 10^[(P_tr1(dBm)-L1(dB))/10] + 10^[(P_tr2(dBm)-L2(dB))/10] + ... + 10^[(P_tr10(dBm)-L10(dB))/10]  (W)");
             * sw1.WriteLine("SINR(dB) = (P_tr-L)(dBm) - 10log_10_(I)(dB)");
             * sw1.WriteLine("-------------------------------------");
             * sw1.WriteLine("NumberOfMacroUE: " + Input.NumberofM_UE);
             * sw1.WriteLine("NumberOfSBS: " + Input.List_SBS.Count);
             * sw1.WriteLine("NumberOfPairD2D: " + Input.List_MBS[0].ListPair.Count);
             * sw1.WriteLine("NumberOfChannel: " + Input.NumberofChannel);
             * sw1.WriteLine("-------------------------------------");
             * sw1.WriteLine("MBSCover: " + Input.MBSCover + " (m)");
             * //  sw1.WriteLine("SBSCover: " + Input.SBSCover + " (m)");
             * sw1.WriteLine("D2DCover: " + Input.D2DCover + " (m)");
             * sw1.WriteLine("MaxPowerofMacro: " + Input.Max_PowerTr + " (dBm)");
             * sw1.WriteLine("MaxPowerofDevice: " + Input.D2D_Max_PowerTr + " (dBm)");
             * sw1.WriteLine("-------------------------------------");
             * sw1.WriteLine("Information of MacroUE: ");
             * for (int i = 0; i < Input.List_MBS[0].ListUE.Count; i++)
             * {
             *   sw1.WriteLine("MacroUE has ID: " + Input.List_MBS[0].ListUE[i].UE_Id + " and shadowing=" + Input.List_MBS[0].ListUE[i].Shadowing + " use channel " + Input.List_MBS[0].ListUE[i].channel_id + " has list device using this channel");
             *   for (int j = 0; j < Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].ListMUE.Count; j++)
             *   {
             *       UE ue = Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].ListMUE[j];
             *       sw1.WriteLine("  UE_id:" + ue.UE_Id + " Power= " + ue.PowerTr + " has distance MBS is " +
             *                                               ue.Position.distance(ue.Position, Input.List_MBS[0].Position));
             *   }
             *   for (int j = 0; j < Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].ListSUE.Count; j++)
             *   {
             *       UE ue = Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].ListSUE[j];
             *       sw1.WriteLine("  ID of SUE:" + ue.UE_Id + " Power= " + ue.PowerTr + " has distance MBS is " +
             *                                               ue.Position.distance(ue.Position, Input.List_MBS[0].Position));
             *   }
             *   for (int j = 0; j < Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].List_device.Count; j++)
             *   {
             *       UE ue = Input.List_MBS[0].ListChannel[Input.List_MBS[0].ListUE[i].channel_id - 1].List_device[j];
             *       sw1.WriteLine("  ID of Device:" + ue.UE_Id + " Power= " + ue.PowerTr + " has distance MBS is " +
             *                                               ue.Position.distance(ue.Position, Input.List_MBS[0].Position));
             *   }
             *   sw1.WriteLine("=>SINR " + Input.List_MBS[0].ListUE[i].SINR);
             * }
             * for(int i=0; i < Input.List_MBS[0].ListTP.Count; i++)
             * {
             *   sw1.WriteLine("throughput=" + Input.List_MBS[0].ListTP[i]);
             *
             * }
             * sw1.Close();*/
        }
Пример #16
0
 public void CanSample()
 {
     var n = new LogNormal(1.0, 2.0);
     var d = n.Sample();
 }
Пример #17
0
        /// <summary>
        /// Run example
        /// </summary>
        /// <a href="http://en.wikipedia.org/wiki/Log-normal_distribution">LogNormal distribution</a>
        public void Run()
        {
            // 1. Initialize the new instance of the LogNormal distribution class with parameters Mu = 0, Sigma = 1
            var logNormal = new LogNormal(0, 1);

            Console.WriteLine(@"1. Initialize the new instance of the LogNormal distribution class with parameters Mu = {0}, Sigma = {1}", logNormal.Mu, logNormal.Sigma);
            Console.WriteLine();

            // 2. Distributuion properties:
            Console.WriteLine(@"2. {0} distributuion properties:", logNormal);

            // Cumulative distribution function
            Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", logNormal.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));

            // Probability density
            Console.WriteLine(@"{0} - Probability density at location '0.3'", logNormal.Density(0.3).ToString(" #0.00000;-#0.00000"));

            // Log probability density
            Console.WriteLine(@"{0} - Log probability density at location '0.3'", logNormal.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));

            // Entropy
            Console.WriteLine(@"{0} - Entropy", logNormal.Entropy.ToString(" #0.00000;-#0.00000"));

            // Largest element in the domain
            Console.WriteLine(@"{0} - Largest element in the domain", logNormal.Maximum.ToString(" #0.00000;-#0.00000"));

            // Smallest element in the domain
            Console.WriteLine(@"{0} - Smallest element in the domain", logNormal.Minimum.ToString(" #0.00000;-#0.00000"));

            // Mean
            Console.WriteLine(@"{0} - Mean", logNormal.Mean.ToString(" #0.00000;-#0.00000"));

            // Median
            Console.WriteLine(@"{0} - Median", logNormal.Median.ToString(" #0.00000;-#0.00000"));

            // Mode
            Console.WriteLine(@"{0} - Mode", logNormal.Mode.ToString(" #0.00000;-#0.00000"));

            // Variance
            Console.WriteLine(@"{0} - Variance", logNormal.Variance.ToString(" #0.00000;-#0.00000"));

            // Standard deviation
            Console.WriteLine(@"{0} - Standard deviation", logNormal.StdDev.ToString(" #0.00000;-#0.00000"));

            // Skewness
            Console.WriteLine(@"{0} - Skewness", logNormal.Skewness.ToString(" #0.00000;-#0.00000"));
            Console.WriteLine();

            // 3. Generate 10 samples
            Console.WriteLine(@"3. Generate 10 samples");
            for (var i = 0; i < 10; i++)
            {
                Console.Write(logNormal.Sample().ToString("N05") + @" ");
            }

            Console.WriteLine();
            Console.WriteLine();

            // 4. Generate 100000 samples of the LogNormal(0, 1) distribution and display histogram
            Console.WriteLine(@"4. Generate 100000 samples of the LogNormal(0, 1) distribution and display histogram");
            var data = new double[100000];

            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 5. Generate 100000 samples of the LogNormal(0, 0.5) distribution and display histogram
            Console.WriteLine(@"5. Generate 100000 samples of the LogNormal(0, 0.5) distribution and display histogram");
            logNormal.Sigma = 0.5;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
            Console.WriteLine();

            // 6. Generate 100000 samples of the LogNormal(5, 0.25) distribution and display histogram
            Console.WriteLine(@"6. Generate 100000 samples of the LogNormal(5, 0.25) distribution and display histogram");
            logNormal.Mu    = 5;
            logNormal.Sigma = 0.25;
            for (var i = 0; i < data.Length; i++)
            {
                data[i] = logNormal.Sample();
            }

            ConsoleHelper.DisplayHistogram(data);
        }