コード例 #1
0
 public void setFuzzyEngine()
 {
     traf = new FuzzyEngine();
     traf.LinguisticVariableCollection.Add(_tex);
     traf.LinguisticVariableCollection.Add(_spi);
     traf.LinguisticVariableCollection.Add(_ss);
     traf.FuzzyRuleCollection = _rules;
 }
コード例 #2
0
    static public string BuildCellModel()
    {
        LinguisticVariable nourishment = new LinguisticVariable("Nourishment");

        nourishment.MembershipFunctionCollection.Add(new MembershipFunction("Hungry", 0, 0, 20, 40));
        nourishment.MembershipFunctionCollection.Add(new MembershipFunction("Nominal", 30, 50, 50, 70));
        nourishment.MembershipFunctionCollection.Add(new MembershipFunction("Bloated", 50, 80, 100, 100));

        LinguisticVariable health = new LinguisticVariable("Health");

        health.MembershipFunctionCollection.Add(new MembershipFunction("Sick", 0, 0, 10, 20));
        health.MembershipFunctionCollection.Add(new MembershipFunction("Functional", 10, 20, 40, 50));
        health.MembershipFunctionCollection.Add(new MembershipFunction("Healthy", 40, 50, 70, 80));
        health.MembershipFunctionCollection.Add(new MembershipFunction("Sporty", 70, 80, 100, 100));

        LinguisticVariable shelter = new LinguisticVariable("Shelter");

        shelter.MembershipFunctionCollection.Add(new MembershipFunction("Shacks", 0, 0, 10, 20));
        shelter.MembershipFunctionCollection.Add(new MembershipFunction("Barebones", 10, 20, 40, 50));
        shelter.MembershipFunctionCollection.Add(new MembershipFunction("Confortable", 40, 50, 70, 80));
        shelter.MembershipFunctionCollection.Add(new MembershipFunction("Luxorious", 70, 80, 100, 100));

        LinguisticVariable trust = new LinguisticVariable("Trust");

        trust.MembershipFunctionCollection.Add(new MembershipFunction("Hate", 0, 0, 20, 40));
        trust.MembershipFunctionCollection.Add(new MembershipFunction("Meh", 30, 50, 50, 70));
        trust.MembershipFunctionCollection.Add(new MembershipFunction("Awe", 50, 80, 100, 100));

        LinguisticVariable mood = new LinguisticVariable("Mood");

        mood.MembershipFunctionCollection.Add(new MembershipFunction("Angry", 0, 0, 10, 20));
        mood.MembershipFunctionCollection.Add(new MembershipFunction("Pissed", 10, 20, 40, 50));
        mood.MembershipFunctionCollection.Add(new MembershipFunction("OK", 40, 50, 70, 80));
        mood.MembershipFunctionCollection.Add(new MembershipFunction("Happy", 70, 80, 100, 100));

        FuzzyEngine fuzzyEngine = new FuzzyEngine();

        fuzzyEngine.LinguisticVariableCollection.Add(nourishment);
        //fuzzyEngine.LinguisticVariableCollection.Add(peacefulness);
        fuzzyEngine.LinguisticVariableCollection.Add(mood);

        fuzzyEngine.Consequent = "Mood";

        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Nourishment IS Bloated) AND (Peacefulness IS Low) THEN Mood IS Pissed"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Nourishment IS Bloated) AND (Peacefulness IS High) THEN Mood IS OK"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Nourishment IS Nominal) AND (Peacefulness IS Low) THEN Mood IS Angry"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Nourishment IS Nominal) AND (Peacefulness IS High) THEN Mood IS Happy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Nourishment IS Hungry) THEN Mood IS Angry"));

        nourishment.InputValue = 5;
        //peacefulness.InputValue = 80;

        double angryness = fuzzyEngine.Defuzzify();

        mood.InputValue = angryness;
        return(mood.Fuzzify() + " (" + angryness.ToString() + ")");
    }
