Esempio n. 1
0
        private void ParseVariables(string[] sparts, bool isAndRule)
        {
            bool       bant = true; // start with ant
            FuzzyValue vant1 = null, vant2 = null;
            FuzzyValue cont = null;
            string     Set, sValue;

            for (int i = 0; i < sparts.Length; i++)
            {
                if (string.Compare(sparts[i], "then", true) == 0)
                {
                    bant = false;
                    continue;
                }
                if (sparts[i].Contains(".") == false)
                {
                    continue;
                }
                ParseRuleString(sparts[i], out Set, out sValue);
                if (bant)
                {
                    if (vant1 == null)
                    {
                        vant1 = FindAntFuzzyValue(Set, sValue);
                    }
                    else
                    {
                        vant2 = FindAntFuzzyValue(Set, sValue);
                    }
                }
                else
                {
                    cont = FindContFuzzyValue(sValue);
                }
            }
            if (vant1 == null && vant2 == null)
            {
                throw new Exception("No Antecedents found!");
            }
            if (cont == null)
            {
                throw new Exception("No Consequent found!");
            }
            if (isAndRule)
            {
                AddNewAndRule(vant1, vant2, cont);
            }
            else
            {
                AddNewOrRule(vant1, vant2, cont);
            }
        }
Esempio n. 2
0
        public void AddNewOrRule(FuzzyValue ant1, FuzzyValue ant2, FuzzyValue cont)
        {
            FuzzyRuleOr r = new FuzzyRuleOr();

            if (ant1 != null)
            {
                r.Antecedents.Add(ant1);
            }
            if (ant2 != null)
            {
                r.Antecedents.Add(ant2);
            }
            r.Consequent = cont;
            Rules.Add(r);
        }
Esempio n. 3
0
        private FuzzyValue FindContFuzzyValue(string sValue)
        {
            FuzzyValue cont = null;

            foreach (var vv in Consequent.Values)
            {
                if (string.Compare(vv.Name, sValue, true) == 0)
                {
                    cont = vv;
                    break;
                }
            }
            if (cont == null)
            {
                throw new Exception("Value was not found!");
            }
            return(cont);
        }
Esempio n. 4
0
        // strings should be like this -> food.Rancid
        public void AddNewRule(string ant1, string ant2, string scont, bool UseAndRule = true)
        {
            string     Set, sValue;
            FuzzyValue vant1 = null, vant2 = null;

            if (ant1 != "none")
            {
                ParseRuleString(ant1, out Set, out sValue);
                vant1 = FindAntFuzzyValue(Set, sValue);
                if (vant1 == null)
                {
                    throw new Exception("Value was not found!");
                }
            }

            if (ant2 != "none")
            {
                ParseRuleString(ant2, out Set, out sValue);
                vant2 = FindAntFuzzyValue(Set, sValue);
                if (vant2 == null)
                {
                    throw new Exception("Value was not found!");
                }
            }

            ParseRuleString(scont, out Set, out sValue);
            if (Consequent.Name != Set)
            {
                throw new Exception("Wrong Set Name!");
            }
            FuzzyValue cont = FindContFuzzyValue(sValue);

            // finally call the previous method
            if (UseAndRule)
            {
                AddNewAndRule(vant1, vant2, cont);
            }
            else
            {
                AddNewOrRule(vant1, vant2, cont);
            }
        }
Esempio n. 5
0
 public void AddValue(FuzzyValue val)
 {
     _values.Add(val);
     val.Parent = this;
 }
Esempio n. 6
0
 public void ApplyMembers(FuzzyValue ant1, FuzzyValue ant2, FuzzyValue cont)
 {
     Antecedents.Add(ant1);
     Antecedents.Add(ant2);
     Consequent = cont;
 }