private void TypeBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { // If Mamdani/Larsen selected if ((FuzzyType)e.AddedItems[0] == FuzzyType.Mamdani || (FuzzyType)e.AddedItems[0] == FuzzyType.Larsen) { if (FuzzySystem.StringToImpMethod(ImpBox.Text) == ImpMethodType.prod) { ImpBox.SelectedItem = ImpMethodType.min; } if (FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.wtaver || FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.wtsum) { DefuzzBox.SelectedItem = DefuzzMethodType.COG; } } // If Sugeno selected if ((FuzzyType)e.AddedItems[0] == FuzzyType.Sugeno) { if (FuzzySystem.StringToImpMethod(ImpBox.Text) == ImpMethodType.min || FuzzySystem.StringToImpMethod(ImpBox.Text) == ImpMethodType.max) { ImpBox.SelectedItem = ImpMethodType.prod; } if (FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.COA || FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.COG || FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.MOM || FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.LOM || FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text) == DefuzzMethodType.SOM) { DefuzzBox.SelectedItem = DefuzzMethodType.wtaver; } } }
private void InitializeFuzzySystem() { switch (FuzzySystem.StringToFuzzyType(TypeBox.Text)) { case FuzzyType.Mamdani: fuzzySystem = new MamdaniFS(); break; case FuzzyType.Larsen: fuzzySystem = new LarsenFS(); break; case FuzzyType.Sugeno: fuzzySystem = new SugenoFS(); break; case FuzzyType.Sparse: break; default: break; } //fuzzySystem = new FuzzySystem(); // Load fuzzysystem data fuzzySystem.Name = NameBox.Text; //fuzzySystem.Type = FuzzySystem.StringToFuzzyType(TypeBox.Text); fuzzySystem.Version = VersionBox.Text; fuzzySystem.AndMethod = FuzzySystem.StringToAndMethod(AndBox.Text); fuzzySystem.OrMethod = FuzzySystem.StringToOrMethod(OrBox.Text); fuzzySystem.AggMethod = FuzzySystem.StringToAggMethod(AggBox.Text); fuzzySystem.ImpMethod = FuzzySystem.StringToImpMethod(ImpBox.Text); fuzzySystem.DefuzzMethod = FuzzySystem.StringToDefuzzMethod(DefuzzBox.Text); // Set up the data and declare the arrays fuzzySystem.NumInputs = InputTemplates.Count; for (int i = 0; i < fuzzySystem.NumInputs; i++) { fuzzySystem.Inputs[i] = new InputOutput { Name = InputTemplates[i].Name, IsInput = true, Index = i + 1 }; } fuzzySystem.NumOutputs = OutputTemplates.Count; for (int i = 0; i < fuzzySystem.NumOutputs; i++) { fuzzySystem.Outputs[i] = new InputOutput { Name = OutputTemplates[i].Name, IsInput = false, Index = i + 1 }; } // Set the ranges and NumMF-s for (int inputId = 0; inputId < InputTemplates.Count; inputId++) { try { fuzzySystem.Inputs[inputId].Range = new float[] { float.Parse(InputTemplates[inputId].RangeMin.Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture), float.Parse(InputTemplates[inputId].RangeMax.Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture) }; } catch (Exception exc) { if (exc != null) { throw exc; } throw new Exception("Failed to read range from" + fuzzySystem.Inputs[inputId].Name); } if (fuzzySystem.Inputs[inputId].Range[0] >= fuzzySystem.Inputs[inputId].Range[1]) { throw new Exception("Incorrect range for" + fuzzySystem.Inputs[inputId].Name); } fuzzySystem.Inputs[inputId].NumMFs = InputTemplates[inputId].NumMF; } for (int outputId = 0; outputId < OutputTemplates.Count; outputId++) { try { fuzzySystem.Outputs[outputId].Range = new float[] { float.Parse(OutputTemplates[outputId].RangeMin.Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture), float.Parse(OutputTemplates[outputId].RangeMax.Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture) }; } catch (Exception exc) { if (exc != null) { throw exc; } throw new Exception("Failed to read range from" + fuzzySystem.Inputs[outputId].Name); } if (fuzzySystem.Outputs[outputId].Range[0] >= fuzzySystem.Outputs[outputId].Range[1]) { throw new Exception("Incorrect range for" + fuzzySystem.Inputs[outputId].Name); //MessageBox.Show("Incorrect range for " + fuzzySystem.Outputs[outputId].Name, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } fuzzySystem.Outputs[outputId].NumMFs = OutputTemplates[outputId].NumMF; } fuzzySystem.GenerateTrapezoidMFs(1.0f / 3.0f, true, fuzzySystem.Type != FuzzyType.Sugeno); //if (fuzzySystem.Type == FuzzyType.Sugeno) //fuzzySystem.GenerateConstantOutputMFs(); }