Exemplo n.º 1
0
        private static RuleInferenceEngine GetInferenceEngine()
        {
            var rie = new RuleInferenceEngine();

            //Put rules here
            var positiveRule = new Rule("Positief");

            positiveRule.AddAntecedent(new GEClause("gewogen_gemiddelde", "16"));
            positiveRule.AddAntecedent(new GEClause("competenties", "6"));
            positiveRule.AddAntecedent(new GEClause("capaciteiten", "6"));
            positiveRule.AddAntecedent(new GEClause("intr. Motivatie", "7"));
            positiveRule.AddAntecedent(new GEClause("extr. Motivatie", "7"));
            positiveRule.AddAntecedent(new IsClause("is_mbo_deficient", "Nee"));
            positiveRule.AddAntecedent(new IsClause("Persoonlijk 'bijspijker'-advies", "0"));
            positiveRule.AddAntecedent(new IsClause("reden_stoppen", ""));
            positiveRule.setConsequent(new IsClause("advies", "Positief"));
            rie.AddRule(positiveRule);

            var doubtRule = new Rule("Twijfel");

            doubtRule.AddAntecedent(new GEClause("gewogen_gemiddelde", "12"));
            doubtRule.AddAntecedent(new LEClause("gewogen_gemiddelde", "15"));
            doubtRule.AddAntecedent(new IsClause("competenties", "5"));
            doubtRule.AddAntecedent(new IsClause("capaciteiten", "5"));
            doubtRule.AddAntecedent(new IsClause("intr. Motivatie", "5"));
            doubtRule.AddAntecedent(new IsClause("extr. Motivatie", "5"));
            doubtRule.AddAntecedent(new IsClause("Persoonlijk 'bijspijker'-advies", "1"));
            doubtRule.AddAntecedent(new IsClause("reden_stoppen", "Uitgeschreven voor opleiding."));
            doubtRule.setConsequent(new IsClause("advies", "Twijfel"));
            rie.AddRule(doubtRule);

            var negativeRule = new Rule("Negatief");

            negativeRule.AddAntecedent(new LEClause("gewogen_gemiddelde", "11"));
            negativeRule.AddAntecedent(new LEClause("competenties", "4"));
            negativeRule.AddAntecedent(new LEClause("capaciteiten", "4"));
            negativeRule.AddAntecedent(new LEClause("intr. Motivatie", "4"));
            negativeRule.AddAntecedent(new LEClause("extr. Motivatie", "4"));
            negativeRule.AddAntecedent(new IsClause("Persoonlijk 'bijspijker'-advies", "0"));
            negativeRule.AddAntecedent(new IsClause("reden_stoppen", "Uitgeschreven voor opleiding."));
            negativeRule.setConsequent(new IsClause("advies", "Negatief"));
            rie.AddRule(negativeRule);

            return(rie);
        }
