// Called at game start - set up FIS
 void Start()
 {
     // Create the inference system
     SetupFuzzySets(isRedCar);
     IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));
     SetupRuleBase(isRedCar);
 }
 private void Rules()
 {
     infSystem = new InferenceSystem(database, new CentroidDefuzzifier(120));
     infSystem.NewRule("Rule 1", "IF Distance IS Far THEN Speed IS Slow");    //AITank Player tanka uzaksa yavaş
     infSystem.NewRule("Rule 2", "IF Distance IS Medi THEN Speed IS Medium"); // AITank Player tanka orta uzaklıkta ise orta hızda
     infSystem.NewRule("Rule 3", "IF Distance IS Near THEN Speed IS Fast");   //AITank Player tanka yakınsa hızlı gidecek
 }
Beispiel #3
0
        private void SetUpFisII()
        {
            //Input
            var impact = new LinguisticVariable("Impact", 0, 100);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)),
                new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)),
                new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100))
            }.ForEach(x => impact.AddLabel(x));


            var onGround = new LinguisticVariable("On_ground", -0.5f, 1.5f);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)),
                new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)),
                new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f))
            }.ForEach(x => onGround.AddLabel(x));


            var timeOnGround = new LinguisticVariable("Time_on_ground", -1, 901);

            new List <FuzzySet>()
            {
                new FuzzySet("Brief", new TrapezoidalFunction(-1, 1, 1, 2)),
                new FuzzySet("Short", new TrapezoidalFunction(1, 5, 10, 15)),
                new FuzzySet("Moderate", new TrapezoidalFunction(10, 120, 480, 720)),
                new FuzzySet("Long", new TrapezoidalFunction(480, 900, 900, 901))
            }.ForEach(x => timeOnGround.AddLabel(x));


            //Output
            var fallWearable = new LinguisticVariable("Fall_wearable", -0.5f, 1.5f);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)),
                new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)),
                new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f))
            }.ForEach(x => fallWearable.AddLabel(x));

            var db = new Database();

            db.AddVariable(impact);
            db.AddVariable(onGround);
            db.AddVariable(timeOnGround);
            db.AddVariable(fallWearable);


            fisII = new InferenceSystem(db, new CentroidDefuzzifier(1000));

            fisII.NewRule("Rule 1", "IF Impact IS High AND On_ground IS High AND Time_on_ground IS Long THEN Fall_wearable IS High");
            fisII.NewRule("Rule 2", "IF Impact IS Medium AND On_ground IS High AND Time_on_ground IS Long THEN Fall_wearable IS High");
            fisII.NewRule("Rule 3", "IF Impact IS Low AND On_ground IS Low AND (Time_on_ground IS Short OR Time_on_ground IS Brief) THEN Fall_wearable IS Low");
            fisII.NewRule("Rule 4", "IF Impact IS Medium AND On_ground IS Medium AND Time_on_ground IS Moderate THEN Fall_wearable IS Medium");
            fisII.NewRule("Rule 5", "IF Impact IS High AND On_ground IS Medium AND (Time_on_ground IS Short OR Time_on_ground IS Brief) THEN Fall_wearable IS Medium");
        }
Beispiel #4
0
    public Fuzzy()
    {
        InitFuzzySets();
        InitLinguisticVariables();

        DB = new Database();
        DB.AddVariable(lvFrontal);
        DB.AddVariable(lvLeft);
        DB.AddVariable(lvRight);
        DB.AddVariable(lvAngle);
        DB.AddVariable(lvRoadSegment);
        DB.AddVariable(lvRightFront);
        DB.AddVariable(lvRightRear);
        DB.AddVariable(lvLeftFront);
        DB.AddVariable(lvLeftRear);
        DB.AddVariable(lvFrontalRight);
        DB.AddVariable(lvFrontalLeft);
        DB.AddVariable(lvCurvedFrontalRight);
        DB.AddVariable(lvCurvedFrontalLeft);
        DB.AddVariable(lvAcceleration);
        DB.AddVariable(lvCarroAd);
        IS = new InferenceSystem(DB, new CentroidDefuzzifier(1000));

        SetRules();
    }
Beispiel #5
0
        private void Initialize(List <Variable> variables, List <String> roles)
        {
            _fuzzyDB = new Database();

            foreach (var variable in variables)
            {
                _fuzzyDB.AddVariable(variable.FVariable);

                if (variable.Type == JConfig.VariableType.Ouput)
                {
                    _outputName = variable.FVariable.Name;
                }
            }

            _centroidDefuzzifier = new CentroidDefuzzifier(1000);
            _system = new InferenceSystem(_fuzzyDB, _centroidDefuzzifier);

            foreach (var variable in variables)
            {
                if (variable.Type == JConfig.VariableType.Input)
                {
                    _system.SetInput(variable.Name, (float)variable.ResultValue);
                }
            }

            int roleCounter = 0;

            foreach (var role in roles)
            {
                _system.NewRule("Role " + roleCounter++, role);
            }
        }
Beispiel #6
0
        private void SetUpFisI()
        {
            //Input
            var treshhold = new LinguisticVariable("Threshold", 0, 100);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)),
                new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)),
                new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100))
            }.ForEach(x => treshhold.AddLabel(x));

            //Output
            var impact = new LinguisticVariable("Impact", 0, 100);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)),
                new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)),
                new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100))
            }.ForEach(x => impact.AddLabel(x));

            var db = new Database();

            db.AddVariable(treshhold);
            db.AddVariable(impact);


            fisI = new InferenceSystem(db, new CentroidDefuzzifier(1000));

            fisI.NewRule("Rule 1", "IF Threshold IS Low THEN Impact IS Low");
            fisI.NewRule("Rule 2", "IF Threshold IS Medium THEN Impact IS Medium");
            fisI.NewRule("Rule 3", "IF Threshold IS High THEN Impact IS High");
        }
Beispiel #7
0
 private void SetRules()
 {
     infSystem = new InferenceSystem(database, new CentroidDefuzzifier(120));
     infSystem.NewRule("Rule 1", "IF Distance IS Near THEN Speed IS Slow");
     infSystem.NewRule("Rule 2", "IF Distance IS Med THEN Speed IS Medium");
     infSystem.NewRule("Rule 3", "IF Distance IS Far THEN Speed IS Fast");
 }
        public override AlgorithmResult ProcessData()
        {
            byte[,] pixels = Input.Image.GetPixels();
            if (gMin == -1 || gMean == -1 || gMax == -1)
            {
                var stats = new ImageStatistics(Input.Image);
                gMin  = stats.Gray.Min;
                gMax  = stats.Gray.Max;
                gMean = (byte)((gMax - gMin) / 2 + gMin);
            }

            InferenceSystem system = SetupInferenceSystem((byte)gMin, (byte)gMax, (byte)gMean);
            var             result = new byte[pixels.GetLength(0), pixels.GetLength(1)];

            for (int i = 0; i < pixels.GetLength(0); i++)
            {
                for (int j = 0; j < pixels.GetLength(1); j++)
                {
                    system.SetInput("LumaIn", pixels[i, j]);
                    double inferrenceResult = system.Evaluate("LumaOut");
                    result[i, j] = (byte)inferrenceResult;
                }
            }

            return(new AlgorithmResult(result));
        }
Beispiel #9
0
        public ZoomGps()
        {
            // création du langage
            var ld = LinguistictDistance();
            var lv = LinguisticVitesse();
            var lz = LinguisticZoom();

            // création des règles

            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(ld);
            fuzzyDB.AddVariable(lv);
            fuzzyDB.AddVariable(lz);

            var IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(100));

            IS.NewRule("Rule 1", "IF Distance IS Grande THEN Zoom IS Petit");
            IS.NewRule("Rule 2", "IF Distance IS Faible AND Vitesse IS Lente THEN Zoom IS Normal");
            IS.NewRule("Rule 3", "IF Distance IS Faible AND Vitesse IS PeuRapide THEN Zoom IS Normal");
            IS.NewRule("Rule 4", "IF Distance IS Faible AND Vitesse IS Rapide THEN Zoom IS Gros");
            IS.NewRule("Rule 5", "IF Distance IS Faible AND Vitesse IS TresRapide THEN Zoom IS Gros");

            IS.NewRule("Rule 6", "IF Distance IS Moyenne AND Vitesse IS Lente THEN Zoom IS Petit");
            IS.NewRule("Rule 7", "IF Distance IS Moyenne AND Vitesse IS PeuRapide THEN Zoom IS Normal");
            IS.NewRule("Rule 8", "IF Distance IS Moyenne AND Vitesse IS Rapide THEN Zoom IS Normal");
            IS.NewRule("Rule 9", "IF Distance IS Moyenne AND Vitesse IS TresRapide THEN Zoom IS Gros");

            m_IS = IS;
        }
    public InferenceSystemThread(InferenceSystem inferenceEngine, float defaultValue)
    {
        this.requestedOutputs = new HashSet<string>();
        this.inferenceEngine = inferenceEngine;
        this.defaultValue = defaultValue;

        this.output = null;
        this.done = true;
    }
    public InferenceSystemThread(InferenceSystem inferenceEngine, float defaultValue)
    {
        this.requestedOutputs = new HashSet <string>();
        this.inferenceEngine  = inferenceEngine;
        this.defaultValue     = defaultValue;

        this.output = null;
        this.done   = true;
    }