コード例 #3
0
 public void SetUp()
 {
     PrepareProfileRepository();
     PrepareKnowledgeBaseManager();
     PrepareInitialDataProvider();
     _fuzzyEngine    = new FuzzyEngine();
     _inferenceGraph = new InferenceGraph();
     _fuzzyExpert    = new Application.InferenceExpert.Implementations.FuzzyExpert(
         _initialDataProvider, _knowledgeBaseManager, _inferenceGraph, _fuzzyEngine);
 }
コード例 #4
0
        private void btnModelYukle_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.FileName = "*.Xml";
            if (op.ShowDialog() == DialogResult.OK)
            {
                fengine = new FuzzyEngine();
                fengine.Load(op.FileName);
            }
        }
コード例 #5
0
ファイル: Form1.cs プロジェクト: genepaulz/MyFuzzy
        public void setFuzzyEngine()
        {
            fe0 = new FuzzyEngine();
            fe0.LinguisticVariableCollection.Add(myhottank);
            fe0.LinguisticVariableCollection.Add(mythottank);
            fe0.LinguisticVariableCollection.Add(myheat);
            fe0.FuzzyRuleCollection = myhrules;

            fe1 = new FuzzyEngine();
            fe1.LinguisticVariableCollection.Add(mycoldtank);
            fe1.LinguisticVariableCollection.Add(mytcoldtank);
            fe1.LinguisticVariableCollection.Add(mycold);
            fe1.FuzzyRuleCollection = mycrules;
        }
コード例 #6
0
    //  initiate fuzzy engine and load xml data
    private void loadFuzzy()
    {
        fuzzyEngineLoad    = new FuzzyEngine();
        fuzzyEngineIdle    = new FuzzyEngine();
        fuzzyEngineOffLow  = new FuzzyEngine();
        fuzzyEngineOffMid  = new FuzzyEngine();
        fuzzyEngineOffHigh = new FuzzyEngine();
        fuzzyEngineOnLow   = new FuzzyEngine();
        fuzzyEngineOnMid   = new FuzzyEngine();
        fuzzyEngineOnHigh  = new FuzzyEngine();

        fuzzyEngineLoad.Load("engineLoad2");
        fuzzyEngineIdle.Load("engineVolIdle");
        fuzzyEngineOffLow.Load("engineVolOffLow");
        fuzzyEngineOffMid.Load("engineVolOffMid");
        fuzzyEngineOffHigh.Load("engineVolOffHigh");
        fuzzyEngineOnLow.Load("engineVolOnLow");
        fuzzyEngineOnMid.Load("engineVolOnMid");
        fuzzyEngineOnHigh.Load("engineVolOnHigh");
    }
コード例 #7
0
        public void CoG_Trap_Defuzzify_WrongType()
        {
            //Arrange
            LinguisticVariable water = new LinguisticVariable("Water");
            var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 40, 70);
            var hot  = water.MembershipFunctions.AddTrapezoid("Hot", 70, 100, 120, 120);

            LinguisticVariable power = new LinguisticVariable("Power");
            var low  = power.MembershipFunctions.AddGaussian("Low", 20, 20);
            var high = power.MembershipFunctions.AddTriangle("High", 50, 100, 150);


            IFuzzyEngine fuzzyEngine = new FuzzyEngine(new TrapezoidCoGDefuzzification());

            fuzzyEngine.Rules.If(water.Is(cold)).Then(power.Is(high));
            fuzzyEngine.Rules.If(water.Is(hot)).Then(power.Is(low));

            //Act
            var result = fuzzyEngine.Defuzzify(new { water = 60 });

            //Assert
        }
