コード例 #1
0
        private static List <DataFuzzy> MF_JlhData(int jlhData)
        {
            List <DataFuzzy> hasilMembershipFunction = new List <DataFuzzy>();
            DataFuzzy        sedikit = new DataFuzzy(); sedikit.kategori = "Sedikit";
            DataFuzzy        banyak  = new DataFuzzy(); banyak.kategori = "Banyak";

            if (jlhData <= 10)
            {
                sedikit.nilai = 1;
                banyak.nilai  = 0;
            }
            else if (jlhData > 10 && jlhData < 50)
            {
                sedikit.nilai = (50 - jlhData) / (50 - 10);
                banyak.nilai  = (jlhData - 10) / (50 - 10);
            }
            else
            {
                sedikit.nilai = 0;
                banyak.nilai  = 1;
            }

            hasilMembershipFunction.Add(sedikit);
            hasilMembershipFunction.Add(banyak);

            return(hasilMembershipFunction);
        }
コード例 #2
0
        private static List <DataFuzzy> MF_JlhSource(int jlhSource)
        {
            List <DataFuzzy> hasilMembershipFunction = new List <DataFuzzy>();
            DataFuzzy        single = new DataFuzzy(); single.kategori = "Single";
            DataFuzzy        multi  = new DataFuzzy(); multi.kategori = "Multi";

            if (jlhSource <= 1)
            {
                single.nilai = 1;
                multi.nilai  = 0;
            }
            else if (jlhSource > 1 && jlhSource < 2)
            {
                single.nilai = (2 - jlhSource) / (2 - 1);
                multi.nilai  = (jlhSource - 1) / (2 - 1);
            }
            else
            {
                single.nilai = 0;
                multi.nilai  = 1;
            }

            hasilMembershipFunction.Add(single);
            hasilMembershipFunction.Add(multi);

            return(hasilMembershipFunction);
        }
コード例 #3
0
        private static List <DataFuzzy> MF_JlhLength(int jlhLength)
        {
            List <DataFuzzy> hasilMembershipFunction = new List <DataFuzzy>();
            DataFuzzy        pendek  = new DataFuzzy(); pendek.kategori = "Pendek";
            DataFuzzy        normal  = new DataFuzzy(); normal.kategori = "Normal";
            DataFuzzy        panjang = new DataFuzzy(); panjang.kategori = "Panjang";

            if (jlhLength <= 60)
            {
                pendek.nilai  = 1;
                normal.nilai  = 0;
                panjang.nilai = 0;
            }
            else if (jlhLength > 60 && jlhLength < 90)
            {
                pendek.nilai  = (90 - jlhLength) / (90 - 60);
                normal.nilai  = (jlhLength - 60) / (90 - 60);
                panjang.nilai = 0;
            }
            else if (jlhLength >= 90 && jlhLength < 120)
            {
                pendek.nilai  = 0;
                normal.nilai  = (120 - jlhLength) / (120 - 90);
                panjang.nilai = (jlhLength - 90) / (120 - 90);
            }
            else
            {
                pendek.nilai  = 0;
                normal.nilai  = 0;
                panjang.nilai = 1;
            }

            hasilMembershipFunction.Add(pendek);
            hasilMembershipFunction.Add(normal);
            hasilMembershipFunction.Add(panjang);

            return(hasilMembershipFunction);
        }
コード例 #4
0
        private static DataFuzzy InferenceProcess(DataFuzzy dt_JlhData, DataFuzzy dt_jlhSource, DataFuzzy dt_JlhLength)
        {
            DataFuzzy dataInference = new DataFuzzy();

            if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                dt_JlhLength.kategori.ToUpper() == "Pendek".ToUpper())
            {
                dataInference.kategori = "Rendah";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Normal".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Panjang".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Pendek".ToUpper())
            {
                dataInference.kategori = "Rendah";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Normal".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Sedikit".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Panjang".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Pendek".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Normal".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Single".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Panjang".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Pendek".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Normal".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }
            else if (dt_JlhData.kategori.ToUpper() == "Banyak".ToUpper() &&
                     dt_jlhSource.kategori.ToUpper() == "Multi".ToUpper() &&
                     dt_JlhLength.kategori.ToUpper() == "Panjang".ToUpper())
            {
                dataInference.kategori = "Tinggi";
            }

            dataInference.nilai = Math.Min(dt_JlhData.nilai, Math.Min(dt_jlhSource.nilai, dt_JlhLength.nilai));
            return(dataInference);
        }
コード例 #5
0
        private static decimal DDosDetectorUsingFuzzyLogic(DataForFuzzy dataForFuzzy)
        {
            decimal nilaiPrediksi = 0M;

            #region Fuzzifikasi
            List <DataFuzzy> f_jlhData   = MF_JlhData(dataForFuzzy.jlhData);
            List <DataFuzzy> f_jlhSource = MF_JlhSource(dataForFuzzy.jlhSource);
            List <DataFuzzy> f_jlhLength = MF_JlhLength(dataForFuzzy.jlhLength);
            #endregion

            #region Inference : Conjunction-Disjunction (Min-Max)
            //Conjunction (Min)
            List <DataFuzzy> hasilConjunction = new List <DataFuzzy>();
            foreach (DataFuzzy dt_JlhData in f_jlhData)
            {
                foreach (DataFuzzy dt_jlhSource in f_jlhSource)
                {
                    foreach (DataFuzzy dt_JlhLength in f_jlhLength)
                    {
                        DataFuzzy dataInference = InferenceProcess(dt_JlhData, dt_jlhSource, dt_JlhLength);
                        hasilConjunction.Add(dataInference);
                    }
                }
            }

            //Disjunction (Max)
            List <DataFuzzy> hasilDisjuntion = new List <DataFuzzy>();

            DataFuzzy rendah = new DataFuzzy();
            rendah.kategori = "Rendah";
            rendah.nilai    = hasilConjunction.Where(x => x.kategori.ToUpper() == rendah.kategori.ToUpper()).Select(y => y.nilai).ToList().Max();
            hasilDisjuntion.Add(rendah);

            DataFuzzy tinggi = new DataFuzzy();
            tinggi.kategori = "Tinggi";
            tinggi.nilai    = hasilConjunction.Where(x => x.kategori.ToUpper() == tinggi.kategori.ToUpper()).Select(y => y.nilai).ToList().Max();
            hasilDisjuntion.Add(tinggi);
            #endregion

            #region Defuzzifikasi : Weighted Average
            foreach (DataFuzzy dataDefuzzy in hasilDisjuntion)
            {
                if (dataDefuzzy.kategori.ToUpper() == "Rendah".ToUpper())
                {
                    nilaiPrediksi += dataDefuzzy.nilai * 0;
                }
                else if (dataDefuzzy.kategori.ToUpper() == "Tinggi".ToUpper())
                {
                    nilaiPrediksi += dataDefuzzy.nilai * 1;
                }
            }

            decimal totalValue = hasilDisjuntion.Select(x => x.nilai).Sum();
            if (totalValue == 0)
            {
                nilaiPrediksi = 0;
            }
            else
            {
                nilaiPrediksi /= totalValue;
            }
            #endregion

            return(nilaiPrediksi);
        }