protected void Button1_Click(object sender, EventArgs e) { int n = 1; while (n > 0) { n--; con.Open(); // int n = 100; // int j = 1; // for(int j=1;j<=50;j++) // { //RandomNumbers.Seed((uint)(time(0))); /* double MU1 = GlobalMembers.random_weight(0, 1); * double MU2 = GlobalMembers.random_weight(0, 1); * double MU3 = GlobalMembers.random_weight(0, 1); * // double a1 = 1; * double NU1 = (double)1 - MU1; * double NU2 = (double)1 - MU2; * double NU3 = (double)1 - MU3; */// double w1=random_weight(0,1),w2=random_weight(0,1),w3=random_weight(0,1); //double MU=1-((1-pow(MU1,w1))*(1-pow(MU2,w2))*(1-pow(MU3,w3))); /* double MU1 = Convert.ToDouble(Session["MU1"]); * double MU2 = Convert.ToDouble(Session["MU2"]); * double MU3 = Convert.ToDouble(Session["MU3"]); * double NU1 = Convert.ToDouble(Session["NU1"]); * double NU2 = Convert.ToDouble(Session["NU2"]); * double NU3 = Convert.ToDouble(Session["NU3"]); */ string semail = Session["email"].ToString(); string sname = Session["name"].ToString(); SqlCommand cmd = new SqlCommand("Select MU_Aggregate,NU_Aggregate from LearningForm Where Email='" + semail + "'", con); SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); int flag = 1; if (dt.Rows.Count <= 0) { // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please fill the Learning Style questionnaire first.')", true); Session["flag"] = 0; Response.Redirect("Learningform.aspx"); } double MU1 = Convert.ToDouble(dt.Rows[0][0]); double NU1 = Convert.ToDouble(dt.Rows[0][1]); SqlCommand cmd1 = new SqlCommand("Select MU,NU from PersonalityForm Where Email='" + semail + "'", con); SqlDataReader dr1 = cmd1.ExecuteReader(); DataTable dt1 = new DataTable(); dt1.Load(dr1); if (dt1.Rows.Count <= 0) { Session["flag"] = 0; Response.Redirect("Personalityform.aspx"); } double MU2 = Convert.ToDouble(dt1.Rows[0][0]); double NU2 = Convert.ToDouble(dt1.Rows[0][1]); SqlCommand cmd2 = new SqlCommand("Select MU,NU from Knowledgeform Where Email='" + semail + "'", con); SqlDataReader dr2 = cmd2.ExecuteReader(); DataTable dt2 = new DataTable(); dt2.Load(dr2); if (dt2.Rows.Count <= 0) { Session["flag"] = 0; Response.Redirect("Knowledgelevel.aspx"); } double MU3 = Convert.ToDouble(dt2.Rows[0][0]); double NU3 = Convert.ToDouble(dt2.Rows[0][1]); double averageMU = (MU1 + MU2 + MU3) / 3; double diffMU1 = MU1 - NU1; double diffMU2 = MU2 - NU2; double diffMU3 = MU3 - NU3; double averagediffMU = (diffMU1 + diffMU2 + diffMU3) / 3; int generation = 0; List <Individual> population = new List <Individual>(); bool found = false; List <Indiv> pop = new List <Indiv>(); for (int i = 0; i < DefineConstants.POPULATION_SIZE; i++) { //string gnome = create_gnome(); population.Add(new Individual(MU1, MU2, MU3)); pop.Add(new Indiv(NU1, NU2, NU3)); //cout<<population[i].fitness<<" "; } while (!found) { if (generation == 100) { found = true; break; } // List<int> integers = new List<int>(); List <Individual> new_generation = new List <Individual>(); List <Indiv> new_gen = new List <Indiv>(); int s = (80 * DefineConstants.POPULATION_SIZE) / 100; for (int i = 10; i < s + 10; i++) { new_generation.Add(population[i]); new_gen.Add(pop[i]); // cout<<population[i].fitness<<" "; } s = (20 * DefineConstants.POPULATION_SIZE) / 100; for (int i = 0; i < s; i++) { // int len = population.size(); int r = GlobalMembers.random_num(0, 5); Individual parent1 = population[r]; Indiv par1 = pop[r]; //cout<<population[r].fitness<<" "; r = GlobalMembers.random_num(0, 5); Individual parent2 = population[r]; Indiv par2 = pop[r]; //cout<<population[r].fitness<<" "; Individual offspring = parent1.mate(parent2); Indiv offsp = par1.mat(par2); new_generation.Add(offspring); new_gen.Add(offsp); //cout<<new_generation[i].fitness<<" "; } population = new_generation; pop = new_gen; // cout<< "Generation: " << generation << "\t"; //cout<< population[0].chromosome <<endl; generation++; } //cout<< generation << "\t"; double X = Convert.ToDouble(population[0].chromosome); double Y = Convert.ToDouble(pop[0].chromo); //System.Diagnostics.Debug.WriteLine("MU-" + X); // System.Diagnostics.Debug.WriteLine("NU-" + Y); if (X + Y > 1) { Y = (double)1 - X; } Session["Mu"] = X; Session["Nu"] = Y; knn a = new knn(); a.KNN(); int c; c = Convert.ToInt32(Session["class"]); SqlCommand com = new SqlCommand("insert into Class (Email,Name,MU,NU,Class,Generation,Mu1,Mu2,Mu3,AverageMu,Mu1diff,Mu2diff,Mu3diff,averageMudiff) values('" + semail + "','" + sname + "','" + X + "','" + Y + "','" + c + "','" + generation + "','" + MU1 + "','" + MU2 + "','" + MU3 + "','" + averageMU + "','" + diffMU1 + "','" + diffMU2 + "','" + diffMU3 + "','" + averagediffMU + "')", con); com.ExecuteNonQuery(); //} // Response.Redirect("knn.aspx"); string cl; if (c == 1) { cl = "Low"; } else if (c == 2) { cl = "Low-Medium"; } else if (c == 3) { cl = "Medium"; } else if (c == 4) { cl = "Medium-High"; } else { cl = "High"; } con.Close(); } //Response.Redirect("WebForm2.aspx"); //Response.Write("<script language='javascript'>window.alert('You belong to class "+cl+"');window.location='WebForm2.aspx';</script>"); }