コード例 #8
0
        public void FuzzyEngine_InvalidInputs_Success()
        {
            //Arrange
            LinguisticVariable water = new LinguisticVariable("Water");
            var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40);
            var warm = water.MembershipFunctions.AddTriangle("Warm", 30, 50, 70);
            var hot  = water.MembershipFunctions.AddTrapezoid("Hot", 50, 80, 100, 100);

            LinguisticVariable power = new LinguisticVariable("Power");
            var low  = power.MembershipFunctions.AddTriangle("Low", 0, 25, 50);
            var high = power.MembershipFunctions.AddTriangle("High", 25, 50, 75);


            IFuzzyEngine fuzzyEngine = new FuzzyEngine(new CoGDefuzzification());

            fuzzyEngine.Rules.If(water.Is(hot)).Then(power.Is(high));

            //Act
            var result = fuzzyEngine.Defuzzify(new { water = "invalid input" });

            //Assert
        }
コード例 #9
0
        public void CoG_Trap_Defuzzify_ZeroDemonenator_Success()
        {
            //Arrange
            LinguisticVariable water = new LinguisticVariable("Water");
            var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 40, 50);
            var hot  = water.MembershipFunctions.AddTrapezoid("Hot", 70, 80, 100, 100);

            LinguisticVariable power = new LinguisticVariable("Power");
            var low  = power.MembershipFunctions.AddTriangle("Low", 0, 20, 40);
            var high = power.MembershipFunctions.AddTriangle("High", 50, 100, 150);


            IFuzzyEngine fuzzyEngine = new FuzzyEngine(new TrapezoidCoGDefuzzification());

            fuzzyEngine.Rules.If(water.Is(cold)).Then(power.Is(high));
            fuzzyEngine.Rules.If(water.Is(hot)).Then(power.Is(low));

            //Act
            var result = fuzzyEngine.Defuzzify(new { water = 60 });

            //Assert
            Assert.That(result, Is.EqualTo(0), "result");
        }
コード例 #10
0
        public void MoM_Defuzzify2_Success(Int32 waterInputValue, Double expectedValue)
        {
            //Arrange
            LinguisticVariable water = new LinguisticVariable("Water");
            var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40);
            var hot  = water.MembershipFunctions.AddTrapezoid("Hot", 30, 40, 50, 50);

            LinguisticVariable power = new LinguisticVariable("Power");
            var low  = power.MembershipFunctions.AddTrapezoid("Low", 0, 0, 20, 40);
            var high = power.MembershipFunctions.AddTrapezoid("High", 30, 40, 50, 50);


            IFuzzyEngine fuzzyEngine = new FuzzyEngine(new MoMDefuzzification());

            fuzzyEngine.Rules.If(water.Is(cold)).Then(power.Is(low));
            fuzzyEngine.Rules.If(water.Is(hot)).Then(power.Is(high));

            //Act
            var result = fuzzyEngine.Defuzzify(new { water = waterInputValue });

            //Assert
            Assert.That(Math.Floor(result), Is.EqualTo(expectedValue));
        }