Beispiel #12
0
        public InferenceSystem SetupInferenceSystem(int width)
        {
            var mp = new TrapezoidalFunction(centerPoint - width / 2, centerPoint, centerPoint + width / 2);
            var mn = new TrapezoidalFunction(-centerPoint - width / 2, -centerPoint, -centerPoint + width / 2);
            var sp = new TrapezoidalFunction(-centerPoint / 2 + width / 4, (double)centerPoint / 2, centerPoint / 2 + width / 3);
            var sn = new TrapezoidalFunction(-centerPoint / 2 - width / 3, (double)-centerPoint / 2, centerPoint / 2 - width / 4);
            var ze = new TrapezoidalFunction(-(double)centerPoint / 4, 0, (double)centerPoint / 4);

            var mpSet = new FuzzySet("MP", mp);
            var mnSet = new FuzzySet("MN", mn);
            var spSet = new FuzzySet("SP", sp);
            var snSet = new FuzzySet("SN", sn);
            var zeSet = new FuzzySet("ZE", ze);

            var ruleDatabase = new Database();

            for (int i = 0; i < windowSize * windowSize - 1; i++)
            {
                var variable = new LinguisticVariable(String.Format("IN{0}", i), -255, 255);
                variable.AddLabel(mpSet);
                variable.AddLabel(mnSet);
                ruleDatabase.AddVariable(variable);
            }

            var outVariable = new LinguisticVariable("OUT", -centerPoint - width / 2, centerPoint + width / 2);

            outVariable.AddLabel(spSet);
            outVariable.AddLabel(snSet);
            outVariable.AddLabel(zeSet);
            ruleDatabase.AddVariable(outVariable);
            var    inferenceSystem = new InferenceSystem(ruleDatabase, new CentroidDefuzzifier(100));
            string rule1           = "IF ";
            string rule2           = "IF ";
            string rule3           = "IF ";

            for (int i = 0; i < windowSize * windowSize - 1; i++)
            {
                rule1 += String.Format("IN{0} is MP and ", i);
                rule2 += String.Format("IN{0} is MN and ", i);
                rule3 += String.Format("IN{0} is not MP and IN{0} is not MN AND ", i);
            }

            rule1 = rule1.Remove(rule1.Length - 4, 4);
            rule2 = rule2.Remove(rule2.Length - 4, 4);
            rule3 = "IF NOT (" + rule1.Replace("IF", "") + ") AND NOT(" + rule2.Replace("IF", "") + ")";

            rule1 += " then OUT is SN";
            rule2 += " then OUT is SP";
            rule3 += " then OUT is ZE";

            inferenceSystem.NewRule("Rule1", rule1);
            inferenceSystem.NewRule("Rule2", rule2);
            inferenceSystem.NewRule("Rule3", rule3);

            return(inferenceSystem);
        }
Beispiel #13
0
    private void AddToDatabese()
    {
        database = new Database();
        database.AddVariable(lvDistance);
        database.AddVariable(lvSpeed);

        infSystem = new InferenceSystem(database, new CentroidDefuzzifier(20));
        infSystem.NewRule("Rule1", "IF Distance IS Near THEN Speed IS Slow");
        infSystem.NewRule("Rule2", "IF Distance IS Med THEN Speed IS Medium");
        infSystem.NewRule("Rule3", "IF Distance IS Far THEN Speed IS Fast");
    }
Beispiel #14
0
    private void InitFuzz()
    {
        this.Charts = new List <FuzzySetGroupCharts>();
        Database db = new Database();

        // fuzzy set to determine perceived distance
        FuzzySetGroupDesc distanceGroup = new FuzzySetGroupDesc("Distance");

        distanceGroup.Add(new FuzzySetDescLeft("Near", 0.75f, 2.5f));
        distanceGroup.Add(new FuzzySetDescMid("Medium", 0.75f, 2.5f, 3, 10));
        distanceGroup.Add(new FuzzySetDescRight("Far", 3, 10));

        this.Charts.Add(new FuzzySetGroupCharts(distanceGroup));
        FuzzySet[] distanceSets = FuzzUtil.CreateFuzzySets(distanceGroup);

        db.AddVariable(FuzzUtil.CreateVariable("RightDistance", 0, 10, distanceSets));
        db.AddVariable(FuzzUtil.CreateVariable("LeftDistance", 0, 10, distanceSets));
        db.AddVariable(FuzzUtil.CreateVariable("FrontDistance", 0, 10, distanceSets));

        // fuzzy set to determine heading directions
        FuzzySetGroupDesc headingGroup = new FuzzySetGroupDesc("Heading");

        headingGroup.Add(new FuzzySetDescLeft("HardLeft", -35, -30));
        headingGroup.Add(new FuzzySetDescMid("Left", -35, -30, -20, -15));
        headingGroup.Add(new FuzzySetDescMid("SlightLeft", -20, -15, -5, 0));
        headingGroup.Add(new FuzzySetDescMid("Straight", -5, -1, 1, 5));
        headingGroup.Add(new FuzzySetDescMid("SlightRight", 0, 5, 15, 20));
        headingGroup.Add(new FuzzySetDescMid("Right", 15, 20, 30, 35));
        headingGroup.Add(new FuzzySetDescRight("HardRight", 30, 35));

        this.Charts.Add(new FuzzySetGroupCharts(headingGroup));
        FuzzySet[] headingSets = FuzzUtil.CreateFuzzySets(headingGroup);

        db.AddVariable(FuzzUtil.CreateVariable("Heading", -50, 50, headingSets));

        _inferenceSystem = new InferenceSystem(db, new CentroidDefuzzifier(50));

        // if all is clear ahead go for it
        _inferenceSystem.NewRule("1", "IF FrontDistance IS Far THEN Heading IS Straight");

        // should handle left/right turns
        _inferenceSystem.NewRule("2", "IF FrontDistance IS Near AND RightDistance IS Near THEN Heading IS Left");
        _inferenceSystem.NewRule("3", "IF FrontDistance IS Near AND LeftDistance IS Near THEN Heading IS Right");

        // edge away from walls
        _inferenceSystem.NewRule("4", "IF LeftDistance IS Near AND (RightDistance IS Medium OR RightDistance IS Far) THEN Heading IS SlightRight");
        _inferenceSystem.NewRule("5", "IF RightDistance IS Near AND (LeftDistance IS Medium OR LeftDistance IS Far) THEN Heading IS SlightLeft");

        // attempt to give priority to left turns if both are available?
        _inferenceSystem.NewRule("6", "IF FrontDistance IS Near THEN Heading IS Left");
    }
        private InferenceSystem SetupInferenceSystem(byte minLuma, byte maxLuma, byte meanLuma)
        {
            var lumaIn  = new LinguisticVariable("LumaIn", minLuma, maxLuma);
            var lumaOut = new LinguisticVariable("LumaOut", 0, 255);

            var darkFunction = new TrapezoidalFunction(minLuma, meanLuma, TrapezoidalFunction.EdgeType.Right);
            var darkSet      = new FuzzySet("Dark", darkFunction);

            var mediumFunction = new TrapezoidalFunction(minLuma, meanLuma, maxLuma);
            var mediumSet      = new FuzzySet("Medium", mediumFunction);

            var lightFunction = new TrapezoidalFunction(meanLuma, maxLuma, TrapezoidalFunction.EdgeType.Left);
            var lightSet      = new FuzzySet("Light", lightFunction);

            lumaIn.AddLabel(darkSet);
            lumaIn.AddLabel(mediumSet);
            lumaIn.AddLabel(lightSet);

            var whiteFunction = new SingletonFunction(255);
            var whiteSet      = new FuzzySet("White", whiteFunction);

            var blackFunction = new SingletonFunction(0);
            var blackSet      = new FuzzySet("Black", blackFunction);

            var grayFunction = new SingletonFunction(128);
            var graySet      = new FuzzySet("Gray", grayFunction);

            lumaOut.AddLabel(blackSet);
            lumaOut.AddLabel(graySet);
            lumaOut.AddLabel(whiteSet);

            var database = new Database();

            database.AddVariable(lumaIn);
            database.AddVariable(lumaOut);

            var inferenceSystem = new InferenceSystem(database, new CogDefuzzifier());

            inferenceSystem.NewRule("Rule 1", "IF LumaIn IS Dark THEN LumaOut is Black");
            inferenceSystem.NewRule("Rule 2", "IF LumaIn IS Medium THEN LumaOut is Gray");
            inferenceSystem.NewRule("Rule 3", "IF LumaIn IS Light THEN LumaOut is White");

            return(inferenceSystem);
        }
Beispiel #16
0
        private byte Modify(InferenceSystem system, int[] windowData, byte center)
        {
            for (int i = 0; i < windowSize * windowSize - 1; i++)
            {
                system.SetInput(String.Format("IN{0}", i), windowData[i]);
            }

            int x = center + (byte)system.Evaluate("OUT");

            if (x < 0)
            {
                return(0);
            }

            if (x > 255)
            {
                return(255);
            }

            return((byte)x);
        }
Beispiel #17
0
        public override AlgorithmResult ProcessData()
        {
            InferenceSystem system = SetupInferenceSystem(windowSize);

            byte[,] pixels = Input.Image.GetPixels();
            int width  = pixels.GetLength(0);
            int height = pixels.GetLength(1);

            var result = new byte[width, height];

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int[] windowData = GetNeighboursData(pixels, i, j, windowSize, width, height);
                    result[i, j] = Modify(system, windowData, pixels[i, j]);
                }
            }

            return(new AlgorithmResult(result));
        }