Exemplo n.º 2
0
        static private RuleInferenceEngine getInferenceEngine()
        {
            RuleInferenceEngine rie = new RuleInferenceEngine();

            Rule rule = new Rule(Bicycle);

            rule.AddAntecedent(new ClauseIs("vehicleType", "cycle"));
            rule.AddAntecedent(new ClauseIs("num_wheels", "2"));
            rule.AddAntecedent(new ClauseIs("motor", "no"));
            rule.Consequent = new ClauseIs("vehicle", Bicycle);
            rie.AddRule(rule);

            rule = new Rule(Tricycle);
            rule.AddAntecedent(new ClauseIs("vehicleType", "cycle"));
            rule.AddAntecedent(new ClauseIs("num_wheels", "3"));
            rule.AddAntecedent(new ClauseIs("motor", "no"));
            rule.Consequent = new ClauseIs("vehicle", Tricycle);
            rie.AddRule(rule);

            rule = new Rule(Motorcycle);
            rule.AddAntecedent(new ClauseIs("vehicleType", "cycle"));
            rule.AddAntecedent(new ClauseIs("num_wheels", "2"));
            rule.AddAntecedent(new ClauseIs("motor", "yes"));
            rule.Consequent = new ClauseIs("vehicle", Motorcycle);
            rie.AddRule(rule);

            rule = new Rule(SportsCar);
            rule.AddAntecedent(new ClauseIs("vehicleType", "automobile"));
            rule.AddAntecedent(new ClauseIs("size", "medium"));
            rule.AddAntecedent(new ClauseIs("num_doors", "2"));
            rule.Consequent = new ClauseIs("vehicle", SportsCar);
            rie.AddRule(rule);

            rule = new Rule(Sedan);
            rule.AddAntecedent(new ClauseIs("vehicleType", "automobile"));
            rule.AddAntecedent(new ClauseIs("size", "medium"));
            rule.AddAntecedent(new ClauseIs("num_doors", "4"));
            rule.Consequent = new ClauseIs("vehicle", Sedan);
            rie.AddRule(rule);

            rule = new Rule(MiniVan);
            rule.AddAntecedent(new ClauseIs("vehicleType", "automobile"));
            rule.AddAntecedent(new ClauseIs("size", "medium"));
            rule.AddAntecedent(new ClauseIs("num_doors", "3"));
            rule.Consequent = new ClauseIs("vehicle", MiniVan);
            rie.AddRule(rule);

            rule = new Rule(SUV);
            rule.AddAntecedent(new ClauseIs("vehicleType", "automobile"));
            rule.AddAntecedent(new ClauseIs("size", "large"));
            rule.AddAntecedent(new ClauseIs("num_doors", "4"));
            rule.Consequent = new ClauseIs("vehicle", SUV);
            rie.AddRule(rule);

            rule = new Rule(Cycle);
            rule.AddAntecedent(new ClauseLt("num_wheels", "4"));
            rule.Consequent = new ClauseIs("vehicleType", "cycle");
            rie.AddRule(rule);

            rule = new Rule(Automobile);
            rule.AddAntecedent(new ClauseIs("num_wheels", "4"));
            rule.AddAntecedent(new ClauseIs("motor", "yes"));
            rule.Consequent = new ClauseIs("vehicleType", "automobile");
            rie.AddRule(rule);

            return(rie);
        }
Exemplo n.º 3
0
        private RuleInferenceEngine getInferenceEngine()
        {
            RuleInferenceEngine rie = new RuleInferenceEngine();

            Rule rule = new Rule("Bicycle");

            rule.AddAntecedent(new IsClause("vehicleType", "cycle"));
            rule.AddAntecedent(new IsClause("num_wheels", "2"));
            rule.AddAntecedent(new IsClause("motor", "no"));
            rule.setConsequent(new IsClause("vehicle", "Bicycle"));
            rie.AddRule(rule);

            rule = new Rule("Tricycle");
            rule.AddAntecedent(new IsClause("vehicleType", "cycle"));
            rule.AddAntecedent(new IsClause("num_wheels", "3"));
            rule.AddAntecedent(new IsClause("motor", "no"));
            rule.setConsequent(new IsClause("vehicle", "Tricycle"));
            rie.AddRule(rule);

            rule = new Rule("Motorcycle");
            rule.AddAntecedent(new IsClause("vehicleType", "cycle"));
            rule.AddAntecedent(new IsClause("num_wheels", "2"));
            rule.AddAntecedent(new IsClause("motor", "yes"));
            rule.setConsequent(new IsClause("vehicle", "Motorcycle"));
            rie.AddRule(rule);

            rule = new Rule("SportsCar");
            rule.AddAntecedent(new IsClause("vehicleType", "automobile"));
            rule.AddAntecedent(new IsClause("size", "medium"));
            rule.AddAntecedent(new IsClause("num_doors", "2"));
            rule.setConsequent(new IsClause("vehicle", "Sports_Car"));
            rie.AddRule(rule);

            rule = new Rule("Sedan");
            rule.AddAntecedent(new IsClause("vehicleType", "automobile"));
            rule.AddAntecedent(new IsClause("size", "medium"));
            rule.AddAntecedent(new IsClause("num_doors", "4"));
            rule.setConsequent(new IsClause("vehicle", "Sedan"));
            rie.AddRule(rule);

            rule = new Rule("MiniVan");
            rule.AddAntecedent(new IsClause("vehicleType", "automobile"));
            rule.AddAntecedent(new IsClause("size", "medium"));
            rule.AddAntecedent(new IsClause("num_doors", "3"));
            rule.setConsequent(new IsClause("vehicle", "MiniVan"));
            rie.AddRule(rule);

            rule = new Rule("SUV");
            rule.AddAntecedent(new IsClause("vehicleType", "automobile"));
            rule.AddAntecedent(new IsClause("size", "large"));
            rule.AddAntecedent(new IsClause("num_doors", "4"));
            rule.setConsequent(new IsClause("vehicle", "SUV"));
            rie.AddRule(rule);

            rule = new Rule("Cycle");
            rule.AddAntecedent(new LessClause("num_wheels", "4"));
            rule.setConsequent(new IsClause("vehicleType", "cycle"));
            rie.AddRule(rule);

            rule = new Rule("Automobile");
            rule.AddAntecedent(new IsClause("num_wheels", "4"));
            rule.AddAntecedent(new IsClause("motor", "yes"));
            rule.setConsequent(new IsClause("vehicleType", "automobile"));
            rie.AddRule(rule);

            return(rie);
        }