コード例 #11
0
        private void fuzzyLogika()
        {
            FuzzyEngine fuzzyPostava = new FuzzyEngine();

            fuzzyPostava.LinguisticVariableCollection.Add(postava);
            fuzzyPostava.LinguisticVariableCollection.Add(hodnota);
            fuzzyPostava.Consequent = "Hodnota";
            fuzzyPostava.FuzzyRuleCollection.Add(new FuzzyRule("IF Postava IS Drobna THEN Hodnota IS Zvysuje"));
            fuzzyPostava.FuzzyRuleCollection.Add(new FuzzyRule("IF Postava IS Normalni THEN Hodnota IS Zustava"));
            fuzzyPostava.FuzzyRuleCollection.Add(new FuzzyRule("IF Postava IS Urostla THEN Hodnota IS Snizuje"));

            FuzzyEngine fuzzyVyska = new FuzzyEngine();

            fuzzyVyska.LinguisticVariableCollection.Add(vyska);
            fuzzyVyska.LinguisticVariableCollection.Add(hodnota);
            fuzzyVyska.Consequent = "Hodnota";
            fuzzyVyska.FuzzyRuleCollection.Add(new FuzzyRule("IF Vyska IS Mala THEN Hodnota IS Zvysuje"));
            fuzzyVyska.FuzzyRuleCollection.Add(new FuzzyRule("IF Vyska IS Stredni THEN Hodnota IS Zustava"));
            fuzzyVyska.FuzzyRuleCollection.Add(new FuzzyRule("IF Vyska IS Vysoka THEN Hodnota IS Snizuje"));

            FuzzyEngine fuzzyVek = new FuzzyEngine();

            fuzzyVek.LinguisticVariableCollection.Add(vek);
            fuzzyVek.LinguisticVariableCollection.Add(hodnota);
            fuzzyVek.Consequent = "Hodnota";
            fuzzyVek.FuzzyRuleCollection.Add(new FuzzyRule("IF Vek IS Mlady THEN Hodnota IS Zvysuje"));
            fuzzyVek.FuzzyRuleCollection.Add(new FuzzyRule("IF Vek IS Stredni THEN Hodnota IS Zustava"));
            fuzzyVek.FuzzyRuleCollection.Add(new FuzzyRule("IF Vek IS Stary THEN Hodnota IS Zvysuje"));

            FuzzyEngine fuzzyVzdelani = new FuzzyEngine();

            fuzzyVzdelani.LinguisticVariableCollection.Add(vzdelani);
            fuzzyVzdelani.LinguisticVariableCollection.Add(hodnota);
            fuzzyVzdelani.Consequent = "Hodnota";
            fuzzyVzdelani.FuzzyRuleCollection.Add(new FuzzyRule("IF Vzdelani IS Zakladni THEN Hodnota IS Zvysuje"));
            fuzzyVzdelani.FuzzyRuleCollection.Add(new FuzzyRule("IF Vzdelani IS Stredni THEN Hodnota IS Zustava"));
            fuzzyVzdelani.FuzzyRuleCollection.Add(new FuzzyRule("IF Vzdelani IS Vysoka THEN Hodnota IS Snizuje"));

            FuzzyEngine fuzzyZaludek = new FuzzyEngine();

            fuzzyZaludek.LinguisticVariableCollection.Add(zaludek);
            fuzzyZaludek.LinguisticVariableCollection.Add(hodnota);
            fuzzyZaludek.Consequent = "Hodnota";
            fuzzyZaludek.FuzzyRuleCollection.Add(new FuzzyRule("IF Zaludek IS Lacno THEN Hodnota IS Zvysuje"));
            fuzzyZaludek.FuzzyRuleCollection.Add(new FuzzyRule("IF Zaludek IS Lehka THEN Hodnota IS Zvysuje"));
            fuzzyZaludek.FuzzyRuleCollection.Add(new FuzzyRule("IF Zaludek IS Stredni THEN Hodnota IS Zustava"));
            fuzzyZaludek.FuzzyRuleCollection.Add(new FuzzyRule("IF Zaludek IS Nadmerna THEN Hodnota IS Snizuje"));

            FuzzyEngine fuzzyNalada = new FuzzyEngine();

            fuzzyNalada.LinguisticVariableCollection.Add(nalada);
            fuzzyNalada.LinguisticVariableCollection.Add(hodnota);
            fuzzyNalada.Consequent = "Hodnota";
            fuzzyNalada.FuzzyRuleCollection.Add(new FuzzyRule("IF Nalada IS Dobra THEN Hodnota IS Snizuje"));
            fuzzyNalada.FuzzyRuleCollection.Add(new FuzzyRule("IF Nalada IS Normalni THEN Hodnota IS Zustava"));
            fuzzyNalada.FuzzyRuleCollection.Add(new FuzzyRule("IF Nalada IS Spatna THEN Hodnota IS Zvysuje"));

            FuzzyEngine fuzzyKurak = new FuzzyEngine();

            fuzzyKurak.LinguisticVariableCollection.Add(kurak);
            fuzzyKurak.LinguisticVariableCollection.Add(hodnota);
            fuzzyKurak.Consequent = "Hodnota";
            fuzzyKurak.FuzzyRuleCollection.Add(new FuzzyRule("IF Kurak IS Ne THEN Hodnota IS Snizuje"));
            fuzzyKurak.FuzzyRuleCollection.Add(new FuzzyRule("IF Kurak IS Cigarety THEN Hodnota IS Zustava"));
            fuzzyKurak.FuzzyRuleCollection.Add(new FuzzyRule("IF Kurak IS Doutniky THEN Hodnota IS Zvysuje"));
            fuzzyKurak.FuzzyRuleCollection.Add(new FuzzyRule("IF Kurak IS Vodarna THEN Hodnota IS Snizuje"));

            FuzzyEngine fuzzyUnava = new FuzzyEngine();

            fuzzyUnava.LinguisticVariableCollection.Add(unava);
            fuzzyUnava.LinguisticVariableCollection.Add(hodnota);
            fuzzyUnava.Consequent = "Hodnota";
            fuzzyUnava.FuzzyRuleCollection.Add(new FuzzyRule("IF Unava IS Mala THEN Hodnota IS Zvysuje"));
            fuzzyUnava.FuzzyRuleCollection.Add(new FuzzyRule("IF Unava IS Normalni THEN Hodnota IS Zustava"));
            fuzzyUnava.FuzzyRuleCollection.Add(new FuzzyRule("IF Unava IS Velka THEN Hodnota IS Snizuje"));

            try
            {
                vVyska = fuzzyVyska.Defuzzify();
                udalosti.Items.Add("Vyska: " + tbVyska.Text + " -> " + vVyska);

                vVek = fuzzyVek.Defuzzify();
                udalosti.Items.Add("Vek: " + tbVek.Text + " -> " + vVek);

                vPostava = fuzzyPostava.Defuzzify();
                udalosti.Items.Add("Postava: " + sPostava.Value + " -> " + vPostava);

                vZaludek = fuzzyZaludek.Defuzzify();
                udalosti.Items.Add("Zaludek: " + sZaludek.Value + " -> " + vZaludek);

                vNalada = fuzzyNalada.Defuzzify();
                udalosti.Items.Add("Nalada: " + sNalada.Value + " -> " + vNalada);

                vUnava = fuzzyUnava.Defuzzify();
                udalosti.Items.Add("Únava: " + sUnava.Value + " -> " + vUnava);

                vVzdelani = fuzzyVzdelani.Defuzzify();
                udalosti.Items.Add("Vzdelani: " + cbVzdelani.Text + " -> " + vVzdelani);

                vKurak = fuzzyKurak.Defuzzify();
                udalosti.Items.Add("Kurak: " + cbKurak.Text + " -> " + vKurak);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }


            string cestaVyska    = @"txt\vyska.txt";
            string cestaVek      = @"txt\vek.txt";
            string cestaPostava  = @"txt\postava.txt";
            string cestaZaludek  = @"txt\zaludek.txt";
            string cestaNalada   = @"txt\nalada.txt";
            string cestaVzdelani = @"txt\vzdelani.txt";
            string cestaKurak    = @"txt\kurak.txt";
            string cestaUnava    = @"txt\unava.txt";

            fuzzyVyska.Save(cestaVyska);
            fuzzyVek.Save(cestaVek);
            fuzzyPostava.Save(cestaPostava);
            fuzzyZaludek.Save(cestaZaludek);
            fuzzyNalada.Save(cestaNalada);
            fuzzyUnava.Save(cestaVzdelani);
            fuzzyVzdelani.Save(cestaVyska);
            fuzzyKurak.Save(cestaKurak);
            fuzzyUnava.Save(cestaUnava);
        }
