예제 #1
0
        public Thirst() : base()
        {
            _module = new FuzzyModule();

            // Antecedents
            FuzzyVariable Thirst      = _module.CreateFLV("Thirst");
            var           Thirst_Low  = Thirst.AddLeftShoulderSet("Thirst_Low", 0, 10, 20);
            var           Thirst_Med  = Thirst.AddTriangularSet("Thirst_Med", 10, 20, 30);
            var           Thirst_High = Thirst.AddRightShoulderSet("Thirst_High", 20, 30, _MAX_THIRST);

            FuzzyVariable Distance        = _module.CreateFLV("Distance");
            var           Distance_Close  = Distance.AddLeftShoulderSet("Distance_Close", 0, 40, 80);
            var           Distance_Medium = Distance.AddTriangularSet("Distance_Medium", 40, 80, 400);
            var           Distance_Far    = Distance.AddRightShoulderSet("Distance_Far", 80, 400, MAX_DISTANCE);

            // Consequence
            FuzzyVariable Desirability  = _module.CreateFLV("Desirability");
            var           Undesirable   = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
            var           Desirable     = Desirability.AddTriangularSet("Desirable", 25, 50, 75);
            var           VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);

            // Rules
            _module.AddRule(new FzAND(Thirst_Low, Distance_Close), Undesirable);
            _module.AddRule(new FzAND(Thirst_Low, Distance_Medium), Undesirable);
            _module.AddRule(new FzAND(Thirst_Low, Distance_Far), Undesirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Close), Desirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Medium), Undesirable);
            _module.AddRule(new FzAND(Thirst_Med, Distance_Far), Undesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Close), VeryDesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Medium), VeryDesirable);
            _module.AddRule(new FzAND(Thirst_High, Distance_Far), Desirable);
        }
예제 #2
0
        public void FuzzyTowerCalcSniper(FuzzyModule towerFuzzyModule)
        {
            // Retrieves the antecedents.
            FuzzyVariable health = towerFuzzyModule.GetVar("Health");
            FzSet         low    = new FzSet(health.GetSet("Low"));
            FzSet         middle = new FzSet(health.GetSet("Middle"));
            FzSet         high   = new FzSet(health.GetSet("High"));


            FuzzyVariable distanceToEnemy = towerFuzzyModule.GetVar("DistanceToEnemy");
            FzSet         close           = new FzSet(distanceToEnemy.GetSet("Close"));
            FzSet         medium          = new FzSet(distanceToEnemy.GetSet("Medium"));
            FzSet         far             = new FzSet(distanceToEnemy.GetSet("Far"));

            // Creates the consequent.
            FuzzyVariable shootDesirability = towerFuzzyModule.CreateFLV("ShootDesirability");

            FzSet undesirable   = shootDesirability.AddLeftShoulderSet("Undesirable", 0, 15, 30);
            FzSet desirable     = shootDesirability.AddTriangularSet("Desirable", 15, 30, 75);
            FzSet veryDesirable = shootDesirability.AddRightShoulderSet("VeryDesirable", 30, 75, 100);

            // Add rules to complete the FAM.
            towerFuzzyModule.AddRule(new FzAND(low, close), desirable);
            towerFuzzyModule.AddRule(new FzAND(low, medium), desirable);
            towerFuzzyModule.AddRule(new FzAND(low, far), veryDesirable);

            towerFuzzyModule.AddRule(new FzAND(middle, close), undesirable);
            towerFuzzyModule.AddRule(new FzAND(middle, medium), undesirable);
            towerFuzzyModule.AddRule(new FzAND(middle, far), desirable);

            towerFuzzyModule.AddRule(new FzAND(high, close), undesirable);
            towerFuzzyModule.AddRule(new FzAND(high, medium), undesirable);
            towerFuzzyModule.AddRule(new FzAND(high, far), desirable);
        }
예제 #3
0
        public static FuzzyTermSet add_term(Sets set, FuzzyVariable fuzzyVar, string name, double min, double peak, double max)
        {
            switch (set)
            {
            case Sets.LEFT_SHOULDER:
                return(fuzzyVar.AddLeftShoulderSet(name, min, peak, max));

            case Sets.TRIANGULAR:
                return(fuzzyVar.AddTriangularSet(name, min, peak, max));

            case Sets.RIGHT_SHOULDER:
                return(fuzzyVar.AddRightShoulderSet(name, min, peak, max));

            default:
                throw new ArgumentException("Cannot find the desired fuzzy set.");
            }
        }