Exemplo n.º 4
0
        private void btnFuzzy_Click(object sender, EventArgs e)
        {
            RuleInferenceEngine rie = new RuleInferenceEngine();

            FuzzySet output = new FuzzySet("Output", -100, 100, 1);

            output.AddMembership("Cooling", new FuzzyReverseGrade(-50, 0));
            output.AddMembership("Zero", new FuzzyTriangle(-50, 0, 50));
            output.AddMembership("Heating", new FuzzyGrade(0, 50));
            rie.AddFuzzySet(output.Name, output);

            FuzzySet tempError = new FuzzySet("Temperature Error", -4, 4, 0.05);

            tempError.AddMembership("Negative", new FuzzyReverseGrade(-2, 0));
            tempError.AddMembership("Zero", new FuzzyTriangle(-2, 0, 2));
            tempError.AddMembership("Positive", new FuzzyGrade(0, 2));
            rie.AddFuzzySet(tempError.Name, tempError);


            FuzzySet tempErrorDot = new FuzzySet("Temperature Error", -10, 10, 0.1);

            tempErrorDot.AddMembership("Negative", new FuzzyReverseGrade(-5, 0));
            tempErrorDot.AddMembership("Zero", new FuzzyTriangle(-5, 0, 5));
            tempErrorDot.AddMembership("Positive", new FuzzyGrade(0, 5));
            rie.AddFuzzySet(tempErrorDot.Name, tempErrorDot);

            /*
             *      1. If (e < 0) AND (er < 0) then Cool 0.5 & 0.0 = 0.0
             *      2. If (e = 0) AND (er < 0) then Heat 0.5 & 0.0 = 0.0
             *      3. If (e > 0) AND (er < 0) then Heat 0.0 & 0.0 = 0.0
             *      4. If (e < 0) AND (er = 0) then Cool 0.5 & 0.5 = 0.5
             *      5. If (e = 0) AND (er = 0) then No_Chng 0.5 & 0.5 = 0.5
             *      6. If (e > 0) AND (er = 0) then Heat 0.0 & 0.5 = 0.0
             *      7. If (e < 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5
             *      8. If (e = 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5
             *      9. If (e > 0) AND (er > 0) then Heat 0.0 & 0.5 = 0.0
             */

            Rule rule = new Rule("Rule 1");

            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 2");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Fuzzy.Rule("Rule 3");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Rule("Rule 4");
            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 5");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Zero");
            rie.AddRule(rule);

            rule = new Rule("Rule 6");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Rule("Rule 7");
            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 8");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 9");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            tempError.X = -1.0;
            Console.WriteLine("For Temperature Error: {0}", tempError.X);
            Console.WriteLine("Negative: " + tempError.GetMembership("Negative").degree(-1.0));
            Console.WriteLine("Zero: " + tempError.GetMembership("Zero").degree(-1.0));
            Console.WriteLine("Positive: " + tempError.GetMembership("Positive").degree(-1.0));

            tempErrorDot.X = 2.5;
            Console.WriteLine("For Temperature Error Dot: {0}", tempErrorDot.X);
            Console.WriteLine("Negative: " + tempErrorDot.GetMembership("Negative").degree(2.5));
            Console.WriteLine("Zero: " + tempErrorDot.GetMembership("Zero").degree(2.5));
            Console.WriteLine("Positive: " + tempErrorDot.GetMembership("Positive").degree(2.5));

            rie.Infer(output);

            Console.WriteLine("output: " + output.X);



            FrmFuzzySet tempCanvas         = new FrmFuzzySet("Output", output);
            FrmFuzzySet tempErrorCanvas    = new FrmFuzzySet("Temp Error", tempError);
            FrmFuzzySet tempErrorDotCanvas = new FrmFuzzySet("Temp Error Dot", tempErrorDot);

            tempCanvas.Show();
            tempErrorCanvas.Show();
            tempErrorDotCanvas.Show();
        }