コード例 #12
0
    void MyFuzzyRules()
    {
        LinguisticVariable points = new LinguisticVariable("Points");

        points.MembershipFunctionCollection.Add(new MembershipFunction("Lowest", 0, 1, 2, 4));
        points.MembershipFunctionCollection.Add(new MembershipFunction("Lower", 3, 5, 7, 9));
        points.MembershipFunctionCollection.Add(new MembershipFunction("Low", 6, 8, 10, 12));
        points.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 11, 13, 15, 17));
        points.MembershipFunctionCollection.Add(new MembershipFunction("High", 16, 18, 20, 22));
        points.MembershipFunctionCollection.Add(new MembershipFunction("Higher", 21, 23, 25, 27));
        points.MembershipFunctionCollection.Add(new MembershipFunction("Highest", 26, 28, 30, 1000));

        LinguisticVariable timeMatch = new LinguisticVariable("Timtch");

        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Lowest", 0, 5, 10, 15));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Lower", 10, 15, 20, 25));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Low", 20, 25, 30, 35));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 30, 35, 40, 45));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("High", 40, 45, 50, 55));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Higher", 50, 55, 60, 65));
        timeMatch.MembershipFunctionCollection.Add(new MembershipFunction("Highest", 60, 65, 70, 120));

        LinguisticVariable mTime = new LinguisticVariable("Time");

        mTime.MembershipFunctionCollection.Add(new MembershipFunction("Lowest", 0, 20, 40, 60));
        mTime.MembershipFunctionCollection.Add(new MembershipFunction("Low", 40, 60, 80, 100));
        mTime.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 80, 100, 120, 140));
        mTime.MembershipFunctionCollection.Add(new MembershipFunction("High", 120, 140, 160, 180));
        mTime.MembershipFunctionCollection.Add(new MembershipFunction("Higher", 160, 180, 200, 500));

        LinguisticVariable mortality = new LinguisticVariable("Mortality");

        mortality.MembershipFunctionCollection.Add(new MembershipFunction("Low", 0, 0, 2, 4));
        mortality.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 2, 3, 5, 6));
        mortality.MembershipFunctionCollection.Add(new MembershipFunction("High", 5, 7, 8, 50));

        LinguisticVariable scoresMeanValue = new LinguisticVariable("Average");

        scoresMeanValue.MembershipFunctionCollection.Add(new MembershipFunction("Low", 0, 2, 4, 6));
        scoresMeanValue.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 5, 7, 9, 11));
        scoresMeanValue.MembershipFunctionCollection.Add(new MembershipFunction("High", 10, 12, 20, 40));

        LinguisticVariable timeToTakeStar = new LinguisticVariable("Starmer");

        timeToTakeStar.MembershipFunctionCollection.Add(new MembershipFunction("Fast", 0, 0.5, 0.5, 1));
        timeToTakeStar.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 0.5, 1, 1.5, 2));
        timeToTakeStar.MembershipFunctionCollection.Add(new MembershipFunction("Slow", 1.5, 2, 2.5, 3));

        LinguisticVariable difficulty = new LinguisticVariable("Difficulty");

        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Easiest", 1, 2, 3, 4));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Easier", 3, 4, 5, 6));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Easy", 5, 6, 7, 8));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Medium", 7, 8, 9, 10));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Hard", 9, 10, 11, 12));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Harder", 11, 12, 13, 14));
        difficulty.MembershipFunctionCollection.Add(new MembershipFunction("Hardest", 13, 14, 15, 16));


        FuzzyEngine fuzzyEngine = new FuzzyEngine();

        fuzzyEngine.LinguisticVariableCollection.Add(points);
        fuzzyEngine.LinguisticVariableCollection.Add(mTime);
        fuzzyEngine.LinguisticVariableCollection.Add(mortality);
        fuzzyEngine.LinguisticVariableCollection.Add(scoresMeanValue);
        fuzzyEngine.LinguisticVariableCollection.Add(difficulty);
        fuzzyEngine.LinguisticVariableCollection.Add(timeMatch);
        fuzzyEngine.LinguisticVariableCollection.Add(timeToTakeStar);
        fuzzyEngine.Consequent = "Difficulty";


        /*   EASIEST   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Average IS Low) THEN Difficulty IS Easiest"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Average IS Medium) THEN Difficulty IS Easiest"));


        /*   EASIER   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS Lower) THEN Difficulty IS Easier"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Medium) AND (Average IS Low) THEN Difficulty IS Easier"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Medium) AND (Average IS Medium) THEN Difficulty IS Easier"));


        /*   EASY   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Time IS Lowest) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Points IS Low) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Timtch IS Low) AND (Points IS Lowest) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Timtch IS Low) AND (Points IS Lower) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Average IS Low) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Average IS Medium) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Medium) AND (Average IS High) THEN Difficulty IS Easy"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS Low) THEN Difficulty IS Easy"));


        /*   MEDIUM   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Points IS Medium) THEN Difficulty IS Medium"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Time IS Higher) THEN Difficulty IS Medium"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Time IS Higher) THEN Difficulty IS Medium"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Average IS High) THEN Difficulty IS Medium"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS Low) AND (Average IS Medium) THEN Difficulty IS Medium"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS Medium) THEN Difficulty IS Medium"));

        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Timtch IS High) AND (Points IS Low) THEN Difficulty IS Medium"));



        /*   HARD   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Points IS High) THEN Difficulty IS Hard"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Starmer IS Slow) AND (Points IS Higher) THEN Difficulty IS Hard"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Starmer IS Medium) AND (Points IS Higher) THEN Difficulty IS Hard"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Starmer IS Slow) AND (Points IS Highest) THEN Difficulty IS Hard"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS High) THEN Difficulty IS Hard"));


        /*   HARDER  */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Points IS Higher) THEN Difficulty IS Harder"));
        //fuzzyEngine.FuzzyRuleCollection.Add (new FuzzyRule ("IF (Starmer IS Slow) AND (Points IS Highest) THEN Difficulty IS Harder"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Starmer IS Medium) AND (Points IS Highest) THEN Difficulty IS Harder"));
        //fuzzyEngine.FuzzyRuleCollection.Add (new FuzzyRule ("IF (Timtch IS Higher) AND (Points IS High) THEN Difficulty IS Harder"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS Higher) THEN Difficulty IS Harder"));


        /*   HARDEST   */
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Points IS Highest) THEN Difficulty IS Hardest"));
        fuzzyEngine.FuzzyRuleCollection.Add(new FuzzyRule("IF (Mortality IS High) AND (Points IS Highest) THEN Difficulty IS Hardest"));


        points.InputValue          = GameController.GlobalVariables.points;
        mTime.InputValue           = GameController.GlobalVariables.gameTime;
        mortality.InputValue       = GameController.GlobalVariables.playerDeaths;
        scoresMeanValue.InputValue = GameController.GlobalVariables.lastScoresAverage;
        timeMatch.InputValue       = GameController.GlobalVariables.matchTime;
        timeToTakeStar.InputValue  = GameController.GlobalVariables.lastTimeStarAverage;


        //Debug.Log ("Defuzzy: " + fuzzyEngine.Defuzzify ());

        double variable = fuzzyEngine.Defuzzify();

        controlDifficulty = Mathf.RoundToInt((float)variable);
    }