예제 #4
0
        public FuzzyModule InitFuzzyTowerBaseModule()
        {
            FuzzyModule towerFuzzyModule = new FuzzyModule();

            FuzzyVariable health = towerFuzzyModule.CreateFLV("Health");

            health.AddLeftShoulderSet("Low", 0, 20, 33);
            health.AddTriangularSet("Middle", 20, 33, 60);
            health.AddRightShoulderSet("High", 33, 60, 100);

            FuzzyVariable distanceToEnemy = towerFuzzyModule.CreateFLV("DistanceToEnemy");

            distanceToEnemy.AddLeftShoulderSet("Close", 0, 29, 30);
            distanceToEnemy.AddTriangularSet("Medium", 29, 30, 66);
            distanceToEnemy.AddRightShoulderSet("Far", 30, 66, 100);

            return(towerFuzzyModule);
        }
        public void FuzzyLogic_Test1()
        {
            FuzzyModule fuzzyModule = new FuzzyModule();

            FuzzyVariable distanceToTarget = fuzzyModule.CreateFLV("DistanceToTarget");
            FzSet         Target_Close     = distanceToTarget.AddLeftShoulderSet("Target_Close", 0, 250, 500);
            FzSet         Target_Medium    = distanceToTarget.AddTriangularSet("Target_Medium", 250, 500, 750);
            FzSet         Target_Far       = distanceToTarget.AddRightShoulderSet("Target_Far", 500, 750, 1000);

            FuzzyVariable AmmoStatus = fuzzyModule.CreateFLV("AmmoStatus");
            FzSet         Ammo_Low   = AmmoStatus.AddLeftShoulderSet("Ammo_Low", 0, 250, 500);
            FzSet         Ammo_Okay  = AmmoStatus.AddTriangularSet("Ammo_Okay", 250, 500, 750);
            FzSet         Ammo_Loads = AmmoStatus.AddRightShoulderSet("Ammo_Loads", 500, 750, 1000);

            FuzzyVariable Desirability   = fuzzyModule.CreateFLV("Desirability");
            FzSet         Undesirable    = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
            FzSet         Desirable      = Desirability.AddTriangularSet("Desirable", 25, 50, 75);
            FzSet         Very_Desirable = Desirability.AddRightShoulderSet("Very_Desirable", 50, 75, 100);

            fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Loads), Undesirable);
            fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Okay), Undesirable);
            fuzzyModule.AddRule(new FzAND(Target_Close, Ammo_Low), Undesirable);
            fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Loads), Very_Desirable);
            fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Okay), Very_Desirable);
            fuzzyModule.AddRule(new FzAND(Target_Medium, Ammo_Low), Desirable);
            fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Loads), Desirable);
            fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Okay), Desirable);
            fuzzyModule.AddRule(new FzAND(Target_Far, Ammo_Low), Undesirable);

            fuzzyModule.Fuzzify("DistanceToTarget", 200);
            fuzzyModule.Fuzzify("AmmoStatus", 400);

            double value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV);

            Assert.Equal(12.5, value);

            fuzzyModule.Fuzzify("DistanceToTarget", 1000);
            fuzzyModule.Fuzzify("AmmoStatus", 600);

            value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV);

            Assert.Equal(50, value);
        }
    public double FuzzyGetDesirabilitySeek(int hungerVar, double moneyVar)
    {
        FuzzyModule fuzzyModule = new FuzzyModule();

        FuzzyVariable hunger      = fuzzyModule.CreateFLV("Hunger");
        FzSet         No_Hunger   = hunger.AddLeftShoulderSet("No_Hunger", 0, 5, 10);
        FzSet         Hunger      = hunger.AddTriangularSet("Hunger", 5, 10, 15);
        FzSet         Very_Hunger = hunger.AddRightShoulderSet("Very_Hunger", 10, 15, 20);

        FuzzyVariable AmmoStatus = fuzzyModule.CreateFLV("Money");
        FzSet         Poor       = AmmoStatus.AddLeftShoulderSet("Poor", 0, 5, 10);
        FzSet         Normal     = AmmoStatus.AddTriangularSet("Normal", 5, 10, 100);
        FzSet         Rich       = AmmoStatus.AddRightShoulderSet("Rich", 10, 100, 1000);

        FuzzyVariable Desirability   = fuzzyModule.CreateFLV("Desirability");
        FzSet         Undesirable    = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);
        FzSet         Desirable      = Desirability.AddTriangularSet("Desirable", 25, 50, 75);
        FzSet         Very_Desirable = Desirability.AddRightShoulderSet("Very_Desirable", 50, 75, 100);

        fuzzyModule.AddRule(new FzAND(No_Hunger, Poor), Undesirable);
        fuzzyModule.AddRule(new FzAND(No_Hunger, Normal), Undesirable);
        fuzzyModule.AddRule(new FzAND(No_Hunger, Rich), Undesirable);
        fuzzyModule.AddRule(new FzAND(Very_Hunger, Poor), Very_Desirable);
        fuzzyModule.AddRule(new FzAND(Very_Hunger, Normal), Very_Desirable);
        fuzzyModule.AddRule(new FzAND(Very_Hunger, Rich), Undesirable);
        fuzzyModule.AddRule(new FzAND(Hunger, Poor), Desirable);
        fuzzyModule.AddRule(new FzAND(Hunger, Normal), Desirable);
        fuzzyModule.AddRule(new FzAND(Hunger, Rich), Undesirable);

        fuzzyModule.Fuzzify("Hunger", hungerVar);
        fuzzyModule.Fuzzify("Money", moneyVar);

        double value = fuzzyModule.DeFuzzify("Desirability", FuzzyModule.DefuzzifyMethod.MaxAV);

        return(value);
    }
