private void btnOK_Click(object sender, EventArgs e) { if (!CheckNull()) return; if (!CheckLogicValue()) return; //ContinuousFuzzySetBLL newFS = new ContinuousFuzzySetBLL(); FuzzyProcess fz = new FuzzyProcess(); ConFS newFS = new ConFS(); //newFS.FuzzySetName = txtLinguistic.Text.Trim(); newFS.Name = txtLinguistic.Text.Trim() + ".conFS"; String content = txtBottomLeft.Text.Trim(); string path = Directory.GetCurrentDirectory() + @"\lib\"; if (txtTopLeft.Text.Trim() == "" && txtTopRight.Text.Trim() != "") { newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text); newFS.Top_Left = newFS.Top_Right = Convert.ToDouble(txtTopRight.Text); newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text); content += "," + txtTopRight.Text.Trim() + "," + txtTopRight.Text.Trim() + "," + txtBottomRight.Text.Trim(); //if (newFS.Update() == 1) if (fz.UpdateFS(path, content, newFS.Name) == 1) { MessageBox.Show("Save Fuzzy Set DONE!"); } else { frmRunAsAdministrator frm = new frmRunAsAdministrator(); frm.ShowDialog(); } } else if (txtTopLeft.Text.Trim() != "" && txtTopRight.Text.Trim() == "") { newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text); newFS.Top_Left = newFS.Top_Right = Convert.ToDouble(txtTopLeft.Text); newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text); content += "," + txtTopLeft.Text.Trim() + "," + txtTopLeft.Text.Trim() + "," + txtBottomRight.Text.Trim(); //if (newFS.Update() == 1) if (fz.UpdateFS(path, content, newFS.Name) == 1) { MessageBox.Show("Save Fuzzy Set DONE!"); } else { frmRunAsAdministrator frm = new frmRunAsAdministrator(); frm.ShowDialog(); } } else { newFS.Bottom_Left = Convert.ToDouble(txtBottomLeft.Text); newFS.Top_Left = Convert.ToDouble(txtTopLeft.Text); newFS.Top_Right = Convert.ToDouble(txtTopRight.Text); newFS.Bottom_Right = Convert.ToDouble(txtBottomRight.Text); content += "," + txtTopLeft.Text.Trim() + "," + txtTopRight.Text.Trim() + "," + txtBottomRight.Text.Trim(); //if (newFS.Update() == 1) if (fz.UpdateFS(path, content, newFS.Name) == 1) { MessageBox.Show("Save Fuzzy Set DONE!"); } else { frmRunAsAdministrator frm = new frmRunAsAdministrator(); frm.ShowDialog(); } } }
//private Double FuzzyCompare(Double value, ContinuousFuzzySetBLL set, String opr) //{ // Double result = 0; // Double membership = set.GetMembershipAt(value); // switch (opr) // { // case "→": // if (value >= set.Bottom_Left && value <= set.Bottom_Right) // result = membership; // return result; // case "<":// // if (value < set.Bottom_Left) // result = 1; // return result; // case ">": // if (value > set.Bottom_Right) // result = 1; // return result; // case "<=": // if (value < set.Bottom_Right) // result = 1;//select // if (value >= set.Bottom_Left && value <= set.Bottom_Right) // result = membership; // return result; // case ">=": // if (value > set.Bottom_Left) // result = 1;//select // if (value >= set.Bottom_Left && value <= set.Bottom_Right) // result = membership; // return result; // case "=": // if (value >= set.Bottom_Left && value <= set.Bottom_Right) // result = membership; // return result; // case "!="://No need to get the membership // if (value <= set.Bottom_Left || value >= set.Bottom_Right) // result = 1;//selet the tuple // return result; // } // return result; //} private Double FuzzyCompare(Double value, ConFS set, String opr) { Double result = 0; Double membership = set.GetMembershipAt(value); switch (opr) { case "→": if (value >= set.Bottom_Left && value <= set.Bottom_Right) result = membership; return result; case "<":// if (value < set.Bottom_Left) result = 1; return result; case ">": if (value > set.Bottom_Right) result = 1; return result; case "<=": if (value < set.Bottom_Right) result = 1;//select if (value >= set.Bottom_Left && value <= set.Bottom_Right) result = membership; return result; case ">=": if (value > set.Bottom_Left) result = 1;//select if (value >= set.Bottom_Left && value <= set.Bottom_Right) result = membership; return result; case "=": if (value >= set.Bottom_Left && value <= set.Bottom_Right) result = membership; return result; case "!="://No need to get the membership if (value <= set.Bottom_Left || value >= set.Bottom_Right) result = 1;//selet the tuple return result; } return result; }
//Also content the path and name public ConFS ReadEachConFS(string path) { ConFS result = new ConFS(); try { using (StreamReader reader = new StreamReader(path)) { String str = reader.ReadLine(); String[] list = str.Split(','); //Only 4 members if (list.Length == 4) { result.Name = FuzzySetName(path); result.Bottom_Left = Double.Parse(list[0]); result.Top_Left = Double.Parse(list[1]); result.Top_Right = Double.Parse(list[2]); result.Bottom_Right = Double.Parse(list[3]); } } return result; } catch (Exception ex) { return null; } }