コード例 #13
0
 public void SetUp()
 {
     _fuzzyEngine = new FuzzyEngine();
 }
コード例 #14
0
        /// <summary>
        /// Liefert Entscheidungswert für eine Aktion basierend auf den CHaractereinflüssen, den aktuellen Umständen und dem Memory.
        /// </summary>
        /// <param name="CharacterDependency1"></param>
        /// <param name="CharacterDependency2"></param>
        /// <param name="CharacterConsequent"></param>
        /// <param name="ratingAction"></param>
        /// <returns>Wert für Entscheidungsoption 1</returns>
        public static double Superdecision5x5x2_Double(CharacterType CharacterDependency1, Circumstance CharacterDependency2, Decision CharacterConsequent, double ratingAction)
        {
            //Abfangen von Characterwerten über 100
            //z.B. bei Energie > 100 (kann nur bei Dependency2 passieren)
            bool   useAdjustedCharacterValue = false;
            double adjustedCharacterValue    = 0;

            if (CharacterDependency2.Value() > 100)
            {
                useAdjustedCharacterValue = true;
                int diff = (int)CharacterDependency2.Value() - 100;
                switch (CharacterDependency1.TypeOfCharacter)
                {
                case CharacterTypes.Faulheit:
                case CharacterTypes.Wut:
                    adjustedCharacterValue = Math.Max(CharacterDependency1.Value() - diff, 0);
                    break;

                case CharacterTypes.Teamfaehigkeit:
                    adjustedCharacterValue = Math.Min(CharacterDependency1.Value() + diff, 100);
                    break;

                default:
                    break;
                }
            }


            FuzzyEngine defuzzer = new FuzzyEngine();

            defuzzer.LinguisticVariableCollection.Add(CharacterDependency1.characterParts);
            defuzzer.LinguisticVariableCollection.Add(CharacterDependency2.characterParts);
            defuzzer.LinguisticVariableCollection.Add(CharacterConsequent.characterParts);

            defuzzer.Consequent = CharacterConsequent.ToString();

            //Allgemeine Regel: C1_x AND C2_y → z_1, wenn y >= 5-x;   x,y = [0..4]
            //Greift keine Regel → Standardwert (nicht von DotFuzzy unterstützt)
            for (int x = 4; x >= 0; x--)
            {
                for (int y = x; y < 5; y++)
                {
                    defuzzer.FuzzyRuleCollection.Add(new FuzzyRule("IF (" + CharacterDependency1.characterParts.Name + " IS " + CharacterDependency1.characterParts.MembershipFunctionCollection[x].Name + ") AND (" + CharacterDependency2.characterParts.Name + " IS " + CharacterDependency2.characterParts.MembershipFunctionCollection[y].Name + ") THEN " + CharacterConsequent.characterParts.Name + " IS " + CharacterConsequent.characterParts.MembershipFunctionCollection[1].Name));
                }
            }

            //Wenn durch eine Ameisenklasse bspw. ein höherer Energiewert zugelassen wird, dann muss das hier berücksichtigt werden
            if (useAdjustedCharacterValue)
            {
                CharacterDependency1.characterParts.InputValue = adjustedCharacterValue; //für positiven Effekt veränderter Wert
                CharacterDependency2.characterParts.InputValue = 100;                    //normierter Wert
            }
            else
            {
                CharacterDependency1.characterParts.InputValue = CharacterDependency1.Value();
                CharacterDependency2.characterParts.InputValue = CharacterDependency2.Value();
            }
            double defuzzedValue = defuzzer.Defuzzify();

            //Standardwert setzen
            //Immer dann, wenn keine positive Entscheidung getroffen wird, es also keine Regel dazu gab, dann defuzzedValue auf Wert für negative (default) Entscheidung setzen.
            if (double.IsNaN(defuzzedValue))
            {
                defuzzedValue = CharacterConsequent.FirstOptionIsDefaultDecision ? 0.25 : 0.75;
            }


            //Gedächtnis einbeziehen (wie gut war die Entscheidung beim letzten Mal?)
            //Durchschnitt reicht nicht aus, beachtet extreme Werte nicht ausreichend
            //-> Extremere Werte sollen die Entscheidung stärker beeinflussen
            if (ratingAction > 0.5)
            {
                ratingAction = Math.Sqrt(ratingAction);
            }

            if (ratingAction < 0.5)
            {
                ratingAction *= ratingAction;
            }

            defuzzedValue = Overthink(ratingAction, defuzzedValue, PreferenceWeight); //zwischen 0..100

            return(defuzzedValue);
        }
コード例 #15
0
    //Constructor
    public AI()
    {
        fuzzyEngine = new FuzzyEngine();

        AINeedsList = new Dictionary <string, Need>();
    }