Beispiel #18
0
        private static InferenceSystem CreateInferenceSystem()
        {
            var objectiveVariable      = new LinguisticVariable("OBJECTIVE", 0, 1);
            var subjectiveVariable     = new LinguisticVariable("SUBJECTIVE", 0, 1);
            var algorithmScoreVariable = new LinguisticVariable("ALGORITHM_SCORE", 0, 1);


            var objectiveLow    = new ZTypeMembership(0, 0.5);
            var objectiveMedium = new PITypeMembership(0, 0.5, 0.75);
            var objectiveHigh   = new STypeMembership(0.25, 1);

            var subjectiveLow    = new ZTypeMembership(0, 0.5);
            var subjectiveMedium = new PITypeMembership(0.25, 0.5, 0.75);
            var subjectiveHigh   = new STypeMembership(0.5, 1);

            var algorithmScoreVeryLow  = new VeryHedge(new ZTypeMembership(0, 0.5));
            var algorithmScoreLow      = new ZTypeMembership(0, 0.5);
            var algorithmScoreMedium   = new PITypeMembership(0.25, 0.5, 0.75);
            var algorithmScoreHigh     = new STypeMembership(0.5, 1);
            var algorithmScoreVeryHigh = new VeryHedge(new STypeMembership(0.5, 1));


            var objectiveLowSet    = new FuzzySet("LOW", objectiveLow);
            var objectiveMediumSet = new FuzzySet("MEDIUM", objectiveMedium);
            var objectiveHighSet   = new FuzzySet("HIGH", objectiveHigh);

            var subjectiveLowSet    = new FuzzySet("LOW", subjectiveLow);
            var subjectiveMediumSet = new FuzzySet("MEDIUM", subjectiveMedium);
            var subjectiveHighSet   = new FuzzySet("HIGH", subjectiveHigh);

            var resultVeryLowSet  = new FuzzySet("VERY_LOW", algorithmScoreVeryLow);
            var resultLowSet      = new FuzzySet("LOW", algorithmScoreLow);
            var resultMediumSet   = new FuzzySet("MEDIUM", algorithmScoreMedium);
            var resultHighSet     = new FuzzySet("HIGH", algorithmScoreHigh);
            var resultVeryHighSet = new FuzzySet("VERY_HIGH", algorithmScoreVeryHigh);


            objectiveVariable.AddLabel(objectiveLowSet);
            objectiveVariable.AddLabel(objectiveMediumSet);
            objectiveVariable.AddLabel(objectiveHighSet);
            subjectiveVariable.AddLabel(subjectiveLowSet);
            subjectiveVariable.AddLabel(subjectiveMediumSet);
            subjectiveVariable.AddLabel(subjectiveHighSet);
            algorithmScoreVariable.AddLabel(resultVeryLowSet);
            algorithmScoreVariable.AddLabel(resultLowSet);
            algorithmScoreVariable.AddLabel(resultMediumSet);
            algorithmScoreVariable.AddLabel(resultHighSet);
            algorithmScoreVariable.AddLabel(resultVeryHighSet);

            var rulebase = new Database();

            rulebase.AddVariable(objectiveVariable);
            rulebase.AddVariable(subjectiveVariable);
            rulebase.AddVariable(algorithmScoreVariable);

            var inferenceSystem = new InferenceSystem(rulebase, new CentroidDefuzzifier(30));

            inferenceSystem.NewRule("Rule1", "if OBJECTIVE is LOW and SUBJECTIVE is LOW then ALGORITHM_SCORE is VERY_LOW ");
            inferenceSystem.NewRule("Rule2", "if OBJECTIVE is LOW and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is LOW");
            inferenceSystem.NewRule("Rule3", "if OBJECTIVE is LOW and SUBJECTIVE is HIGH then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule4", "if OBJECTIVE is MEDIUM and SUBJECTIVE is LOW then ALGORITHM_SCORE is LOW");
            inferenceSystem.NewRule("Rule5", "if OBJECTIVE is MEDIUM and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule6", "if OBJECTIVE is MEDIUM and SUBJECTIVE is HIGH then ALGORITHM_SCORE is HIGH");
            inferenceSystem.NewRule("Rule7", "if OBJECTIVE is HIGH and SUBJECTIVE is LOW then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule8", "if OBJECTIVE is HIGH and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is HIGH");
            inferenceSystem.NewRule("Rule9", "if OBJECTIVE is HIGH and SUBJECTIVE is HIGH then ALGORITHM_SCORE is VERY_HIGH");

            return(inferenceSystem);
        }
Beispiel #19
0
 public Evaluator()
 {
     inferenceSystem = CreateInferenceSystem();
 }
