Exemplo n.º 1
0
        public FuzzyTermSet AddTriangularSet(string name, double min, double peak, double max)
        {
            FuzzyTermSet set = new FuzzyTermSet(name);

            set.Set = new TriangularSet(min, peak, max);
            MemberSets.Add(name, set);
            return(set);
        }
Exemplo n.º 2
0
        public FuzzyTermSet AddRightShoulderSet(string name, double min, double peak, double max)
        {
            FuzzyTermSet set = new FuzzyTermSet(name);

            set.Set = new RightShoulderSet(min, peak, max);
            MemberSets.Add(name, set);
            return(set);
        }
Exemplo n.º 3
0
        public double Defuzzify(string flvName, DefuzzifyType type)
        {
            // Clear DOMs of all consequents.
            SetConfidencesOfConsequentsToZero();

            for (int i = 0; i < Rules.Count; i++)
            {
                Console.WriteLine($"{Rules[i]}");
                Rules[i].Calculate();
            }

            Console.WriteLine();

            // custom code - get maximum consequences of ruleset
            // it's trash though, fix later
            // uses the MaxAV method using pure garbage code that.. works
            // pointers and C# just don't mix...

            List <OutputSet> outputSet = new List <OutputSet>();

            for (int i = 0; i < Rules.Count; i++)
            {
                FuzzyTermSet consequence = (FuzzyTermSet)Rules[i].Consequence;
                string       name        = consequence.VariableName;
                double       value       = consequence.GetDOM();
                double       represents  = consequence.Set.Represents;

                if (outputSet.Exists(os => os.Name == name))
                {
                    outputSet.Find(os => os.Name == name).SetMax(value);
                }
                else
                {
                    outputSet.Add(new OutputSet(name, value, represents));
                }
            }

            double calculatedMaxAV = 0.0;
            double divisor         = 0.0;

            foreach (OutputSet set in outputSet)
            {
                calculatedMaxAV += (set.RepresentativeValue * set.Value);
                divisor         += set.Value;
            }
            calculatedMaxAV /= divisor;
            return(calculatedMaxAV);
        }
Exemplo n.º 4
0
        public static FuzzyModule GazelleWannaRun(FuzzyModule gazelleFuzzyModule)
        {
            // Get the antecedents
            FuzzyVariable hunger   = gazelleFuzzyModule.GetVariable("Hunger");
            FuzzyTermSet  Full     = new FuzzyTermSet(hunger.MemberSets["Full"]);
            FuzzyTermSet  CouldEat = new FuzzyTermSet(hunger.MemberSets["CouldEat"]);
            FuzzyTermSet  Hungry   = new FuzzyTermSet(hunger.MemberSets["Hungry"]);

            FuzzyVariable distanceToEnemy = gazelleFuzzyModule.GetVariable("DistanceToEnemy");
            FuzzyTermSet  Close           = new FuzzyTermSet(distanceToEnemy.MemberSets["Close"]);
            FuzzyTermSet  Middle          = new FuzzyTermSet(distanceToEnemy.MemberSets["Middle"]);
            FuzzyTermSet  Far             = new FuzzyTermSet(distanceToEnemy.MemberSets["Far"]);

            // Create the consequent
            FuzzyVariable run = gazelleFuzzyModule.CreateFLV("RunDesirability");

            FuzzyTermSet Undesirable   = run.AddLeftShoulderSet("Undesirable", 0, 30, 40);
            FuzzyTermSet Desirable     = run.AddTrapezoidSet("Desirable", 30, 40, 60, 70);
            FuzzyTermSet VeryDesirable = run.AddRightShoulderSet("VeryDesirable", 60, 70, 150);

            // We need 9 of these with HUNGER + DISTANCE = DESIRABILITY
            //          Close      Middle     Far
            // Full       VD         D         UD
            // CouldEat   VD         UD        UD
            // Hungry     VD         UD        UD

            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Full, Close), VeryDesirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Full, Middle), Desirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Full, Far), Undesirable);

            gazelleFuzzyModule.AddRule(new FuzzyTermAND(CouldEat, Close), VeryDesirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(CouldEat, Middle), Undesirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(CouldEat, Far), Undesirable);

            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Hungry, Close), VeryDesirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Hungry, Middle), Undesirable);
            gazelleFuzzyModule.AddRule(new FuzzyTermAND(Hungry, Far), Undesirable);

            return(gazelleFuzzyModule);
        }
Exemplo n.º 5
0
 public static void add_rule(FuzzyModule module, FuzzyTermSet IF, FuzzyTermSet AND, FuzzyTermSet THEN) => module.AddRule(new FuzzyAND(IF, AND), THEN);
Exemplo n.º 6
0
 public FuzzyTermSet(FuzzyTermSet fts)
 {
     _fuzzSet = fts._fuzzSet;
 }