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(); }