// TODO : Add constant function and trapeziodal private static IFuzzyFunction defineFunction(Match match) { string value = match.Groups[3].Value; string[] functionParameters = match.Groups[4].Value.Split(' '); NumberStyles numberStyles = NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign | NumberStyles.Float | NumberStyles.AllowThousands | NumberStyles.AllowExponent; if (value == "gaussmf") { GaussianFunction function = new GaussianFunction(); function.Center = Double.Parse(functionParameters[1].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.Steepness = Double.Parse(functionParameters[0].ToUpper(), numberStyles, CultureInfo.InvariantCulture); return(function); } else if (value == "trimf") { TriangleFunction function = new TriangleFunction(); function.LeftPoint = Double.Parse(functionParameters[0].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.MiddlePoint = Double.Parse(functionParameters[1].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.RightPoint = Double.Parse(functionParameters[2].ToUpper(), numberStyles, CultureInfo.InvariantCulture); return(function); } else if (value == "constant") { ConstantFunction function = new ConstantFunction(); function.ConstValue = Double.Parse(functionParameters[0].ToUpper(), numberStyles); return(function); } else if (value == "trapmf") { TrapezoidalFunction function = new TrapezoidalFunction(); function.LeftBottomPoint = Double.Parse(functionParameters[0].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.LeftTopPoint = Double.Parse(functionParameters[1].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.RightTopPoint = Double.Parse(functionParameters[2].ToUpper(), numberStyles, CultureInfo.InvariantCulture); function.RightBottomPoint = Double.Parse(functionParameters[3].ToUpper(), numberStyles, CultureInfo.InvariantCulture); return(function); } else { throw new FuzzyLogicException("Unknown function"); } }
private void OnAddTermBtnClick(object sender, RoutedEventArgs e) { float low, mid, high; try { low = System.Convert.ToSingle(textBox_lowVal.Text); mid = System.Convert.ToSingle(textBox_midVal.Text); high = System.Convert.ToSingle(textBox_highVal.Text); } catch (Exception) { MessageBox.Show("Input validate function data!"); return; } if (low > mid || mid > high) { MessageBox.Show("Incorrect values of triangle function!"); return; } if (string.IsNullOrEmpty(textBox_NameTerm.Text)) { MessageBox.Show("Input name of term!"); return; } string nameTerm = textBox_NameTerm.Text; TriangleFunction function = new TriangleFunction(low, mid, high); if (TermsList == null) { TermsList = new ObservableCollection <Term>(); //ListViewTerms.ItemsSource = TermsList; } TermsList.Add(new Term(nameTerm, function)); textBox_NameTerm.Text = null; //Console.WriteLine("terms list: "); //foreach (var item in TermsList) //{ // Console.WriteLine("name : {0}; functionName: {1};" , item.Name, item.Function.ToString()); //} }