private void diagnoseBtn_Click(object sender, EventArgs e) { List <Kasus> listKasus = new List <Kasus>(); Kasus input = new Kasus(); List <string> temp = new List <string>(); for (int i = 0; i < listBoxGejala.Items.Count; i++) { if (listBoxGejala.GetItemChecked(i)) { string str = (string)listBoxGejala.Items[i]; temp.Add(str.Split('(', ')')[1]); } } foreach (Control control in this.waktuGroupBox.Controls) { if (control is RadioButton) { RadioButton radio = control as RadioButton; if (radio.Checked) { string str = radio.Text; temp.Add(str.Split('(', ')')[1]); } } } string[] gejala = temp.ToArray(); input.SetGejala(gejala); listKasus.Add(input); Diagnose(listKasus); }
private void diagnoseBtn_Click(object sender, EventArgs e) { List<Kasus> listKasus = new List<Kasus>(); Kasus input = new Kasus(); List<string> temp = new List<string>(); for (int i = 0; i < listBoxGejala.Items.Count; i++) { if (listBoxGejala.GetItemChecked(i)) { string str = (string) listBoxGejala.Items[i]; temp.Add(str.Split('(', ')')[1]); } } foreach (Control control in this.waktuGroupBox.Controls) { if (control is RadioButton) { RadioButton radio = control as RadioButton; if (radio.Checked) { string str = radio.Text; temp.Add(str.Split('(', ')')[1]); } } } string[] gejala = temp.ToArray(); input.SetGejala(gejala); listKasus.Add(input); Diagnose(listKasus); }
private void prosesBtn_Click(object sender, EventArgs e) { beliefDgv.Rows.Clear(); individuDgv.Rows.Clear(); int popSize = Convert.ToInt32(popSizeBox.Text); int iterasi = Convert.ToInt32(iterationBox.Text); double cr = Convert.ToDouble(crBox.Text); double mr = Convert.ToDouble(mrBox.Text); DataTable dt = db.query("SELECT * FROM gejala"); rule = new List<Gejala>(); foreach (DataRow row in dt.Rows) { Gejala g = new Gejala(); double[] p = new double[3]; g.SetKodeGejala(Convert.ToString(row["kode_gejala"])); g.SetNamaGejala(Convert.ToString(row["nama_gejala"])); p[0] = Convert.ToDouble(row["pneumonia"]); p[1] = Convert.ToDouble(row["bronkitis"]); p[2] = Convert.ToDouble(row["urti"]); g.SetPenyakit(p); rule.Add(g); } DataTable ks = db.query("SELECT * FROM kasus"); List<Kasus> listKasus = new List<Kasus>(); foreach (DataRow r in ks.Rows) { string s = Convert.ToString(r["gejala"]); string[] gejala = Array.ConvertAll(s.Split(','), ge => ge.Trim()); string d = Convert.ToString(r["diagnosa"]); string[] diagnosa = Array.ConvertAll(d.Split(','), di => di.Trim()); Kasus k = new Kasus(); k.SetGejala(gejala); k.SetDiagnosa(diagnosa); listKasus.Add(k); } de = new Density(rule); iBaru = new List<Individu>(); List<int> index = new List<int>(); for (int iter = 0; iter < iterasi; iter++) { // Init List<Individu> P; Console.WriteLine("Iterasi ke - " + (iter + 1) + " ---------------------------------"); if (iter == 0) { P = new List<Individu>(); Console.WriteLine("-- Dempster Shafer Individu --"); for (int i = 0; i < popSize; i++) { Console.WriteLine(">> Individu ke - " + (i + 1)); Individu inv = new Individu(de.GetDensity()); DempsterShafer ds = new DempsterShafer(inv, listKasus); inv.SetFitness(ds.GetFitness()); P.Add(inv); } } else { P = iBaru; } List<Individu> C = new List<Individu>(); CrossOver co = new CrossOver(P, cr, popSize); C = co.GetCrossover(); Console.WriteLine("-- Dempster Shafer Crossover --"); for (int j = 0; j < C.Count; j++) { Console.WriteLine(">> Crossover ke - " + (j + 1)); DempsterShafer ds = new DempsterShafer(C[j], listKasus); C[j].SetFitness(ds.GetFitness()); } double minimum = C[0].GetFitness(); double maximum = 0; for (int k = 0; k < C.Count; k++) { if (minimum > C[k].GetFitness()) minimum = C[k].GetFitness(); if (maximum < C[k].GetFitness()) maximum = C[k].GetFitness(); } double maxmin = maximum - minimum; Console.WriteLine("-- Mutasi, Dempster Shafer Mutasi --"); Mutasi mts = new Mutasi(P, mr, popSize, maxmin, rule); C.Add(mts.GetMutasi()); DempsterShafer dss = new DempsterShafer(C[C.Count - 1], listKasus); C[C.Count - 1].SetFitness(dss.GetFitness()); Console.WriteLine("-- Nilai Fitness Akhir --"); Selection slct = new Selection(P, C, popSize); iBaru = slct.GetITerbaik(); index = slct.GetIndex(); } PopulateDgv(rule, iBaru[0]); double akurasi = iBaru[0].GetFitness() * 100; labelAkurasi.Text = akurasi.ToString() + " %"; for (int i = 0; i < iBaru.Count; i++) { int idIndividu = index[i]+1; string kode; if ( idIndividu > popSize) { idIndividu -= popSize; kode = "C" + idIndividu; } else { kode = "P" + idIndividu; } this.individuDgv.Rows.Add(kode, iBaru[i].GetFitness()); } MessageBox.Show("Proses Perhitungan Selesai"); }
private void prosesBtn_Click(object sender, EventArgs e) { beliefDgv.Rows.Clear(); individuDgv.Rows.Clear(); int popSize = Convert.ToInt32(popSizeBox.Text); int iterasi = Convert.ToInt32(iterationBox.Text); double cr = Convert.ToDouble(crBox.Text); double mr = Convert.ToDouble(mrBox.Text); DataTable dt = db.query("SELECT * FROM gejala"); rule = new List <Gejala>(); foreach (DataRow row in dt.Rows) { Gejala g = new Gejala(); double[] p = new double[3]; g.SetKodeGejala(Convert.ToString(row["kode_gejala"])); g.SetNamaGejala(Convert.ToString(row["nama_gejala"])); p[0] = Convert.ToDouble(row["pneumonia"]); p[1] = Convert.ToDouble(row["bronkitis"]); p[2] = Convert.ToDouble(row["urti"]); g.SetPenyakit(p); rule.Add(g); } DataTable ks = db.query("SELECT * FROM kasus"); List <Kasus> listKasus = new List <Kasus>(); foreach (DataRow r in ks.Rows) { string s = Convert.ToString(r["gejala"]); string[] gejala = Array.ConvertAll(s.Split(','), ge => ge.Trim()); string d = Convert.ToString(r["diagnosa"]); string[] diagnosa = Array.ConvertAll(d.Split(','), di => di.Trim()); Kasus k = new Kasus(); k.SetGejala(gejala); k.SetDiagnosa(diagnosa); listKasus.Add(k); } de = new Density(rule); iBaru = new List <Individu>(); List <int> index = new List <int>(); for (int iter = 0; iter < iterasi; iter++) { // Init List <Individu> P; Console.WriteLine("Iterasi ke - " + (iter + 1) + " ---------------------------------"); if (iter == 0) { P = new List <Individu>(); Console.WriteLine("-- Dempster Shafer Individu --"); for (int i = 0; i < popSize; i++) { Console.WriteLine(">> Individu ke - " + (i + 1)); Individu inv = new Individu(de.GetDensity()); DempsterShafer ds = new DempsterShafer(inv, listKasus); inv.SetFitness(ds.GetFitness()); P.Add(inv); } } else { P = iBaru; } List <Individu> C = new List <Individu>(); CrossOver co = new CrossOver(P, cr, popSize); C = co.GetCrossover(); Console.WriteLine("-- Dempster Shafer Crossover --"); for (int j = 0; j < C.Count; j++) { Console.WriteLine(">> Crossover ke - " + (j + 1)); DempsterShafer ds = new DempsterShafer(C[j], listKasus); C[j].SetFitness(ds.GetFitness()); } double minimum = C[0].GetFitness(); double maximum = 0; for (int k = 0; k < C.Count; k++) { if (minimum > C[k].GetFitness()) { minimum = C[k].GetFitness(); } if (maximum < C[k].GetFitness()) { maximum = C[k].GetFitness(); } } double maxmin = maximum - minimum; Console.WriteLine("-- Mutasi, Dempster Shafer Mutasi --"); Mutasi mts = new Mutasi(P, mr, popSize, maxmin, rule); C.Add(mts.GetMutasi()); DempsterShafer dss = new DempsterShafer(C[C.Count - 1], listKasus); C[C.Count - 1].SetFitness(dss.GetFitness()); Console.WriteLine("-- Nilai Fitness Akhir --"); Selection slct = new Selection(P, C, popSize); iBaru = slct.GetITerbaik(); index = slct.GetIndex(); } PopulateDgv(rule, iBaru[0]); double akurasi = iBaru[0].GetFitness() * 100; labelAkurasi.Text = akurasi.ToString() + " %"; for (int i = 0; i < iBaru.Count; i++) { int idIndividu = index[i] + 1; string kode; if (idIndividu > popSize) { idIndividu -= popSize; kode = "C" + idIndividu; } else { kode = "P" + idIndividu; } this.individuDgv.Rows.Add(kode, iBaru[i].GetFitness()); } MessageBox.Show("Proses Perhitungan Selesai"); }