Example #1
0
        public void GetMembershipFunctions(out IMemebershipFunction cold, out IMemebershipFunction warm, out IMemebershipFunction hot)
        {
            Coords c0;
            Coords c1;
            Coords c2;

            c0.X = -270;
            c0.Y = 1;
            c1.X = 5;
            c1.Y = 1;
            c2.X = 20;
            c2.Y = 0;
            cold = new TriangularMemebershipFunction(c0, c1, c2);

            c0.X = 5;
            c0.Y = 0;
            c1.X = 20;
            c1.Y = 1;
            c2.X = 30;
            c2.Y = 0;
            warm = new TriangularMemebershipFunction(c0, c1, c2);

            c0.X = 20;
            c0.Y = 0;
            c1.X = 30;
            c1.Y = 1;
            c2.X = 100;
            c2.Y = 1;
            hot  = new TriangularMemebershipFunction(c0, c1, c2);
        }
Example #2
0
        private FuzzySet <AmmoStatus> GetAmmoStatusSet()
        {
            IMemebershipFunction lowFx   = new ShoulderMembershipFunction(0f, new Coords(0f, 1f), new Coords(10f, 0f), 40f);
            IMemebershipFunction okayFx  = new TriangularMemebershipFunction(new Coords(0f, 0f), new Coords(10f, 1f), new Coords(30f, 0f));
            IMemebershipFunction loadsFx = new ShoulderMembershipFunction(0f, new Coords(10f, 0f), new Coords(30f, 1f), 40f);

            FuzzySet <AmmoStatus> set = new FuzzySet <AmmoStatus>();

            set.Set(AmmoStatus.Low, lowFx);
            set.Set(AmmoStatus.Okay, okayFx);
            set.Set(AmmoStatus.Loads, loadsFx);
            return(set);
        }
Example #3
0
        private FuzzySet <DistanceToTarget> GetDistanceToTargetSet()
        {
            IMemebershipFunction closeFx  = new ShoulderMembershipFunction(0f, new Coords(25f, 1f), new Coords(150f, 0f), 400f);
            IMemebershipFunction mediumFx = new TriangularMemebershipFunction(new Coords(25f, 0f), new Coords(150f, 1f), new Coords(300f, 0f));
            IMemebershipFunction farFx    = new ShoulderMembershipFunction(0f, new Coords(150f, 0f), new Coords(300f, 1f), 400f);

            FuzzySet <DistanceToTarget> set = new FuzzySet <DistanceToTarget>();

            set.Set(DistanceToTarget.Close, closeFx);
            set.Set(DistanceToTarget.Medium, mediumFx);
            set.Set(DistanceToTarget.Far, farFx);
            return(set);
        }
Example #4
0
        private FuzzySet <Desirability> GetDesirabilitySet()
        {
            IMemebershipFunction undesirableFx   = new ShoulderMembershipFunction(0f, new Coords(25f, 1f), new Coords(50f, 0f), 100f);
            IMemebershipFunction desirableFx     = new TriangularMemebershipFunction(new Coords(25f, 0f), new Coords(50f, 1f), new Coords(75f, 0f));
            IMemebershipFunction veryDesirableFx = new ShoulderMembershipFunction(0f, new Coords(50f, 0f), new Coords(75f, 1f), 100f);

            FuzzySet <Desirability> set = new FuzzySet <Desirability>();

            set.Set(new FuzzyVariable <Desirability>(Desirability.Undesirable, undesirableFx));
            set.Set(new FuzzyVariable <Desirability>(Desirability.Desirable, desirableFx));
            set.Set(new FuzzyVariable <Desirability>(Desirability.VeryDesirable, veryDesirableFx));
            return(set);
        }
Example #5
0
        public void FuzzyExpressionBuilder()
        {
            Coords c0 = new Coords(2.5f, 0f);
            Coords c1 = new Coords(5f, 1f);
            Coords c2 = new Coords(7.5f, 0.25f);
            TriangularMemebershipFunction membFunc = new TriangularMemebershipFunction(c1, c0, c2);
            FuzzyVariable <Temperature>   cold     = new FuzzyVariable <Temperature>(Temperature.Cold, membFunc);
            FuzzyVariable <Temperature>   warm     = new FuzzyVariable <Temperature>(Temperature.Warm, membFunc);
            FuzzyVariable <Temperature>   hot      = new FuzzyVariable <Temperature>(Temperature.Hot, membFunc);
            var    exp      = cold.AsExpression().And(warm).Or(hot.AsExpression().Not());
            string expected = "((Cold AND Warm) OR NOT(Hot))";

            Assert.IsNotNull(exp);
            Assert.AreEqual(expected, exp.ToString());
        }
Example #6
0
        public void TestTriangularMemebershipFunction()
        {
            Coords c0 = new Coords(2.5f, 0f);
            Coords c1 = new Coords(5f, 1f);
            Coords c2 = new Coords(7.5f, 0.25f);
            TriangularMemebershipFunction membFunc = new TriangularMemebershipFunction(c1, c0, c2);

            Assert.AreEqual(2.5f, membFunc.P0.X);
            Assert.AreEqual(5f, membFunc.P1.X);
            Assert.AreEqual(7.5f, membFunc.P2.X);
            var result = membFunc.fX(0.0f);

            Assert.AreEqual(0f, result);
            result = membFunc.fX(3.75f);
            Assert.AreEqual(0.5f, result);
            result = membFunc.fX(5.0f);
            Assert.AreEqual(1f, result);
            result = membFunc.fX(6.25f);
            Assert.AreEqual(0.625f, result);
            result = membFunc.fX(10.0f);
            Assert.AreEqual(0.25f, result);
        }