Beispiel #20
0
    void InitFuzzyEngine()
    {
        //Sunciones de Pertenencia
        //Alturas
        FuzzySet fsBaja  = new FuzzySet("Baja", new TrapezoidalFunction(-1f, 0f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsMedia = new FuzzySet("Media", new TrapezoidalFunction(-1f, -0.1f, 0.1f, 1f));
        FuzzySet fsAlta  = new FuzzySet("Alta", new TrapezoidalFunction(0f, 1f, TrapezoidalFunction.EdgeType.Left));
        //Velocidades
        FuzzySet fsMn   = new FuzzySet("Negativa", new TrapezoidalFunction(-1f, -0.5f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsZero = new FuzzySet("Media", new TrapezoidalFunction(-1f, -0.5f, 0.5f, 1f));
        FuzzySet fsMp   = new FuzzySet("Positiva", new TrapezoidalFunction(0.5f, 1f, TrapezoidalFunction.EdgeType.Left));
        //Fuerzas
        FuzzySet fsZf = new FuzzySet("PocaFuerza", new TrapezoidalFunction(0f, 1f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsPf = new FuzzySet("ZeroFuerza", new TrapezoidalFunction(0.5f, 1f, 9f, 10f));
        FuzzySet fsMf = new FuzzySet("MuchaFuerza", new TrapezoidalFunction(9.5f, 16f, TrapezoidalFunction.EdgeType.Left));


        //Entradas
        //Altura
        LinguisticVariable lvAltura = new LinguisticVariable("Altura", -15, 15);

        lvAltura.AddLabel(fsBaja);
        lvAltura.AddLabel(fsMedia);
        lvAltura.AddLabel(fsAlta);
        //Velocidades
        LinguisticVariable lvVelocidad = new LinguisticVariable("Velocidad", -25, 25);

        lvVelocidad.AddLabel(fsMn);
        lvVelocidad.AddLabel(fsZero);
        lvVelocidad.AddLabel(fsMp);
        //Fuerzas
        LinguisticVariable lvFuerza = new LinguisticVariable("Fuerza", 0, 16);

        lvFuerza.AddLabel(fsPf);
        lvFuerza.AddLabel(fsZf);
        lvFuerza.AddLabel(fsMf);

        //La base de datos
        Database fuzzyDb = new Database();

        fuzzyDb.AddVariable(lvAltura);
        fuzzyDb.AddVariable(lvFuerza);
        fuzzyDb.AddVariable(lvVelocidad);

        //Sistema de interferencia


        ISL = new InferenceSystem(fuzzyDb, new CentroidDefuzzifier(1000));

        ISL.NewRule("Rule 1", "IF Altura IS Baja AND Velocidad IS Negativa THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 2", "IF Altura IS Baja AND Velocidad IS Media THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 3", "IF Altura IS Baja AND Velocidad IS Positiva THEN Fuerza IS MuchaFuerza");

        ISL.NewRule("Rule 4", "IF Altura IS Media AND Velocidad IS Negativa THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 5", "IF Altura IS Media AND Velocidad IS Media THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 6", "IF Altura IS Media AND Velocidad IS Positiva THEN Fuerza IS ZeroFuerza");

        ISL.NewRule("Rule 7", "IF Altura IS Alta AND Velocidad IS Negativa THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 8", "IF Altura IS Alta AND Velocidad IS Media THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 9", "IF Altura IS Alta AND Velocidad IS Positiva THEN Fuerza IS ZeroFuerza");
    }
        private void bunifuImageButton9_Click(object sender, EventArgs e)
        {
            // Kecepatan (0-120)
            FuzzySet fsLambat = new FuzzySet("Lambat", new TrapezoidalFunction(30, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsSedang = new FuzzySet("Sedang", new TrapezoidalFunction(40, 60, 80));
            FuzzySet fsCepat  = new FuzzySet("Cepat", new TrapezoidalFunction(70, 80, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvKecepatan = new LinguisticVariable("Kecepatan", 0, 120);

            lvKecepatan.AddLabel(fsLambat);
            lvKecepatan.AddLabel(fsSedang);
            lvKecepatan.AddLabel(fsCepat);

            // Jarak (0-10)
            FuzzySet fsDekat      = new FuzzySet("Dekat", new TrapezoidalFunction(1, 2, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsJauh       = new FuzzySet("Jauh", new TrapezoidalFunction(1, 4, 5));
            FuzzySet fsSangatJauh = new FuzzySet("SangatJauh", new TrapezoidalFunction(4, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Jarak
            LinguisticVariable lvJarak = new LinguisticVariable("Jarak", 0, 10);

            lvJarak.AddLabel(fsDekat);
            lvJarak.AddLabel(fsJauh);
            lvJarak.AddLabel(fsSangatJauh);

            // Kemiringan Jalan ((-90)-90)
            FuzzySet fsTurun = new FuzzySet("Turun", new TrapezoidalFunction(-40, -20, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsDatar = new FuzzySet("Datar", new TrapezoidalFunction(-25, 0, 25));
            FuzzySet fsNaik  = new FuzzySet("Naik", new TrapezoidalFunction(20, 40, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kemiringan Jalan
            LinguisticVariable lvKemiringan = new LinguisticVariable("Kemiringan", -90, 90);

            lvKemiringan.AddLabel(fsTurun);
            lvKemiringan.AddLabel(fsDatar);
            lvKemiringan.AddLabel(fsNaik);

            // OUTPUT

            // Tingkat Pengereman (0-10)
            FuzzySet fsLemah  = new FuzzySet("Lemah", new TrapezoidalFunction(3, 4, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Sedang", new TrapezoidalFunction(3, 4, 6, 7));
            FuzzySet fsKuat   = new FuzzySet("Kuat", new TrapezoidalFunction(6, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvTingkatPengereman = new LinguisticVariable("TingkatPengereman", 0, 10);

            lvTingkatPengereman.AddLabel(fsLemah);
            lvTingkatPengereman.AddLabel(fsMedium);
            lvTingkatPengereman.AddLabel(fsKuat);

            // Database
            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvJarak);
            fuzzyDB.AddVariable(lvKemiringan);
            fuzzyDB.AddVariable(lvKecepatan);
            fuzzyDB.AddVariable(lvTingkatPengereman);

            // Inferensi System Engine
            InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Rules
            IS.NewRule("Rule 1", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 2", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 3", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 4", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 5", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 6", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 7", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 8", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 9", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 10", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 11", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 12", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 13", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 14", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 15", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 16", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 17", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 18", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 19", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 20", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 21", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 22", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 23", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 24", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 25", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 26", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 27", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");

            // Set Input

            IS.SetInput("Kecepatan", (float)Convert.ToDouble(TB_Speed.Value));
            IS.SetInput("Jarak", (float)Convert.ToDouble(TB_Distance.Value));
            if (TB_AngleMin.Value != 0)
            {
                IS.SetInput("Kemiringan", (float)Convert.ToDouble(TB_AngleMin.Value));
            }
            IS.SetInput("Kemiringan", (float)Convert.ToDouble(TB_AnglePlus.Value));

            // Get output
            double BrakeLevel = IS.Evaluate("TingkatPengereman");

            if (TB_Speed.Value == 0 && TB_Distance.Value == 0 && TB_AngleMin.Value == 0 && TB_AnglePlus.Value == 0)
            {
                BrakeLevel         = 0;
                Gauge_Break.Value  = Convert.ToInt32(BrakeLevel * 10);
                lblvalueBrake.Text = Convert.ToString(Math.Ceiling(BrakeLevel));
            }
            else
            {
                Gauge_Break.Value = Convert.ToInt32(BrakeLevel * 10);
            }
            lblvalueBrake.Text = Convert.ToString(Math.Ceiling(BrakeLevel));
        }
Beispiel #22
0
    void InitFuzzyEngine()
    {
        // Linguistic labels (fuzzy sets) para aciertos
        FuzzySet fsLow     = new FuzzySet("Low", new TrapezoidalFunction(0.0, 0.33, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsNeutral = new FuzzySet("Normal", new TrapezoidalFunction(0.0, 0.33, 0.66, 1.00));
        FuzzySet fsHigh    = new FuzzySet("High", new TrapezoidalFunction(0.66, 1.00, TrapezoidalFunction.EdgeType.Left));

        /*  // Linguistic labels (fuzzy sets) para errores y ayuda
         * FuzzySet fsLowInv = new FuzzySet("Low", new TrapezoidalFunction(0.0, 0.33, TrapezoidalFunction.EdgeType.Right));
         * FuzzySet fsHighInv = new FuzzySet("High", new TrapezoidalFunction(0.66, 1.00, TrapezoidalFunction.EdgeType.Left));
         */

        // Linguistic labels (fuzzy sets) para el tiempo
        FuzzySet fsFast   = new FuzzySet("Fast", new TrapezoidalFunction(0, 0.33, TrapezoidalFunction.EdgeType.Left));
        FuzzySet fsNormal = new FuzzySet("Normal", new TrapezoidalFunction(0, 0.33, 0.66, 1.00));
        FuzzySet fsSlow   = new FuzzySet("Slow", new TrapezoidalFunction(0.66, 1.00, TrapezoidalFunction.EdgeType.Right));



        // Right Distance (Input)
        LinguisticVariable numAciertos = new LinguisticVariable("Aciertos", 0, 1);

        numAciertos.AddLabel(fsLow);
        numAciertos.AddLabel(fsNeutral);
        numAciertos.AddLabel(fsHigh);


        // Left Distance (Input)
        LinguisticVariable numErrores = new LinguisticVariable("Errores", 0, 1);

        numErrores.AddLabel(fsLow);
        numErrores.AddLabel(fsNeutral);
        numErrores.AddLabel(fsHigh);

        LinguisticVariable ayudas = new LinguisticVariable("Ayuda", 0, 1);

        ayudas.AddLabel(fsLow);
        ayudas.AddLabel(fsNeutral);
        ayudas.AddLabel(fsHigh);

        // Time (Input)
        LinguisticVariable tiempoSeg = new LinguisticVariable("Time", 0, 1);

        tiempoSeg.AddLabel(fsSlow);
        tiempoSeg.AddLabel(fsNormal);
        tiempoSeg.AddLabel(fsFast);

        // Linguistic labels (fuzzy sets) that compose Dificultad
        FuzzySet fsVeryWeak = new FuzzySet("VeryWeak", new TrapezoidalFunction(0.0, 0.20, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsWeak     = new FuzzySet("Weak", new TrapezoidalFunction(0.0, 0.20, 0.35, 0.40));
        FuzzySet fsBasico   = new FuzzySet("Normal", new TrapezoidalFunction(0.35, 0.40, 0.55, 0.60));
        FuzzySet fsGood     = new FuzzySet("Good", new TrapezoidalFunction(0.55, 0.60, 0.75, 0.80));
        FuzzySet fsGreat    = new FuzzySet("Great", new TrapezoidalFunction(0.75, 0.80, TrapezoidalFunction.EdgeType.Left));

        // AnglefsWonderFull
        lvDificultad = new LinguisticVariable("Dificultad", 0, 1.00);
        lvDificultad.AddLabel(fsVeryWeak);
        lvDificultad.AddLabel(fsWeak);
        lvDificultad.AddLabel(fsBasico);
        lvDificultad.AddLabel(fsGood);
        lvDificultad.AddLabel(fsGreat);

        // The database
        Database fuzzyDB = new Database();

        fuzzyDB.AddVariable(numAciertos);
        fuzzyDB.AddVariable(numErrores);
        fuzzyDB.AddVariable(tiempoSeg);
        fuzzyDB.AddVariable(ayudas);
        fuzzyDB.AddVariable(lvDificultad);

        // Creating the inference system
        IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1500));

        IS.NewRule("RULE 1", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 2", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Good");
        IS.NewRule("RULE 3", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Great");
        IS.NewRule("RULE 4", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Normal");
        IS.NewRule("RULE 5", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 6", "IF Time IS Fast AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 7", "IF Time IS Fast AND Ayuda IS Low AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 8", "IF Time IS Fast AND Ayuda IS Low AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 9", "IF Time IS Fast AND Ayuda IS Low AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 10", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 11", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 12", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Great");
        IS.NewRule("RULE 13", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 14", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Good");
        IS.NewRule("RULE 15", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 16", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 17", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 18", "IF Time IS Fast AND Ayuda IS Normal AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 19", "IF Time IS Fast AND Ayuda IS High AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 20", "IF Time IS Fast AND Ayuda IS High AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 21", "IF Time IS Fast AND Ayuda IS High AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 22", "IF Time IS Fast AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 23", "IF Time IS Fast AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 24", "IF Time IS Fast AND Ayuda IS High AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 25", "IF Time IS Fast AND Ayuda IS High AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 26", "IF Time IS Fast AND Ayuda IS High AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 27", "IF Time IS Fast AND Ayuda IS High AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 28", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 29", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 30", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Great");
        IS.NewRule("RULE 31", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Normal");
        IS.NewRule("RULE 32", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 33", "IF Time IS Normal AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 34", "IF Time IS Normal AND Ayuda IS Low AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 35", "IF Time IS Normal AND Ayuda IS Low AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 36", "IF Time IS Normal AND Ayuda IS Low AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 37", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Normal");
        IS.NewRule("RULE 38", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 39", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 40", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Normal");
        IS.NewRule("RULE 41", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 42", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 43", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 44", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 45", "IF Time IS Normal AND Ayuda IS Normal AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 46", "IF Time IS Normal AND Ayuda IS High AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 47", "IF Time IS Normal AND Ayuda IS High AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 48", "IF Time IS Normal AND Ayuda IS High AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 49", "IF Time IS Normal AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 50", "IF Time IS Normal AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 51", "IF Time IS Normal AND Ayuda IS High AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 52", "IF Time IS Normal AND Ayuda IS High AND Errores IS High AND Aciertos IS Low THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 53", "IF Time IS Normal AND Ayuda IS High AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 54", "IF Time IS Normal AND Ayuda IS High AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 55", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Normal");
        IS.NewRule("RULE 56", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 57", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 58", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 59", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 60", "IF Time IS Slow AND Ayuda IS Low AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 61", "IF Time IS Slow AND Ayuda IS Low AND Errores IS High AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 62", "IF Time IS Slow AND Ayuda IS Low AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 63", "IF Time IS Slow AND Ayuda IS Low AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 64", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 65", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 66", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Good");
        IS.NewRule("RULE 67", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 68", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Normal");
        IS.NewRule("RULE 69", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 70", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Low THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 71", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 72", "IF Time IS Slow AND Ayuda IS Normal AND Errores IS High AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 73", "IF Time IS Slow AND Ayuda IS High AND Errores IS Low AND Aciertos IS Low THEN Dificultad IS Weak");
        IS.NewRule("RULE 74", "IF Time IS Slow AND Ayuda IS High AND Errores IS Low AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 75", "IF Time IS Slow AND Ayuda IS High AND Errores IS Low AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 76", "IF Time IS Slow AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Low THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 77", "IF Time IS Slow AND Ayuda IS High AND Errores IS Normal AND Aciertos IS Normal THEN Dificultad IS Weak");
        IS.NewRule("RULE 78", "IF Time IS Slow AND Ayuda IS High AND Errores IS Normal AND Aciertos IS High THEN Dificultad IS Normal");
        IS.NewRule("RULE 79", "IF Time IS Slow AND Ayuda IS High AND Errores IS High AND Aciertos IS Low THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 80", "IF Time IS Slow AND Ayuda IS High AND Errores IS High AND Aciertos IS Normal THEN Dificultad IS VeryWeak");
        IS.NewRule("RULE 81", "IF Time IS Slow AND Ayuda IS High AND Errores IS High AND Aciertos IS High THEN Dificultad IS Weak");
    }
    //Definición del sistema de lógica difusa
    void InitFuzzyEngine()
    {
        //Funciones de Pertenencia
        //Demanda
        FuzzySet fsBaja  = new FuzzySet("Baja", new TrapezoidalFunction(2f, 4f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsMedia = new FuzzySet("Media", new TrapezoidalFunction(3f, 5f, 7f));
        FuzzySet fsAlta  = new FuzzySet("Alta", new TrapezoidalFunction(6f, 8f, TrapezoidalFunction.EdgeType.Left));
        //Disponible
        FuzzySet fsPoco   = new FuzzySet("Poco", new TrapezoidalFunction(4f, 8f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsNormal = new FuzzySet("Normal", new TrapezoidalFunction(6f, 10f, 14f));
        FuzzySet fsMucho  = new FuzzySet("Mucho", new TrapezoidalFunction(12f, 16f, TrapezoidalFunction.EdgeType.Left));
        //Fuerzas
        FuzzySet fsPbaja  = new FuzzySet("Pbaja", new TrapezoidalFunction(0.1f, 0.2f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsPmedia = new FuzzySet("Pmedia", new TrapezoidalFunction(0.3f, 0.5f, 0.7f));
        FuzzySet fsPalta  = new FuzzySet("Palta", new TrapezoidalFunction(0.6f, 0.8f, TrapezoidalFunction.EdgeType.Left));


        //Entradas
        //Altura
        LinguisticVariable lvDemanda = new LinguisticVariable("Demanda", 0, 10);

        lvDemanda.AddLabel(fsBaja);
        lvDemanda.AddLabel(fsMedia);
        lvDemanda.AddLabel(fsAlta);
        //Velocidades
        LinguisticVariable lvDisponible = new LinguisticVariable("Disponible", 0, 20);

        lvDisponible.AddLabel(fsPoco);
        lvDisponible.AddLabel(fsNormal);
        lvDisponible.AddLabel(fsMucho);
        //Fuerzas
        LinguisticVariable lvFuerza = new LinguisticVariable("Prioridad", 0, 1);

        lvFuerza.AddLabel(fsPbaja);
        lvFuerza.AddLabel(fsPmedia);
        lvFuerza.AddLabel(fsPalta);

        //La base de datos
        Database fuzzyDb = new Database();

        fuzzyDb.AddVariable(lvDemanda);
        fuzzyDb.AddVariable(lvFuerza);
        fuzzyDb.AddVariable(lvDisponible);

        //Sistema de interferencia


        ISL = new InferenceSystem(fuzzyDb, new CentroidDefuzzifier(800));

        //Definicion de reglas

        ISL.NewRule("Rule 1", "IF Demanda IS Baja AND Disponible IS Poco THEN Prioridad IS Pmedia");
        ISL.NewRule("Rule 2", "IF Demanda IS Baja AND Disponible IS Normal THEN Prioridad IS Pbaja");
        ISL.NewRule("Rule 3", "IF Demanda IS Baja AND Disponible IS Mucho THEN Prioridad IS Pbaja");

        ISL.NewRule("Rule 4", "IF Demanda IS Media AND Disponible IS Poco THEN Prioridad IS Palta");
        ISL.NewRule("Rule 5", "IF Demanda IS Media AND Disponible IS Normal THEN Prioridad IS Pbaja");
        ISL.NewRule("Rule 6", "IF Demanda IS Media AND Disponible IS Mucho THEN Prioridad IS Pbaja");

        ISL.NewRule("Rule 7", "IF Demanda IS Alta AND Disponible IS Poco THEN Prioridad IS Palta");
        ISL.NewRule("Rule 8", "IF Demanda IS Alta AND Disponible IS Normal THEN Prioridad IS Pmedia");
        ISL.NewRule("Rule 9", "IF Demanda IS Alta AND Disponible IS Mucho THEN Prioridad IS Pbaja");
    }
Beispiel #24
0
        private void Form1_Load(object sender, EventArgs e)
        {
            /*
             * LinguisticVariable lvTemperature = new LinguisticVariable("Temperature", 0, 80);
             *
             * TrapezoidalFunction function1 = new TrapezoidalFunction(10, 15, TrapezoidalFunction.EdgeType.Right);
             * FuzzySet fsCold = new FuzzySet("Cold", function1);
             * TrapezoidalFunction function2 = new TrapezoidalFunction(10, 15, 20, 25);
             * FuzzySet fsCool = new FuzzySet("Cool", function2);
             * TrapezoidalFunction function3 = new TrapezoidalFunction(20, 25, 30, 35);
             * FuzzySet fsWarm = new FuzzySet("Warm", function3);
             * TrapezoidalFunction function4 = new TrapezoidalFunction(30, 35, TrapezoidalFunction.EdgeType.Left);
             * FuzzySet fsHot = new FuzzySet("Hot", function4);
             *
             * lvTemperature.AddLabel(fsCold);
             * lvTemperature.AddLabel(fsCool);
             * lvTemperature.AddLabel(fsWarm);
             * lvTemperature.AddLabel(fsHot);
             *
             * textBox1.Text += "Cold; Cool; Warm; Hot" + Environment.NewLine;
             * for (float x = 0; x < 80; x += 0.2f)
             * {
             *  float y1 = lvTemperature.GetLabelMembership("Cold", x);
             *  float y2 = lvTemperature.GetLabelMembership("Cool", x);
             *  float y3 = lvTemperature.GetLabelMembership("Warm", x);
             *  float y4 = lvTemperature.GetLabelMembership("Hot", x);
             *
             *  textBox1.Text += y1.ToString() + " " + y2.ToString() + " " + y3.ToString() + " " + y4.ToString() + Environment.NewLine;
             * }
             */

            /*
             * FuzzySet fsNear = new FuzzySet("Near", new TrapezoidalFunction(15, 50, TrapezoidalFunction.EdgeType.Right));
             * FuzzySet fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(15, 50, 60, 100));
             * FuzzySet fsFar = new FuzzySet("Far", new TrapezoidalFunction(60, 100, TrapezoidalFunction.EdgeType.Left));
             *
             * LinguisticVariable lvFront = new LinguisticVariable("FrontalDistance", 0, 120);
             * lvFront.AddLabel(fsNear);
             * lvFront.AddLabel(fsMedium);
             * lvFront.AddLabel(fsFar);
             *
             * FuzzySet fsZero = new FuzzySet("Zero", new TrapezoidalFunction(-10, 5, 5, 10));
             * FuzzySet fsLP = new FuzzySet("LittlePositive", new TrapezoidalFunction(5, 10, 20, 25));
             * FuzzySet fsP = new FuzzySet("Positive", new TrapezoidalFunction(20, 25, 35, 40));
             * FuzzySet fsVP = new FuzzySet("VeryPositive", new TrapezoidalFunction(35, 40, TrapezoidalFunction.EdgeType.Left));
             *
             * LinguisticVariable lvAngle = new LinguisticVariable("Angle", -10, 50);
             * lvAngle.AddLabel(fsZero);
             * lvAngle.AddLabel(fsLP);
             * lvAngle.AddLabel(fsP);
             * lvAngle.AddLabel(fsVP);
             *
             * Database fuzzyDB = new Database();
             * fuzzyDB.AddVariable(lvFront);
             * fuzzyDB.AddVariable(lvAngle);
             *
             * InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));
             *
             * IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero");
             * IS.NewRule("Rule 2", "IF FrontalDistance IS Near THEN Angle IS Positive");
             *
             * IS.SetInput("FrontalDistance", 20);
             * float a = IS.Evaluate("Angle"); // -> 29.999
             *
             * try
             * {
             *  FuzzyOutput fuzzyOutput = IS.ExecuteInference("Angle"); // -> 0.87 Positive
             *
             *  foreach (FuzzyOutput.OutputConstraint oc in fuzzyOutput.OutputList)
             *  {
             *      Console.WriteLine(oc.Label + " - " + oc.FiringStrength.ToString());
             *  }
             * }
             * catch (Exception)
             * {
             * }*/


            FuzzySet fsxM2 = new FuzzySet("xM2", new TrapezoidalFunction(-150, -80, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsxM1 = new FuzzySet("xM1", new TrapezoidalFunction(-90f, -65f, 0f));
            FuzzySet fsxS  = new FuzzySet("xS", new TrapezoidalFunction(-30f, 0, 30f));
            FuzzySet fsxD1 = new FuzzySet("xD1", new TrapezoidalFunction(0f, 65f, 90f));
            FuzzySet fsxD2 = new FuzzySet("xD2", new TrapezoidalFunction(80, 150, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvX = new LinguisticVariable("XDist", -150, 150);

            lvX.AddLabel(fsxM2);
            lvX.AddLabel(fsxM1);
            lvX.AddLabel(fsxS);
            lvX.AddLabel(fsxD1);
            lvX.AddLabel(fsxD2);


            FuzzySet fsfM3 = new FuzzySet("fM3", new TrapezoidalFunction(-190, -140, -90));
            FuzzySet fsfM2 = new FuzzySet("fM2", new TrapezoidalFunction(-140f, -90f, -45f));
            FuzzySet fsfM1 = new FuzzySet("fM1", new TrapezoidalFunction(-90f, -45f, 0f));
            FuzzySet fsfS  = new FuzzySet("fS", new TrapezoidalFunction(-30f, 0, 30f));
            FuzzySet fsfD1 = new FuzzySet("fD1", new TrapezoidalFunction(0f, 45f, 90f));
            FuzzySet fsfD2 = new FuzzySet("fD2", new TrapezoidalFunction(45f, 90f, 140f));
            FuzzySet fsfD3 = new FuzzySet("fD3", new TrapezoidalFunction(90, 140, 190));

            LinguisticVariable lvF = new LinguisticVariable("FAngle", -190, 190);

            lvF.AddLabel(fsfM3);
            lvF.AddLabel(fsfM2);
            lvF.AddLabel(fsfM1);
            lvF.AddLabel(fsfS);
            lvF.AddLabel(fsfD1);
            lvF.AddLabel(fsfD2);
            lvF.AddLabel(fsfD3);


            FuzzySet fsaM3 = new FuzzySet("aM3", new TrapezoidalFunction(-45, -30, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsaM2 = new FuzzySet("aM2", new TrapezoidalFunction(-45f, -30f, -5f));
            FuzzySet fsaM1 = new FuzzySet("aM1", new TrapezoidalFunction(-30f, -17f, -5f));
            FuzzySet fsaS  = new FuzzySet("aS", new TrapezoidalFunction(-5f, 0, 5f));
            FuzzySet fsaD1 = new FuzzySet("aD1", new TrapezoidalFunction(5f, 17f, 30f));
            FuzzySet fsaD2 = new FuzzySet("aD2", new TrapezoidalFunction(5f, 30f, 45f));
            FuzzySet fsaD3 = new FuzzySet("aD3", new TrapezoidalFunction(30, 45, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvA = new LinguisticVariable("OutAngle", -45, 45);

            lvA.AddLabel(fsaM3);
            lvA.AddLabel(fsaM2);
            lvA.AddLabel(fsaM1);
            lvA.AddLabel(fsaS);
            lvA.AddLabel(fsaD1);
            lvA.AddLabel(fsaD2);
            lvA.AddLabel(fsaD3);

            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvX);
            fuzzyDB.AddVariable(lvF);
            fuzzyDB.AddVariable(lvA);

            /*
             * float x = -100, F = 180, A = 45;
             * float Px = 0, Pf = 0, Pa = 0;
             * int Nx = -1, Nf = -1, Na = -1;
             *
             * float _t = lvX.GetLabelMembership("xM2", x);
             * if (_t > Px)
             * {
             *  Px = _t;
             *  Nx = 0;
             * }
             *
             * _t = lvX.GetLabelMembership("xM1", x);
             * if (_t > Px)
             * {
             *  Px = _t;
             *  Nx = 1;
             * }
             *
             * _t = lvX.GetLabelMembership("xS", x);
             * if (_t > Px)
             * {
             *  Px = _t;
             *  Nx = 2;
             * }
             *
             * _t = lvX.GetLabelMembership("xD1", x);
             * if (_t > Px)
             * {
             *  Px = _t;
             *  Nx = 3;
             * }
             *
             * _t = lvX.GetLabelMembership("xD2", x);
             * if (_t > Px)
             * {
             *  Px = _t;
             *  Nx = 4;
             * }*/



            InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            IS.NewRule("Rule 1", "IF XDist IS xM2 AND FAngle IS fD3 THEN OutAngle IS aD3");
            //Rule r = IS.GetRule("Rule 1");
            //Clause cl = r.Output;

            IS.SetInput("XDist", -100);
            IS.SetInput("FAngle", 180);

            float fu  = lvX.GetLabelMembership("xM2", -100); // 0.29
            float fuu = lvF.GetLabelMembership("fD3", 180);  // 0.2

            float a = IS.Evaluate("OutAngle");               // -> 38.2

            try
            {
                FuzzyOutput fuzzyOutput = IS.ExecuteInference("OutAngle"); // -> 0.2 ad3

                foreach (FuzzyOutput.OutputConstraint oc in fuzzyOutput.OutputList)
                {
                    Console.WriteLine(oc.Label + " - " + oc.FiringStrength.ToString());
                }
            }
            catch (Exception)
            {
            }
        }
        public FuzzyEngine()
        {
            // Linguistic labels (fuzzy sets) for Momentum
            var momDown    = new FuzzySet("Down", new TrapezoidalFunction(-20, 5, 5, 5));
            var momNeutral = new FuzzySet("Neutral", new TrapezoidalFunction(-20, 0, 0, 20));
            var momUp      = new FuzzySet("Up", new TrapezoidalFunction(5, 20, 20, 20));


            // Linguistic labels (fuzzy sets) for RSI
            var rsiLow    = new FuzzySet("Low", new TrapezoidalFunction(0, 30, 30, 30));
            var rsiMedium = new FuzzySet("Medium", new TrapezoidalFunction(0, 50, 50, 100));
            var rsiHigh   = new FuzzySet("High", new TrapezoidalFunction(70, 100, 100, 100));

            // MOM (Input)
            var lvMom = new LinguisticVariable("MOM", -20, 20);

            lvMom.AddLabel(momDown);
            lvMom.AddLabel(momNeutral);
            lvMom.AddLabel(momUp);

            // RSI (Input)
            var lvRsi = new LinguisticVariable("RSI", 0, 100);

            lvRsi.AddLabel(rsiLow);
            lvRsi.AddLabel(rsiMedium);
            lvRsi.AddLabel(rsiHigh);

            // Linguistic labels (fuzzy sets) that compose the Signal
            var fsShort = new FuzzySet("Sell", new TrapezoidalFunction(-100, 0, 0, 00));
            var fsHold  = new FuzzySet("Hold", new TrapezoidalFunction(-50, 0, 0, 50));
            var fsLong  = new FuzzySet("Buy", new TrapezoidalFunction(0, 100, 100, 100));

            // Output
            var lvSignal = new LinguisticVariable("Signal", -100, 100);

            lvSignal.AddLabel(fsShort);
            lvSignal.AddLabel(fsHold);
            lvSignal.AddLabel(fsLong);

            // The database
            var fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvMom);
            fuzzyDB.AddVariable(lvRsi);
            fuzzyDB.AddVariable(lvSignal);

            // Creating the inference system
            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Rules
            IS.NewRule("Rule 1", "IF RSI IS Low AND MOM IS Down THEN Signal IS Buy");
            IS.NewRule("Rule 2", "IF RSI IS Medium AND MOM IS Down THEN Signal IS Buy");
            IS.NewRule("Rule 3", "IF RSI IS High AND MOM IS Down THEN Signal IS Hold");

            IS.NewRule("Rule 4", "IF RSI IS Low AND MOM IS Neutral THEN Signal IS Buy");
            IS.NewRule("Rule 5", "IF RSI IS Medium AND MOM IS Neutral THEN Signal IS Hold");
            IS.NewRule("Rule 6", "IF RSI IS High AND MOM IS Neutral THEN Signal IS Sell");

            IS.NewRule("Rule 7", "IF RSI IS Low AND MOM IS Up THEN Signal IS Hold");
            IS.NewRule("Rule 8", "IF RSI IS Medium AND MOM IS Up THEN Signal IS Sell");
            IS.NewRule("Rule 9", "IF RSI IS High AND MOM IS Up THEN Signal IS Sell");
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            InferenceSystem IS;

            int    estatura = 0, simpatia = 0, inteligencia = 0, complexion = 0, tez = 0, bellezaE;
            float  belleza  = 0;
            string bellezaR = "";

            FuzzySet fsBajo  = new FuzzySet("Bajo", new TrapezoidalFunction(140, 155, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedio = new FuzzySet("Medio", new TrapezoidalFunction(160, 170, 175));
            FuzzySet fsAlto  = new FuzzySet("Alto", new TrapezoidalFunction(180, 190, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvEstatura = new LinguisticVariable("Estatura", 140, 190);

            lvEstatura.AddLabel(fsBajo);
            lvEstatura.AddLabel(fsMedio);
            lvEstatura.AddLabel(fsAlto);


            FuzzySet fsMalGenio  = new FuzzySet("MalGenio", new TrapezoidalFunction(0, 3, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsNeutro    = new FuzzySet("Neutro", new TrapezoidalFunction(4, 5, 6));
            FuzzySet fsAgradable = new FuzzySet("Agradable", new TrapezoidalFunction(7, 10, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvSimpatia = new LinguisticVariable("Simpatia", 0, 10);

            lvSimpatia.AddLabel(fsMalGenio);
            lvSimpatia.AddLabel(fsNeutro);
            lvSimpatia.AddLabel(fsAgradable);


            FuzzySet fsPocaIntel   = new FuzzySet("PocoInteligente", new TrapezoidalFunction(0, 3, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsNeutraIntel = new FuzzySet("InteligenciaNeutra", new TrapezoidalFunction(4, 5, 6));
            FuzzySet fsAltaIntel   = new FuzzySet("MuyInteligente", new TrapezoidalFunction(7, 10, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvInteligencia = new LinguisticVariable("Inteligencia", 0, 10);

            lvInteligencia.AddLabel(fsPocaIntel);
            lvInteligencia.AddLabel(fsNeutraIntel);
            lvInteligencia.AddLabel(fsAltaIntel);

            FuzzySet fsComplexionBaja   = new FuzzySet("ComplexionBaja", new TrapezoidalFunction(0, 3, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsComplexionNeutra = new FuzzySet("ComplexionNeutra", new TrapezoidalFunction(4, 5, 6));
            FuzzySet fsComplexionGrande = new FuzzySet("ComplexionGrande", new TrapezoidalFunction(7, 10, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvComplexion = new LinguisticVariable("Complexion", 0, 10);

            lvComplexion.AddLabel(fsComplexionBaja);
            lvComplexion.AddLabel(fsComplexionNeutra);
            lvComplexion.AddLabel(fsComplexionGrande);

            FuzzySet fsTezClara  = new FuzzySet("TezClara", new TrapezoidalFunction(0, 3, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsTezNeutra = new FuzzySet("TezNeutra", new TrapezoidalFunction(4, 5, 6));
            FuzzySet fsTezOscura = new FuzzySet("TezOscura", new TrapezoidalFunction(7, 10, TrapezoidalFunction.EdgeType.Left));


            LinguisticVariable lvTez = new LinguisticVariable("Tez", 0, 10);

            lvTez.AddLabel(fsTezClara);
            lvTez.AddLabel(fsTezNeutra);
            lvTez.AddLabel(fsTezOscura);

            FuzzySet fsBellezaBaja   = new FuzzySet("No_Chido", new TrapezoidalFunction(0, 3, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsBellezaNeutra = new FuzzySet("Chido", new TrapezoidalFunction(4, 5, 6));
            FuzzySet fsBellezaAlta   = new FuzzySet("Muy_Chido", new TrapezoidalFunction(7, 10, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvBelleza = new LinguisticVariable("Belleza", 0, 10);

            lvBelleza.AddLabel(fsBellezaBaja);
            lvBelleza.AddLabel(fsBellezaNeutra);
            lvBelleza.AddLabel(fsBellezaAlta);


            Console.WriteLine("INGRESA LA ESTATURA (140 a 190 cm)");
            estatura = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("INGRESA LA SIMPATIA (1=Mal Genio     10=Muy simpático)");
            simpatia = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Ingresa la Inteligencia del 1 al 10 (No creo que deba explicarlo xd))");
            inteligencia = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("¿Qué complexión tiene? 1=Nada en forma       10=En forma B)");
            complexion = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Ingresa la Tez   1=Oscura        10=Blanco");
            tez = Convert.ToInt32(Console.ReadLine());


            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvEstatura);
            fuzzyDB.AddVariable(lvSimpatia);
            fuzzyDB.AddVariable(lvInteligencia);
            fuzzyDB.AddVariable(lvComplexion);
            fuzzyDB.AddVariable(lvTez);
            fuzzyDB.AddVariable(lvBelleza);



            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));



            IS.NewRule("Rule 1", "IF Estatura IS Alto  THEN Belleza IS Muy_Chido");
            IS.NewRule("Rule 2", "IF Simpatia IS Agradable  THEN Belleza IS Muy_Chido");
            IS.NewRule("Rule 3", "IF Inteligencia IS MuyInteligente  THEN Belleza IS Muy_Chido");
            IS.NewRule("Rule 4", "IF Complexion IS ComplexionGrande  THEN Belleza IS Muy_Chido");
            IS.NewRule("Rule 5", "IF Tez IS TezOscura  THEN Belleza IS Muy_Chido");

            IS.NewRule("Rule 6", "IF Estatura IS Medio THEN Belleza IS Chido");
            IS.NewRule("Rule 7", "IF Simpatia IS Neutro  THEN Belleza IS Chido");
            IS.NewRule("Rule 8", "IF Inteligencia IS InteligenciaNeutra  THEN Belleza IS Chido");
            IS.NewRule("Rule 9", "IF Complexion IS ComplexionNeutra  THEN Belleza IS Chido");
            IS.NewRule("Rule 10", "IF Tez IS TezNeutra  THEN Belleza IS Chido");

            IS.NewRule("Rule 11", "IF Estatura IS Bajo THEN Belleza IS No_Chido");
            IS.NewRule("Rule 12", "IF Simpatia IS MalGenio  THEN Belleza IS No_Chido");
            IS.NewRule("Rule 13", "IF Inteligencia IS PocoInteligente  THEN Belleza IS No_Chido");
            IS.NewRule("Rule 14", "IF Complexion IS ComplexionBaja  THEN Belleza IS No_Chido");
            IS.NewRule("Rule 15", "IF Tez IS TezClara  THEN Belleza IS No_Chido");


            IS.SetInput("Estatura", estatura);
            IS.SetInput("Simpatia", simpatia);
            IS.SetInput("Inteligencia", inteligencia);
            IS.SetInput("Complexion", complexion);
            IS.SetInput("Tez", tez);

            belleza = IS.Evaluate("Belleza");


            //belleza.ToString("##0");
            bellezaE = Convert.ToInt32(belleza.ToString("##0"));

            Console.WriteLine("*****************************************************");
            Console.WriteLine(belleza);

            //Console.WriteLine(IS.SetInput("Belleza", belleza));

            //Console.WriteLine(IS.GetLinguisticVariable("Belleza").GetLabel("Muy_Chido").Name);

            switch (bellezaE)
            {
            case int n when(n >= 0 && n <= 3):
                bellezaR = IS.GetLinguisticVariable("Belleza").GetLabel("No_Chido").Name.ToString();

                break;

            case int n when(n >= 4 && n <= 6):
                bellezaR = IS.GetLinguisticVariable("Belleza").GetLabel("Chido").Name.ToString();

                break;

            case int n when(n >= 7 && n <= 10):
                bellezaR = IS.GetLinguisticVariable("Belleza").GetLabel("Muy_Chido").Name.ToString();

                break;
            }

            Console.WriteLine(bellezaR);
        }
Beispiel #27
0
        public void JNCK()
        {
            InitializeComponent();
            // INPUT

            // Kecepatan (0-120)
            FuzzySet fsLambat = new FuzzySet("Lambat", new TrapezoidalFunction(30, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsSedang = new FuzzySet("Sedang", new TrapezoidalFunction(40, 60, 80));
            FuzzySet fsCepat  = new FuzzySet("Cepat", new TrapezoidalFunction(70, 80, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvKecepatan = new LinguisticVariable("Kecepatan", 0, 120);

            lvKecepatan.AddLabel(fsLambat);
            lvKecepatan.AddLabel(fsSedang);
            lvKecepatan.AddLabel(fsCepat);

            // Jarak (0-10)
            FuzzySet fsDekat      = new FuzzySet("Dekat", new TrapezoidalFunction(1, 2, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsJauh       = new FuzzySet("Jauh", new TrapezoidalFunction(1, 4, 5));
            FuzzySet fsSangatJauh = new FuzzySet("SangatJauh", new TrapezoidalFunction(4, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Jarak
            LinguisticVariable lvJarak = new LinguisticVariable("Jarak", 0, 10);

            lvJarak.AddLabel(fsDekat);
            lvJarak.AddLabel(fsJauh);
            lvJarak.AddLabel(fsSangatJauh);

            // Kemiringan Jalan ((-90)-90)
            FuzzySet fsTurun = new FuzzySet("Turun", new TrapezoidalFunction(-40, -20, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsDatar = new FuzzySet("Datar", new TrapezoidalFunction(-25, 0, 25));
            FuzzySet fsNaik  = new FuzzySet("Naik", new TrapezoidalFunction(20, 40, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kemiringan Jalan
            LinguisticVariable lvKemiringan = new LinguisticVariable("Kemiringan", -90, 90);

            lvKemiringan.AddLabel(fsTurun);
            lvKemiringan.AddLabel(fsDatar);
            lvKemiringan.AddLabel(fsNaik);

            // OUTPUT

            // Tingkat Pengereman (0-10)
            FuzzySet fsLemah  = new FuzzySet("Lemah", new TrapezoidalFunction(3, 4, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Sedang", new TrapezoidalFunction(3, 4, 6, 7));
            FuzzySet fsKuat   = new FuzzySet("Kuat", new TrapezoidalFunction(6, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvTingkatPengereman = new LinguisticVariable("TingkatPengereman", 0, 10);

            lvTingkatPengereman.AddLabel(fsLemah);
            lvTingkatPengereman.AddLabel(fsMedium);
            lvTingkatPengereman.AddLabel(fsKuat);

            // Database
            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvJarak);
            fuzzyDB.AddVariable(lvKemiringan);
            fuzzyDB.AddVariable(lvKecepatan);
            fuzzyDB.AddVariable(lvTingkatPengereman);

            // Inferensi System Engine
            InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Rules
            IS.NewRule("Rule 1", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 2", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 3", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 4", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 5", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 6", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 7", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 8", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 9", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 10", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 11", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 12", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 13", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 14", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 15", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 16", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 17", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 18", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 19", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 20", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 21", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 22", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 23", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 24", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 25", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 26", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 27", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");

            // Set Input
            IS.SetInput("Kecepatan", (float)speed);
            IS.SetInput("Jarak", (float)distance);
            IS.SetInput("Kemiringan", (float)angle);

            // Get output
            double BreakLevel = IS.Evaluate("TingkatPengereman");

            // Tampilkan Hasil
            System.Console.WriteLine(BreakLevel);
        }
Beispiel #28
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // rms
            FuzzySet fsLowRMS = new FuzzySet("Low", new TrapezoidalFunction(
                                                 (float)RMSmin,
                                                 Divide(RMSmin, RMSmax, 3, 1),
                                                 TrapezoidalFunction.EdgeType.Right));

            FuzzySet fsAverageRMS = new FuzzySet("Average", new TrapezoidalFunction(
                                                     (float)RMSmin,
                                                     Divide(RMSmin, RMSmax, 3, 1),
                                                     Divide(RMSmin, RMSmax, 3, 2),
                                                     (float)RMSmax));

            FuzzySet fsHighRMS = new FuzzySet("High", new TrapezoidalFunction(
                                                  Divide(RMSmin, RMSmax, 3, 2),
                                                  (float)RMSmax,
                                                  TrapezoidalFunction.EdgeType.Left));

            // повороты
            FuzzySet fsLowTurns = new FuzzySet("Low", new TrapezoidalFunction(
                                                   turnsMin,
                                                   Divide(turnsMin, turnsMax, 3, 1),
                                                   TrapezoidalFunction.EdgeType.Right));

            FuzzySet fsAverageTurns = new FuzzySet("Average", new TrapezoidalFunction(
                                                       turnsMin,
                                                       Divide(turnsMin, turnsMax, 3, 1),
                                                       Divide(turnsMin, turnsMax, 3, 2),
                                                       turnsMax));

            FuzzySet fsHighTurns = new FuzzySet("High", new TrapezoidalFunction(
                                                    Divide(turnsMin, turnsMax, 3, 2),
                                                    turnsMax,
                                                    TrapezoidalFunction.EdgeType.Left));


            LinguisticVariable lvRMS = new LinguisticVariable("RMS", (float)RMSmin, (float)RMSmax);

            lvRMS.AddLabel(fsLowRMS);
            lvRMS.AddLabel(fsAverageRMS);
            lvRMS.AddLabel(fsHighRMS);

            LinguisticVariable lvTurns = new LinguisticVariable("Turns", turnsMin, turnsMax);

            lvTurns.AddLabel(fsLowTurns);
            lvTurns.AddLabel(fsAverageTurns);
            lvTurns.AddLabel(fsHighTurns);

            // выход
            FuzzySet fsСlonus    = new FuzzySet("True", new SingletonFunction(1));
            FuzzySet fsClonusNot = new FuzzySet("False", new SingletonFunction(0));

            LinguisticVariable lvClonus = new LinguisticVariable("Clonus", 0, 1);

            lvClonus.AddLabel(fsСlonus);
            lvClonus.AddLabel(fsClonusNot);

            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvClonus);
            fuzzyDB.AddVariable(lvRMS);
            fuzzyDB.AddVariable(lvTurns);

            InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            IS.NewRule("Rule 1", "IF RMS IS Low OR Turns IS Low THEN Clonus IS False");

            IS.NewRule("Rule 2", "IF RMS IS High AND Turns IS High THEN Clonus IS True");
        }
        public FuzzyContainer()
        {
            registredVariables = new List <string>();

            //var HR = new LinguisticVariable("HR", 0, 200);
            //new List<FuzzySet>()
            //{
            //	new FuzzySet("Low", new TrapezoidalFunction(0, 5, 45, 50)),
            //	new FuzzySet("Medium", new TrapezoidalFunction(50, 55, 115, 120)),
            //	new FuzzySet("High", new TrapezoidalFunction(120, 125, 195 ,200))
            //}.ForEach(x => HR.AddLabel(x));



            var impact = new LinguisticVariable("IMPACT", 0, 100);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)),
                new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)),
                new FuzzySet("High", new TrapezoidalFunction(50, 55, 95, 100))
            }.ForEach(x => impact.AddLabel(x));
            registredVariables.Add(impact.Name);


            Console.WriteLine("IMPACT name: " + impact.Name);


            var onGround = new LinguisticVariable("ON_GROUND", -0.5f, 1.5f);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)),
                new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)),
                new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f))
            }.ForEach(x => onGround.AddLabel(x));
            registredVariables.Add(onGround.Name);

            var timeOnGround = new LinguisticVariable("TIME_ON_GROUND", -1, 901);

            new List <FuzzySet>()
            {
                new FuzzySet("Brief", new TrapezoidalFunction(-1, 1, 1, 2)),
                new FuzzySet("Short", new TrapezoidalFunction(1, 5, 10, 15)),
                new FuzzySet("Moderate", new TrapezoidalFunction(10, 120, 480, 720)),
                new FuzzySet("Long", new TrapezoidalFunction(480, 900, 900, 901))
            }.ForEach(x => timeOnGround.AddLabel(x));
            registredVariables.Add(timeOnGround.Name);


            //Output
            var fallWearable = new LinguisticVariable("FALL", -0.5f, 1.5f);

            new List <FuzzySet>()
            {
                new FuzzySet("Low", new TrapezoidalFunction(-0.5f, -0.2f, 0.2f, 0.5f)),
                new FuzzySet("Medium", new TrapezoidalFunction(0.1f, 0.5f, 0.5f, 0.9f)),
                new FuzzySet("High", new TrapezoidalFunction(0.5f, 0.8f, 1.2f, 1.5f))
            }.ForEach(x => fallWearable.AddLabel(x));


            //var heartRate = new LinguisticVariable("HEART_RATE", 0, 100);
            //new List<FuzzySet>()
            //{
            //	new FuzzySet("Low", new TrapezoidalFunction(0, 5, 25, 30)),
            //	new FuzzySet("Medium", new TrapezoidalFunction(20, 25, 55, 60)),
            //	new FuzzySet("High", new TrapezoidalFunction(50, 55, 95 ,100))
            //}.ForEach(x => heartRate.AddLabel(x));


            var db = new Database();

            //db.AddVariable(HR);
            //db.AddVariable(heartRate);

            db.AddVariable(impact);
            db.AddVariable(onGround);
            db.AddVariable(timeOnGround);
            db.AddVariable(fallWearable);


            fis = new InferenceSystem(db, new CentroidDefuzzifier(1000));

            //         fis.NewRule("Rule 1", "IF HR IS Low THEN HEART_RATE IS Low");
            //fis.NewRule("Rule 2", "IF HR IS Medium THEN HEART_RATE IS Medium");
            //fis.NewRule("Rule 3", "IF HR IS High THEN HEART_RATE IS High");


            fis.NewRule("Rule 4", "IF IMPACT IS High AND ON_GROUND IS High AND TIME_ON_GROUND IS Long THEN FALL IS High");
            fis.NewRule("Rule 5", "IF IMPACT IS Medium AND ON_GROUND IS High AND TIME_ON_GROUND IS Long THEN FALL IS High");
            fis.NewRule("Rule 6", "IF IMPACT IS Low AND ON_GROUND IS Low AND (TIME_ON_GROUND IS Short OR TIME_ON_GROUND IS Brief) THEN FALL IS Low");
            fis.NewRule("Rule 7", "IF IMPACT IS Medium AND ON_GROUND IS Medium AND TIME_ON_GROUND IS Moderate THEN FALL IS Medium");
            fis.NewRule("Rule 8", "IF IMPACT IS High AND ON_GROUND IS Medium AND (TIME_ON_GROUND IS Short OR TIME_ON_GROUND IS Brief) THEN FALL IS Medium");



            e2l = new EventToLabel();
        }
Beispiel #30
0
        // Hardcode initializing the Fuzzy Inference System
        void InitFuzzyEngine( )
        {
            // Linguistic labels (fuzzy sets) that compose the distances
            FuzzySet fsNear   = new FuzzySet("Near", new TrapezoidalFunction(15, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(15, 50, 60, 100));
            FuzzySet fsFar    = new FuzzySet("Far", new TrapezoidalFunction(60, 100, TrapezoidalFunction.EdgeType.Left));

            // Right Distance (Input)
            LinguisticVariable lvRight = new LinguisticVariable("RightDistance", 0, 120);

            lvRight.AddLabel(fsNear);
            lvRight.AddLabel(fsMedium);
            lvRight.AddLabel(fsFar);

            // Left Distance (Input)
            LinguisticVariable lvLeft = new LinguisticVariable("LeftDistance", 0, 120);

            lvLeft.AddLabel(fsNear);
            lvLeft.AddLabel(fsMedium);
            lvLeft.AddLabel(fsFar);

            // Front Distance (Input)
            LinguisticVariable lvFront = new LinguisticVariable("FrontalDistance", 0, 120);

            lvFront.AddLabel(fsNear);
            lvFront.AddLabel(fsMedium);
            lvFront.AddLabel(fsFar);

            // Linguistic labels (fuzzy sets) that compose the angle
            FuzzySet fsVN   = new FuzzySet("VeryNegative", new TrapezoidalFunction(-40, -35, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsN    = new FuzzySet("Negative", new TrapezoidalFunction(-40, -35, -25, -20));
            FuzzySet fsLN   = new FuzzySet("LittleNegative", new TrapezoidalFunction(-25, -20, -10, -5));
            FuzzySet fsZero = new FuzzySet("Zero", new TrapezoidalFunction(-10, 5, 5, 10));
            FuzzySet fsLP   = new FuzzySet("LittlePositive", new TrapezoidalFunction(5, 10, 20, 25));
            FuzzySet fsP    = new FuzzySet("Positive", new TrapezoidalFunction(20, 25, 35, 40));
            FuzzySet fsVP   = new FuzzySet("VeryPositive", new TrapezoidalFunction(35, 40, TrapezoidalFunction.EdgeType.Left));

            // Angle
            LinguisticVariable lvAngle = new LinguisticVariable("Angle", -50, 50);

            lvAngle.AddLabel(fsVN);
            lvAngle.AddLabel(fsN);
            lvAngle.AddLabel(fsLN);
            lvAngle.AddLabel(fsZero);
            lvAngle.AddLabel(fsLP);
            lvAngle.AddLabel(fsP);
            lvAngle.AddLabel(fsVP);

            // The database
            Database fuzzyDB = new Database( );

            fuzzyDB.AddVariable(lvFront);
            fuzzyDB.AddVariable(lvLeft);
            fuzzyDB.AddVariable(lvRight);
            fuzzyDB.AddVariable(lvAngle);

            // Creating the inference system
            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Going Straight
            IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero");
            // Going Straight (if can go anywhere)
            IS.NewRule("Rule 2", "IF FrontalDistance IS Far AND RightDistance IS Far AND LeftDistance IS Far THEN Angle IS Zero");
            // Near right wall
            IS.NewRule("Rule 3", "IF RightDistance IS Near AND LeftDistance IS Not Near THEN Angle IS LittleNegative");
            // Near left wall
            IS.NewRule("Rule 4", "IF RightDistance IS Not Near AND LeftDistance IS Near THEN Angle IS LittlePositive");
            // Near front wall - room at right
            IS.NewRule("Rule 5", "IF RightDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive");
            // Near front wall - room at left
            IS.NewRule("Rule 6", "IF LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Negative");
            // Near front wall - room at both sides - go right
            IS.NewRule("Rule 7", "IF RightDistance IS Far AND LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive");
        }
Beispiel #31
0
        public static void Main()
        {
            // linguistic labels (fuzzy sets) that compose the distances
            var fsNear = new FuzzySet("Near", new TrapezoidalFunction(
                                          450, 500, TrapezoidalFunction.EdgeType.Left));
            var fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(
                                            100, 250, 460, 500));
            var fsFar = new FuzzySet("Far", new TrapezoidalFunction(
                                         0, 250, TrapezoidalFunction.EdgeType.Right));

            // right Distance (Input)
            var lvDist = new LinguisticVariable("Distance", 0, 500);

            lvDist.AddLabel(fsNear);
            lvDist.AddLabel(fsMedium);
            lvDist.AddLabel(fsFar);

            // linguistic labels (fuzzy sets) that compose the angle
            var fsVeryDownSpeed = new FuzzySet("VeryNegative", new TrapezoidalFunction(
                                                   -100, -10, TrapezoidalFunction.EdgeType.Right));
            var fsDownSpeed = new FuzzySet("Negative", new TrapezoidalFunction(
                                               -50, -30, -15, -10));
            var fsLittleDownSpeed = new FuzzySet("LittleNegative", new TrapezoidalFunction(
                                                     -15, -8, -5, -1));
            var fsZero = new FuzzySet("Zero", new TrapezoidalFunction(
                                          -10, 0, 5, 10));
            var fsLittleUpSpeed = new FuzzySet("LittlePositive", new TrapezoidalFunction(
                                                   0, 5, 20, 30));
            var fsUpSpeed = new FuzzySet("Positive", new TrapezoidalFunction(
                                             20, 25, 35, 40));
            var fsVeryUpSpeed = new FuzzySet("VeryPositive", new TrapezoidalFunction(
                                                 35, 100, TrapezoidalFunction.EdgeType.Left));

            // angle
            var lvSpeed = new LinguisticVariable("Speed", -100, 100);

            lvSpeed.AddLabel(fsVeryDownSpeed);
            lvSpeed.AddLabel(fsDownSpeed);
            lvSpeed.AddLabel(fsLittleDownSpeed);
            lvSpeed.AddLabel(fsZero);
            lvSpeed.AddLabel(fsLittleUpSpeed);
            lvSpeed.AddLabel(fsUpSpeed);
            lvSpeed.AddLabel(fsVeryUpSpeed);

            // the database
            var fuzzyDb = new Database( );

            fuzzyDb.AddVariable(lvDist);
            fuzzyDb.AddVariable(lvSpeed);

            // creating the inference system
            var IS = new InferenceSystem(fuzzyDb, new CentroidDefuzzifier(1000));

            // going Straight
            IS.NewRule("Rule 1", "IF Distance IS Far THEN Speed IS VeryPositive");
            // going Straight (if can go anywhere)
            IS.NewRule("Rule 2", "IF Distance IS Medium THEN Speed IS Positive");
            // near right wall
            IS.NewRule("Rule 3", "IF Distance IS Near THEN Speed IS Negative");
            // near left wall

            IS.SetInput("Distance", 0);

            /*try
             * {
             * double NewSpeed = IS.Evaluate( "Speed" );
             * Console.WriteLine("Speed = {0} ", NewSpeed );
             * }
             * catch ( Exception )
             * {
             * Console.WriteLine("Speed not s");
             * }
             * Console.ReadLine();
             */
            double curDist  = 0;
            double newSpeed = 0;

            while (curDist < 500)
            {
                newSpeed = IS.Evaluate("Speed");
                curDist += 2 * newSpeed / 3600;
                Console.WriteLine("Speed = {0}, position = {1} ", newSpeed, curDist);
                IS.SetInput("Distance", (float)(curDist));
                //Console.ReadLine();
            }
            Console.ReadLine();
        }