private void button2_Click(object sender, EventArgs e) { try { Double[] universo = new Double[2]; Double[] suporte = new Double[2]; Double[] nucleo = new Double[2]; Double valor; universo[0] = Convert.ToDouble(txtUni1.Text); universo[1] = Convert.ToDouble(txtUni2.Text); suporte[0] = Convert.ToDouble(txtSup1.Text); suporte[1] = Convert.ToDouble(txtSup2.Text); nucleo[0] = Convert.ToDouble(txtNuc1.Text); nucleo[1] = Convert.ToDouble(txtNuc2.Text); valor = Convert.ToDouble(txtValue.Text); FuzzyAlgorithm fuzzy = new FuzzyAlgorithm(universo, suporte, nucleo, valor); lblResultado.Text = "PertinĂȘncia: " + fuzzy.getRelevance.ToString("###,##0.0000"); } catch (Exception exc) { lblResultado.Text = "Erro: " + exc.Message; } }
public static int GetDistances(string s, string t, FuzzyAlgorithm algorithm = FuzzyAlgorithm.LevenshteinDistance) { int distance = 100000; switch (algorithm) { case FuzzyAlgorithm.LevenshteinDistance: distance = LevenshteinDistance.GetLevenshteinDistance(s, t); break; case FuzzyAlgorithm.DamerauLevenshteinDistance: distance = DamerauLevenshteinDistance.GetDamerauLevenshteinDistance(s, t); break; case FuzzyAlgorithm.HammingDistance: distance = HammingDistance.GetHammingDistance(s, t); break; default: distance = LevenshteinDistance.GetLevenshteinDistance(s, t); break; } return(distance); }
private void fuzzyfication() { double percent = 0; FuzzyAlgorithm fuzzy = new FuzzyAlgorithm(); double value = 0; string operador = ""; XmlDocument doc = new XmlDocument(); doc.Load(FrmPrincipal.PATHRULESXML); XmlNodeList listNode = doc.SelectNodes("configuracao/regra"); pBar.Value = Convert.ToInt32(percent); foreach (XmlNode nodeR in listNode) { foreach (XmlNode node in nodeR.ChildNodes) { if (node.LocalName == "INICIA") { old = new Variable(); operador = ""; } else if (node.LocalName == "CLAUSULA") { value = getPertinence(fuzzy, listVariables, node.InnerText, operador); } else if (node.LocalName == "OPERADOR") { operador = node.InnerText; } else if (node.LocalName == "RESULTADO") { operador = ""; } else if (node.LocalName == "VALOR") { node.InnerText = value.ToString(); } } percent = (percent * 100) / listNode.Count; pBar.Value = Convert.ToInt32(percent); } doc.Save(FrmPrincipal.PATHRULESXML); pBar.Value = 100; MessageBox.Show("Calculo efetuado com sucesso!"); }
private Double getPertinence(FuzzyAlgorithm fuzzy, List <Variable> variables, string cmd, string op) { Variable variable = null; Term term = null; Double value; foreach (Variable v in variables) { if (v.name == cmd.Split('=')[0]) { variable = v; foreach (Term t in v.terms) { if (t.name == cmd.Split('=')[1]) { term = t; break; } } } } fuzzy.parameters(variable.universe, term.support, term.core, variable.insertValue); term.relevance = fuzzy.getRelevance; variable.rulesResult = term.relevance; if (old != null) { if (op == "E") { if (old.rulesResult > variable.rulesResult) { value = variable.rulesResult; } else { value = old.rulesResult; } } else if (op == "OU") { if (old.rulesResult > variable.rulesResult) { value = old.rulesResult; } else { value = variable.rulesResult; } } else { value = variable.rulesResult; } } else { value = variable.rulesResult; } old = variable; return(value); }
public static bool IsFuzzySimilar(this string input, string parameter, int fuzzyness = 3, FuzzyAlgorithm fuzzyAlgorithm = FuzzyAlgorithm.LevenshteinDistance) { if (string.IsNullOrEmpty(parameter)) { throw new ArgumentNullException($"parameter can't be empty or null"); } if (fuzzyness < 0) { throw new InvalidOperationException($"fuzzyness can't be less than 0"); } var string1 = ""; var string2 = ""; return((DistanceFactory.GetDistances(GetCanonicalForm(input), GetCanonicalForm(parameter)) < fuzzyness) || input.Contains(parameter) || parameter.Contains(input)); }