예제 #7
0
    protected override void initializeFuzzyModule()
    {
        FuzzyVariable DistToTarget = m_FuzzyModule.CreateFLV("DistToTarget");

        //FzSet is a fuzzy set!!!
        FzSet Target_Close  = DistToTarget.AddLeftShoulderSet("eTarget_Close", 0, 250, 500);
        FzSet Target_Medium = DistToTarget.AddTriangularSet("eTarget_Medium", 250, 500, 750);
        FzSet Target_Far    = DistToTarget.AddRightShoulderSet("eTarget_Far", 500, 750, 1000);

        FuzzyVariable DistToMate  = m_FuzzyModule.CreateFLV("DistToMate");
        FzSet         Mate_Close  = DistToMate.AddLeftShoulderSet("mTarget_Close", 0, 250, 500);
        FzSet         Mate_Medium = DistToMate.AddTriangularSet("mTarget_Medium", 250, 500, 750);
        FzSet         Mate_Far    = DistToMate.AddRightShoulderSet("mTarget_Far", 500, 750, 1000);

        FuzzyVariable Hunger     = m_FuzzyModule.CreateFLV("Hunger");
        FzSet         VeryHungry = Hunger.AddRightShoulderSet("VeryHungry", 50, 75, 100);
        FzSet         Hungry     = Hunger.AddTriangularSet("Hungry", 25, 50, 75);
        FzSet         NotHungry  = Hunger.AddLeftShoulderSet("NotHungry", 0, 25, 50);


        FuzzyVariable Libido       = m_FuzzyModule.CreateFLV("Libido");
        FzSet         HighLibido   = Libido.AddRightShoulderSet("HighLibido", 50, 75, 100);
        FzSet         MediumLibido = Libido.AddTriangularSet("MediumLibido", 25, 50, 75);
        FzSet         NoLibido     = Libido.AddLeftShoulderSet("NoLibido", 0, 25, 50);

        FuzzyVariable Desirability  = m_FuzzyModule.CreateFLV("Desirability");
        FzSet         VeryDesirable = Desirability.AddRightShoulderSet("VeryDesirable", 50, 75, 100);
        FzSet         Desirable     = Desirability.AddTriangularSet("Desirable", 25, 50, 75);
        FzSet         Undesirable   = Desirability.AddLeftShoulderSet("Undesirable", 0, 25, 50);


        FuzzyVariable Sex       = m_FuzzyModule.CreateFLV("Sex");
        FzSet         HighSex   = Sex.AddRightShoulderSet("HighSex", 50, 75, 100);
        FzSet         MediumSex = Sex.AddTriangularSet("MediumSex", 25, 50, 75);
        FzSet         NoSex     = Sex.AddLeftShoulderSet("NoSex", 0, 25, 50);



        //temperature
        FuzzyVariable Temperature = m_FuzzyModule2.CreateFLV("Temperature");

        FzSet hot  = Temperature.AddLeftShoulderSet("hot", 0, 250, 500);
        FzSet warm = Temperature.AddTriangularSet("warm", 250, 500, 750);
        FzSet cold = Temperature.AddRightShoulderSet("cold", 500, 750, 1000);

        FuzzyVariable Hunger2     = m_FuzzyModule2.CreateFLV("Hunger2");
        FzSet         VeryHungry2 = Hunger2.AddRightShoulderSet("VeryHungry", 50, 75, 100);
        FzSet         Hungry2     = Hunger2.AddTriangularSet("Hungry", 25, 50, 75);
        FzSet         NotHungry2  = Hunger2.AddLeftShoulderSet("NotHungry", 0, 25, 50);

        FuzzyVariable Libido2       = m_FuzzyModule2.CreateFLV("Libido2");
        FzSet         HighLibido2   = Libido2.AddRightShoulderSet("HighLibido", 50, 75, 100);
        FzSet         MediumLibido2 = Libido2.AddTriangularSet("MediumLibido", 25, 50, 75);
        FzSet         NoLibido2     = Libido2.AddLeftShoulderSet("NoLibido", 0, 25, 50);

        FuzzyVariable Desirability2  = m_FuzzyModule2.CreateFLV("Desirability2");
        FzSet         VeryDesirable2 = Desirability2.AddRightShoulderSet("VeryDesirable", 50, 75, 100);
        FzSet         Desirable2     = Desirability2.AddTriangularSet("Desirable", 25, 50, 75);
        FzSet         Undesirable2   = Desirability2.AddLeftShoulderSet("Undesirable", 0, 25, 50);

        FuzzyVariable Sex2       = m_FuzzyModule2.CreateFLV("Sex2");
        FzSet         HighSex2   = Sex2.AddRightShoulderSet("HighSex", 50, 75, 100);
        FzSet         MediumSex2 = Sex2.AddTriangularSet("MediumSex", 25, 50, 75);
        FzSet         NoSex2     = Sex2.AddLeftShoulderSet("NoSex", 0, 25, 50);

        //Temperature Rules
        m_FuzzyModule2.AddRule(new FzAND(hot, VeryHungry2), Undesirable2);
        m_FuzzyModule2.AddRule(new FzAND(hot, Hungry2), Undesirable2);
        m_FuzzyModule2.AddRule(new FzAND(hot, NotHungry2), Undesirable2);

        m_FuzzyModule2.AddRule(new FzAND(warm, VeryHungry2), VeryDesirable2);
        m_FuzzyModule2.AddRule(new FzAND(warm, Hungry2), VeryDesirable2);
        m_FuzzyModule2.AddRule(new FzAND(warm, NotHungry2), Desirable2);

        m_FuzzyModule2.AddRule(new FzAND(cold, VeryHungry2), Desirable2);
        m_FuzzyModule2.AddRule(new FzAND(cold, Hungry2), Undesirable2);
        m_FuzzyModule2.AddRule(new FzAND(cold, NotHungry2), Undesirable2);


        m_FuzzyModule2.AddRule(new FzAND(hot, HighLibido2), NoSex2);
        m_FuzzyModule2.AddRule(new FzAND(hot, MediumLibido2), NoSex2);
        m_FuzzyModule2.AddRule(new FzAND(hot, NoLibido2), NoSex2);

        m_FuzzyModule2.AddRule(new FzAND(warm, HighLibido2), MediumSex2);
        m_FuzzyModule2.AddRule(new FzAND(warm, MediumLibido2), NoSex2);
        m_FuzzyModule2.AddRule(new FzAND(warm, NoLibido2), NoSex2);

        m_FuzzyModule2.AddRule(new FzAND(cold, HighLibido2), HighSex2);
        m_FuzzyModule2.AddRule(new FzAND(cold, MediumLibido2), HighSex2);
        m_FuzzyModule2.AddRule(new FzAND(cold, NoLibido2), NoSex2);



        //food
        //antecedents and consequents are FzSet isntances, so Clone() uses FzSet member function Clone().
        m_FuzzyModule.AddRule(new FzAND(Target_Close, HighLibido, VeryHungry), VeryDesirable);    //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, MediumLibido, VeryHungry), VeryDesirable);  //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, NoLibido, VeryHungry), VeryDesirable);      //done

        m_FuzzyModule.AddRule(new FzAND(Target_Close, HighLibido, Hungry), Desirable);            //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, MediumLibido, Hungry), Desirable);          //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, NoLibido, Hungry), VeryDesirable);          //done

        m_FuzzyModule.AddRule(new FzAND(Target_Close, HighLibido, NotHungry), Undesirable);       //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, MediumLibido, NotHungry), Undesirable);     //done
        m_FuzzyModule.AddRule(new FzAND(Target_Close, NoLibido, NotHungry), Undesirable);         //done

        m_FuzzyModule.AddRule(new FzAND(Target_Medium, HighLibido, VeryHungry), Desirable);       //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, MediumLibido, VeryHungry), VeryDesirable); //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, NoLibido, VeryHungry), VeryDesirable);     //done

        m_FuzzyModule.AddRule(new FzAND(Target_Medium, HighLibido, Hungry), Desirable);           //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, MediumLibido, Hungry), Desirable);         //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, NoLibido, Hungry), VeryDesirable);         //done

        m_FuzzyModule.AddRule(new FzAND(Target_Medium, HighLibido, NotHungry), Undesirable);      //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, MediumLibido, NotHungry), Undesirable);    //done
        m_FuzzyModule.AddRule(new FzAND(Target_Medium, NoLibido, NotHungry), Undesirable);        //done

        m_FuzzyModule.AddRule(new FzAND(Target_Far, HighLibido, VeryHungry), VeryDesirable);      //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, MediumLibido, VeryHungry), VeryDesirable);    //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, NoLibido, VeryHungry), VeryDesirable);        //done

        m_FuzzyModule.AddRule(new FzAND(Target_Far, HighLibido, Hungry), Desirable);              //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, MediumLibido, Hungry), Desirable);            //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, NoLibido, Hungry), VeryDesirable);            //done

        m_FuzzyModule.AddRule(new FzAND(Target_Far, HighLibido, NotHungry), Undesirable);         //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, MediumLibido, NotHungry), Undesirable);       //done
        m_FuzzyModule.AddRule(new FzAND(Target_Far, NoLibido, NotHungry), Undesirable);           //done

        //sex
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, VeryHungry, HighLibido), MediumSex);   //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, VeryHungry, MediumLibido), MediumSex); //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, VeryHungry, NoLibido), NoSex);         //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Close, Hungry, HighLibido), HighSex);         //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, Hungry, MediumLibido), MediumSex);     //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, Hungry, NoLibido), NoSex);             //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Close, NotHungry, HighLibido), HighSex);      //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, NotHungry, MediumLibido), HighSex);    //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Close, NotHungry, NoLibido), NoSex);          //done


        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, VeryHungry, HighLibido), MediumSex);  ///done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, VeryHungry, MediumLibido), NoSex);    //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, VeryHungry, NoLibido), NoSex);        //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, Hungry, HighLibido), HighSex);        //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, Hungry, MediumLibido), MediumSex);    //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, Hungry, NoLibido), NoSex);            //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, NotHungry, HighLibido), HighSex);     //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, NotHungry, MediumLibido), MediumSex); //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Medium, NotHungry, NoLibido), NoSex);         //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Far, VeryHungry, HighLibido), MediumSex);     //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, VeryHungry, MediumLibido), NoSex);       //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, VeryHungry, NoLibido), NoSex);           //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Far, Hungry, HighLibido), MediumSex);         //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, Hungry, MediumLibido), MediumSex);       //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, Hungry, NoLibido), NoSex);               //done

        m_FuzzyModule.AddRule(new FzAND(Mate_Far, NotHungry, HighLibido), HighSex);        //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, NotHungry, MediumLibido), MediumSex);    //done
        m_FuzzyModule.AddRule(new FzAND(Mate_Far, NotHungry, NoLibido), NoSex);            //done
    }