public LinguisticVariable(LinguisticVariableParameters par) { name = par.Name; x = par.range; H = par.Labels.ToArray(); G = new IMembershipFunction[par.memberShipFunction.Count]; for (int i = 0; i < par.memberShipFunction.Count; i++) { var mFunction = par.memberShipFunction[i]; mFunction = mFunction.Remove(mFunction.Length - 1, 1); var mFunctionArray = mFunction.Split('('); var args = new List <string>(); foreach (var v in mFunctionArray[1].Split(',')) { args.Add(v); } switch (mFunctionArray[0]) { case "triangle": var triangle1 = double.Parse(args[0]); var triangle2 = double.Parse(args[1]); var triangle3 = double.Parse(args[2]); G[i] = new TriangleMembershipFunction(triangle1, triangle2, triangle3); break; case "trapezoid": var trapezoid1 = double.Parse(args[0]); var trapezoid2 = double.Parse(args[1]); var trapezoid3 = double.Parse(args[2]); var trapezoid4 = double.Parse(args[3]); G[i] = new TrapezoidMembershipFunction(trapezoid1, trapezoid2, trapezoid3, trapezoid4); break; case "classic": var classic1 = args[0]; var classic2 = double.Parse(args[1]); G[i] = new ClassicMembershipFunction(classic1, classic2); break; case "gauss": var gauss1 = double.Parse(args[0]); var gauss2 = double.Parse(args[1]); G[i] = new GaussMembershipFunction(gauss1, gauss2); break; } } }
/// <summary> /// Handles the Click event of the ButtonAddTerm control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void ButtonAddTerm_Click(object sender, EventArgs e) { var term = new TermModel(this.textBoxTermName.Text.ToString()); if (this.comboBoxVariableForm.SelectedItem == null || string.IsNullOrEmpty(term.Name)) { return; } IMembershipFunction function = null; if (this.comboBoxVariableForm.SelectedItem.Equals("Triangle")) { // TODO: Make validation for entered values. function = new TriangleMembershipFunction { Left = Int32.Parse(this.textBoxTriangleLeft.Text), Middle = Int32.Parse(this.textBoxTriangleMiddle.Text), Right = Int32.Parse(this.textBoxTriangleRight.Text) }; } else if (this.comboBoxVariableForm.SelectedItem.Equals("Gauss")) { // TODO: Make validation function = new GaussMembershipFunction { B = Int32.Parse(this.textBoxGaussB.Text), C = Int32.Parse(this.textBoxGaussC.Text) }; } term.Function = function; /// Checks if term was edited or created new one. if (this.newFuzzyVariable.Terms.Any(t => t.Name.Equals(this.textBoxTermName.Text.ToString()))) { int termIndex = this.newFuzzyVariable.Terms.FindIndex(t => t.Name.Equals(this.textBoxTermName.Text)); this.newFuzzyVariable.Terms[termIndex] = term; } else { this.newFuzzyVariable.Terms.Add(term); } this.ClearTermField(); this.UpdateListBox(); this.UpdateChart(term); }