Exemplo n.º 5
0
        public void Run()
        {
            RuleInferenceEngine rie = new RuleInferenceEngine();

            FuzzySet output = new FuzzySet("Output", -100, 100, 1);

            output.AddMembership("Cooling", new FuzzyReverseGrade(-50, 0));
            output.AddMembership("Zero", new FuzzyTriangle(-50, 0, 50));
            output.AddMembership("Heating", new FuzzyGrade(0, 50));
            rie.AddFuzzySet(output.Name, output);

            FuzzySet tempError = new FuzzySet("Temperature Error", -4, 4, 0.05);

            tempError.AddMembership("Negative", new FuzzyReverseGrade(-2, 0));
            tempError.AddMembership("Zero", new FuzzyTriangle(-2, 0, 2));
            tempError.AddMembership("Positive", new FuzzyGrade(0, 2));
            rie.AddFuzzySet(tempError.Name, tempError);


            FuzzySet tempErrorDot = new FuzzySet("Temperature Error", -10, 10, 0.1);

            tempErrorDot.AddMembership("Negative", new FuzzyReverseGrade(-5, 0));
            tempErrorDot.AddMembership("Zero", new FuzzyTriangle(-5, 0, 5));
            tempErrorDot.AddMembership("Positive", new FuzzyGrade(0, 5));
            rie.AddFuzzySet(tempErrorDot.Name, tempErrorDot);

            /*
             *      1. If (e < 0) AND (er < 0) then Cool 0.5 & 0.0 = 0.0
             *      2. If (e = 0) AND (er < 0) then Heat 0.5 & 0.0 = 0.0
             *      3. If (e > 0) AND (er < 0) then Heat 0.0 & 0.0 = 0.0
             *      4. If (e < 0) AND (er = 0) then Cool 0.5 & 0.5 = 0.5
             *      5. If (e = 0) AND (er = 0) then No_Chng 0.5 & 0.5 = 0.5
             *      6. If (e > 0) AND (er = 0) then Heat 0.0 & 0.5 = 0.0
             *      7. If (e < 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5
             *      8. If (e = 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5
             *      9. If (e > 0) AND (er > 0) then Heat 0.0 & 0.5 = 0.0
             */

            Rule rule = new Rule("Rule 1");

            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 2");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Rule("Rule 3");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Rule("Rule 4");
            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 5");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Zero");
            rie.AddRule(rule);

            rule = new Rule("Rule 6");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            rule = new Rule("Rule 7");
            rule.AddAntecedent(new Clause(tempError, "Is", "Negative"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 8");
            rule.AddAntecedent(new Clause(tempError, "Is", "Zero"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Cooling");
            rie.AddRule(rule);

            rule = new Rule("Rule 9");
            rule.AddAntecedent(new Clause(tempError, "Is", "Positive"));
            rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive"));
            rule.Consequent = new Clause(output, "Is", "Heating");
            rie.AddRule(rule);

            tempError.X = -1.0;
            WriteLine("For Temperature Error: {0}", tempError.X);
            WriteLine("Negative: " + tempError.GetMembership("Negative").degree(-1.0));
            WriteLine("Zero: " + tempError.GetMembership("Zero").degree(-1.0));
            WriteLine("Positive: " + tempError.GetMembership("Positive").degree(-1.0));

            tempErrorDot.X = 2.5;
            WriteLine("For Temperature Error Dot: {0}", tempErrorDot.X);
            WriteLine("Negative: " + tempErrorDot.GetMembership("Negative").degree(2.5));
            WriteLine("Zero: " + tempErrorDot.GetMembership("Zero").degree(2.5));
            WriteLine("Positive: " + tempErrorDot.GetMembership("Positive").degree(2.5));

            rie.Infer(output);

            WriteLine("output: " + output.X);


            /*
             * Application.EnableVisualStyles();
             * Application.SetCompatibleTextRenderingDefault(false);
             *
             *
             * FrmFuzzySet tempCanvas = new FrmFuzzySet("Output", output);
             * FrmFuzzySet tempErrorCanvas = new FrmFuzzySet("Temp Error", tempError);
             * FrmFuzzySet tempErrorDotCanvas = new FrmFuzzySet("Temp Error Dot", tempErrorDot);
             *
             * SimpleUI.Instance.Display(tempCanvas);
             * SimpleUI.Instance.Display(tempErrorCanvas);
             * SimpleUI.Instance.Display(tempErrorDotCanvas);
             *
             * Application.Run(SimpleUI.Instance.View);*/
        }