示例#1
0
        /// <summary>
        /// FUZZY 'IS' RULE
        /// 
        /// "IF 
        ///     val1 is a member of fs1, 
        /// THEN 
        ///     fs3 IS fs4
        /// </summary>
        /// <param name="val1">Antecedent 1</param> 
        /// <param name="fs1">Antecedent Set 1</param>
        /// <param name="fs3">Consequent Output</param>
        /// <param name="fs4">Consequent</param>
        /// <param name="ftemp">Rule Applicability Output Set</param>
        public static FuzzySet IS(double val1, FuzzySet fs1, ref FuzzySet fs3, FuzzySet fs4,
                                FuzzySet ruleSet)
        {
            double lowRange = fs4.GetLowRange();
            double highRange = fs4.GetHighRange();

            string consName = fs3.Id;
            Brush consColour = fs3.LineColour;

            FuzzySet ftemp = new FuzzySet(ruleSet);
            ftemp.Clear();
            ftemp.SetRangeWithPoints(lowRange, highRange);

            double membership = fs1.Fuzzify(val1);

            if (membership > 0)
            {
                ftemp = Operations.ScaleFS(fs4, membership);
                ftemp.LineColour = ruleSet.LineColour;
                ftemp.Id = ruleSet.Id;

                fs3 = Operations.UnionFS(fs3, ftemp, ruleSet.LineColour);
                fs3.Id = consName;
                fs3.LineColour = consColour;
            }

            return ftemp;
        }
示例#2
0
        /// <summary>
        /// Defizzify a FuzzySet and get its CENTER OF GRAVITY
        /// </summary>
        /// <param name="fs">Input Set</param>
        /// <returns>Center of Gravity</returns>
        public static double DeFuzzifyCOG(FuzzySet fs)
        {
            if (fs == null) { return -1; }

            int points = (int)(((double)fs.GetNumPoints()) * 1.9 + 1);

            if (points < 21) points = 21;

            if (points < 4 || points > 1000) { return -1; }
            if (fs.Invalid()) { fs.Err = 10; return -1; }
            double sumTop = 0;
            double sumBottom = 0;
            double w, s, r, step;
            r = fs.HighRange - fs.LowRange;
            step = r / (points - 1);
            int i;
            for (i = 0; i < points; i++)
            {
                w = fs.LowRange + step * i;
                s = fs.Fuzzify(w);
                sumTop = sumTop + s * w;
                sumBottom = sumBottom + s;
            }
            if (AEqual(0, sumBottom)) { fs.Err = 15; return -1; }

            return sumTop / sumBottom;
        }
示例#3
0
        /// <summary>
        /// Performs a CLIP on a Fuzzy Set
        /// </summary>
        /// <param name="fs">The Fuzzy Set to Clip</param>
        /// <param name="top">The scalar amount to Clip the Fuzzy Set to</param>
        /// <returns>Clipped Fuzzy Set</returns>
        public static FuzzySet ClipFS(FuzzySet fs, double clipVal)
        {
            FuzzySet fuzz = new FuzzySet(fs);

            fuzz.UopFS(fuzz, 1, clipVal);

            return fuzz;
        }
示例#4
0
        /// <summary>
        /// Returns the COMPLIMENT (inverse) of the Given Fuzzy Set
        /// </summary>
        /// <param name="fs">Fuzzy Set to find the compliment of</param>
        /// <returns>The Compliment Set</returns>
        public static FuzzySet ComplimentFS(FuzzySet fs)
        {
            FuzzySet fuzz = new FuzzySet(fs);

            fuzz.NotFS(fuzz);

            return fuzz;
        }
        private void SetupExampleSet1()
        {
            //Add a new Fuzzy Set to the Collection
            ExampleSets.Add("Example 1", new FuzzySet());

            //Initialize the new Fuzzy Set
            ExampleSets["Example 1"] = new FuzzySet("Example 1", 0, 100);
            ExampleSets["Example 1"].LineColour = new SolidBrush(Color.Brown);

            //Now, define the points in the Set
            ExampleSets["Example 1"].AddPoint(0, 0);
            ExampleSets["Example 1"].AddPoint(25, 0.8);
            ExampleSets["Example 1"].AddPoint(50, 0.8);
            ExampleSets["Example 1"].AddPoint(60, 0.3);
            ExampleSets["Example 1"].AddPoint(90, 0.3);
            ExampleSets["Example 1"].AddPoint(100, 0);
        }
示例#6
0
        /// <summary>
        /// Adds a new Fuzzy Set (Checks for naming 
        /// conflicts first)    
        /// </summary>
        /// <param name="_fs"></param>
        /// <returns></returns>
        public int Add(FuzzySet _fs)
        {
            // adds a fuzzy set (checks name first)
                // -1 = fails
            FuzzySet  k = Find(_fs.GetName());

            if (k != null)
                return -1;

            int i = FindEmpty();
            if (i==-1)
                return -1;

            f[i] = _fs;

            if (i >= numFuzzySets) numFuzzySets=i+1;
            return i;
        }
示例#7
0
        /// <summary>
        /// Copy one set to another if invalid it will still copy
        /// </summary>
        /// <param name="copyTo"></param>
        /// <param name="copyFrom"></param>
        /// <returns></returns>
        public static bool CopyFS(FuzzySet copyTo, FuzzySet copyFrom)
        {
            if (copyTo == null || copyFrom == null) { return false; }

            copyTo.Id = copyFrom.Id;

            copyTo.LowRange = copyFrom.LowRange;
            copyTo.HighRange = copyFrom.HighRange;
            copyTo.Valid = copyFrom.Valid;
            copyTo.Err = copyFrom.Err;
            int i;
            for (i = 0; i < copyFrom.NumPoints; i++)
            {
                copyTo.WorldValue[i] = copyFrom.WorldValue[i]; // X values range lowRange .. highRange
                copyTo.SetValue[i] = copyFrom.SetValue[i]; // Y values range 0..1
            }
            return true;
        }
示例#8
0
        /// <summary>
        /// FUZZY 'AND' RULE
        /// 
        /// "IF 
        ///     val1 is a member of fs1, 
        /// AND
        ///     val2 is a member of fs2
        /// THEN 
        ///     fs3 IS fs4
        /// </summary>
        /// <param name="val1">Antecedent 1</param> 
        /// <param name="fs1">Antecedent Set 1</param>
        /// <param name="val2">Antecedent 2</param>
        /// <param name="fs2">Antecedent Set 2</param>
        /// <param name="fs3">Consequent Output</param>
        /// <param name="fs4">Consequent</param>
        /// <param name="ftemp">Rule Applicability Output Set</param>
        public static FuzzySet AND(double val1, FuzzySet fs1, double val2, FuzzySet fs2, ref FuzzySet fs3, FuzzySet fs4,
                               FuzzySet ruleSet)
        {
            double lowRange = fs4.GetLowRange();
            double highRange = fs4.GetHighRange();

            //... and of the Consequent Output...
            string consName = fs3.Id;
            Brush consColour = fs3.LineColour;

            FuzzySet ftemp = new FuzzySet(ruleSet);
            ftemp.Clear();
            ftemp.SetRangeWithPoints(lowRange, highRange);

            double fval1 = fs1.Fuzzify(val1);
            double fval2 = fs2.Fuzzify(val2);

            double membership = Math.Min(fval1, fval2); //MIN for AND

            if (membership > 0)
            {
                FuzzySet oldRule = new FuzzySet(ftemp);

                ftemp = new FuzzySet(Operations.ScaleFS(fs4, membership));
                ftemp.LineColour = ruleSet.LineColour;
                ftemp.Id = ruleSet.Id;

                if (ftemp.GetNumPoints() < 2)
                    ftemp = oldRule;

                fs3 = new FuzzySet(Operations.UnionFS(fs3, ftemp, consColour));
                fs3.Id = consName;

            }

            return ftemp;
        }
示例#9
0
        /**
        * Defuzzify a set using the Mean of Maximums aproximation function
        * if it fails it returns -1 (which may be a valid answer)
        */
        /// <summary>
        /// Defizzify a FuzzySet and get its MEAN OF MAXIMUMS
        /// </summary>
        /// <param name="fs"></param>
        /// <returns>Mean of Maximums</returns>
        public static double DeFuzzifyMOM(FuzzySet fs)
        {
            if (fs == null) { return -1; }
            if (fs.Invalid()) { fs.Err = 10; return -1; }
            double m = fs.GetMaxSetValue();
            double sumTop = 0;
            double sumBottom = 0;
            double w;
            int i;
            for (i = 0; i < fs.GetNumPoints(); i++)
            {
                if (AEqual(fs.SetValue[i], m))
                {
                    w = fs.WorldValue[i];

                    sumTop = sumTop + w;
                    sumBottom = sumBottom + 1;
                }
            }
            if (AEqual(0, sumBottom)) { fs.Err = 15; return -1; }

            return sumTop / sumBottom;
        }
示例#10
0
        /// <summary>
        /// Performs an Intersection on two FuzzySets
        /// </summary>
        /// <param name="fs1">Fuzzy Set 1</param>
        /// <param name="fs2">Fuzzy Set 2</param>
        /// <param name="colour">The colour of the resulting set</param>
        /// <returns>The resulting Set</returns>
        public static FuzzySet IntersectionFS(FuzzySet fs1, FuzzySet fs2, Brush colour)
        {
            FuzzySet fuzz = new FuzzySet();

            fuzz.IntersectionFS(fuzz, fs1, fs2);

            fuzz.LineColour = colour;

            return fuzz;
        }
        /// <summary>
        /// Sets up the Throttle Fuzzy Sets for the Throttle FuzzyCollection
        /// </summary>
        private void SetThrottleSets()
        {
            #region Throttle Set Definition - T_None, T_Soft, T_Medium, T_Hard

                ThrottleSets = new FuzzyCollection("Throttle Sets", null);

                ThrottleSets.Add("T_None", new FuzzySet());
                ThrottleSets["T_None"] = new FuzzySet("T_None", 0, 100);
                ThrottleSets["T_None"].LineColour = new SolidBrush(Color.Gray);
                ThrottleSets["T_None"].AddPoint(0, 1, false, false);
                ThrottleSets["T_None"].AddPoint(8, 0, false, false);
                ThrottleSets["T_None"].AddPoint(100, 0, false, false);

                #endregion
        }
        /// <summary>
        /// This is where the guts of it all goes down. 
        /// 
        /// Remember that because of the nature of C#, items within a collection
        /// CANNOT BE PASSED BY REFERENCE! Thus, if you are making an alteration to any 
        /// set within a method where the set is passed by reference (ref), you will
        /// need to assign the FuzzySet to a variable, pass that variable, and then set
        /// the oiginal FuzzySet within the Collection to the altered variable.
        /// A little bit of frigging around, but it works.
        /// </summary>
        public override void CalculateFuzzyLogic()
        {
            //Get the vars for this Simulator - dont alter this!
                _lander = ((LanderSim)Globals.Simulator).SpaceShip;

                //Assign the sets to variables
                FuzzySet tResult = new FuzzySet(ThrottleOutputs["ThrottleResult"]);

                //Clear the ThrottleResult Set so that we can repopulate it with new data
                tResult.Clear();
                tResult.SetRangeWithPoints(0, 100);

                //WRITE YOUR RULES LIKE THIS....
                //(dont forget to pass the
                //accumulator variable by reference, and also pass the Rule itself
                //Hot Tip: COMMENT YOUR RULES SO YOU KNOW WHAT THEY DO!

                // Rule 0: IF Height is High THEN Throttle -> Soft
                //RuleSets["Rule0"] = Rule.IS(_lander.Y, HeightSets["high"], ref tResult, ThrottleSets["soft"],RuleSets["Rule0"]);

                /*
                 *
                 * Rules go here....
                 *
                 *
                 */

                //reassign the variables to the sets
                ThrottleOutputs["ThrottleResult"] = new FuzzySet(tResult);

                if (!Manual)
                {
                    //THIS IS THE THROTTLE VALUE SET BY PRESSING THE BUTTONS
                    _lander.Throttle = throttle;

                    //Limit Throttle (incase of ridiculous values)
                    if (_lander.Throttle < 0)
                        _lander.Throttle = 0;

                    if (_lander.Throttle > 100)
                        _lander.Throttle = 100;

                    //IF YOU ARE WRITING RULES FOR THE SIDE-THRUST,
                    // You will need to defuzzify into _lander.Left and _lander.Right
                    // Otherwise, leave these here to control your lander with the function buttons
                    _lander.Left = throttleL;
                    _lander.Right = throttleR;

                }
                else
                {
                    //THIS IS THE THROTTLE VALUE DEFUZZIFIED BY THE RULESETS
                    _lander.Throttle = Operations.DeFuzzifyCOG(ThrottleOutputs["ThrottleResult"]);
                }

                //Save the state of the Lander - dont alter this
                ((LanderSim) (Globals.Simulator)).SpaceShip = _lander;
        }
        public override void CalculateFuzzyLogic()
        {
            //START
            harrier = ((HarrierSim)Globals.Simulator).Harrier;

            double height;

            if (    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy)     ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium)   ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard)     )
                height = harrier.Y - 23;
            else
                height = harrier.Y - 5;

            double speedY = harrier.YVel;
            double speedX = harrier.XVel;
            double safeX = harrier.X - harrier.MidSafeX - 40;

            //FuzzySet throttleOutput = ;
            //FuzzySet thrustVectorOutput = ;

            FuzzySet throttleOutput = new FuzzySet(ThrottleAccum["ThrottleOutput"]);
            FuzzySet thrustVectorOutput = new FuzzySet(ThrustVecAccum["ThrustVector"]);

            throttleOutput.Clear();
            thrustVectorOutput.Clear();
            throttleOutput.SetRangeWithPoints(0, 120);
            thrustVectorOutput.SetRangeWithPoints(-5, 5);

            //if height is high and speed is med, throttle soft		:R1
            //YourRuleSet["Rule0"] = Rule.AND(height, "Your Height Set[high]", speedY, "Your Y Speed Set[medium]", ref throttleOutput, "Your Throttle Set[soft]", YourRuleSet["Rule0"]);

            #region Throttle Rules

            if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard) ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.VeryHard))
            {

                #region Y Velocity Height Rules

                // if Y vel is up then throttle is no
                RuleSetThrottle["Rule0"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule0"]);

                // if height is high and Y vel is high then throttle is medium
                RuleSetThrottle["Rule1"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule1"]);

                // if height is high and Y vel is moderate then throttle is medium
                RuleSetThrottle["Rule2"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule2"]);

                // if height is high and Y vel is low then throttle is low
                RuleSetThrottle["Rule3"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule3"]);

                // if height is high and Y vel is safe then throttle is low
                RuleSetThrottle["Rule4"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule4"]);

                // if height is medium and Y vel is high then throttle is high
                RuleSetThrottle["Rule5"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule5"]);

                // if height is medium and Y vel is moderate then throttle is high
                RuleSetThrottle["Rule6"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule6"]);

                // if height is medium and Y vel is low then throttle is medium
                RuleSetThrottle["Rule7"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule7"]);

                // if height is medium and Y vel is safe then throttle is low
                RuleSetThrottle["Rule8"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule8"]);

                // if height is low and Y vel is high then throttle is high
                RuleSetThrottle["Rule9"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule9"]);

                // if height is low and Y vel is moderate then throttle is medium
                RuleSetThrottle["Rule10"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule10"]);

                // if height is low and Y vel is low then throttle is medium
                RuleSetThrottle["Rule11"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule11"]);

                // if height is low and Y vel is safe then throttle is low
                RuleSetThrottle["Rule12"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule12"]);

                // if height is landing and Y vel is high then throttle is high
                RuleSetThrottle["Rule13"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule13"]);

                // if height is landing and Y vel is moderate then throttle is high
                RuleSetThrottle["Rule14"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule14"]);

                // if height is landing and Y vel is low then throttle  is medium
                RuleSetThrottle["Rule15"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule15"]);

                // if height is landing and Y vel is safe then throttle is low
                RuleSetThrottle["Rule16"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule16"]);

                RuleSetThrottle["Rule17"] = Rule.IS(height + 23, HeightSets["Below Deck Height"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule17"]);

                RuleSetThrottle["Rule18"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule18"]);

                RuleSetThrottle["Rule19"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule19"]);

                RuleSetThrottle["Rule20"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule20"]);

                #endregion

            }

            if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy) ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium))
            {

                #region Y Velocity Height Rules

                // if Y vel is up then throttle is no
                RuleSetThrottle["Rule0"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule0"]);

                // if height is high and Y vel is high then throttle is medium
                RuleSetThrottle["Rule1"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule1"]);

                // if height is high and Y vel is moderate then throttle is medium
                RuleSetThrottle["Rule2"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule2"]);

                // if height is high and Y vel is low then throttle is low
                RuleSetThrottle["Rule3"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule3"]);

                // if height is high and Y vel is safe then throttle is low
                RuleSetThrottle["Rule4"] = Rule.AND(height, HeightSets["High Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule4"]);

                // if height is medium and Y vel is high then throttle is high
                RuleSetThrottle["Rule5"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule5"]);

                // if height is medium and Y vel is moderate then throttle is high
                RuleSetThrottle["Rule6"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule6"]);

                // if height is medium and Y vel is low then throttle is medium
                RuleSetThrottle["Rule7"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule7"]);

                // if height is medium and Y vel is safe then throttle is low
                RuleSetThrottle["Rule8"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule8"]);

                // if height is low and Y vel is high then throttle is high
                RuleSetThrottle["Rule9"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule9"]);

                // if height is low and Y vel is moderate then throttle is medium
                RuleSetThrottle["Rule10"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule10"]);

                // if height is low and Y vel is low then throttle is medium
                RuleSetThrottle["Rule11"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule11"]);

                // if height is low and Y vel is safe then throttle is low
                RuleSetThrottle["Rule12"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule12"]);

                // if height is landing and Y vel is high then throttle is high
                RuleSetThrottle["Rule13"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["High Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule13"]);

                // if height is landing and Y vel is moderate then throttle is high
                RuleSetThrottle["Rule14"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Moderate Velocity"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule14"]);

                // if height is landing and Y vel is low then throttle  is medium
                RuleSetThrottle["Rule15"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Low Velocity"], ref throttleOutput, ThrottleSets["Medium Throttle"], RuleSetThrottle["Rule15"]);

                // if height is landing and Y vel is safe then throttle is low
                RuleSetThrottle["Rule16"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Safe Velocity"], ref throttleOutput, ThrottleSets["Low Throttle"], RuleSetThrottle["Rule16"]);

                RuleSetThrottle["Rule17"] = Rule.IS(height + 23, HeightSets["Below Deck Height"], ref throttleOutput, ThrottleSets["High Throttle"], RuleSetThrottle["Rule17"]);

                RuleSetThrottle["Rule18"] = Rule.AND(height, HeightSets["Medium Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule18"]);

                RuleSetThrottle["Rule19"] = Rule.AND(height, HeightSets["Low Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule19"]);

                RuleSetThrottle["Rule20"] = Rule.AND(height, HeightSets["Landing Height"], speedY, YVelocitySets["Up Velocity"], ref throttleOutput, ThrottleSets["No Throttle"], RuleSetThrottle["Rule20"]);

                #endregion

            }

            #endregion

            #region Thrust Vector Rules

            if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Hard) ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.VeryHard))
            {

                #region  X Velocity Left Dangerzone Rules

                #region Rule 0: if distance is left high dangerzone then thrust vector is forward high thrust

                RuleSetThrustVec["Rule0"] = Rule.IS(safeX, DistanceSets["Left High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]);

                // if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule0"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]);

                // if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule1"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]);

                // if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule2"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]);

                // if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule3"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]);

                #endregion

                // if distance is left moderate dangerzone and X vel is high left then thrust vector is forward high thrust
                RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]);

                // if distance is left moderate dangerzone and X vel is moderate left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule2"]);

                // if distance is left moderate dangerzone and X vel is low left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule3"]);

                // if distance is left moderate dangerzone and X vel is neutral then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule4"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule4"]);

                // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule5"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule5"]);

                // if distance is left low dangerzone and X vel is moderate left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule6"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule6"]);

                // if distance is left low dangerzone and X vel is low left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule7"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule7"]);

                // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule8"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule8"]);

                #endregion

                #region X Velocity Safezone Rules

                // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]);

                // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule10"]);

                // if distance is safe zone and X vel is low left then thrust vector is forward low thrust
                RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule11"]);

                // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust
                RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]);

                // if distance is safe zone and X vel is low right then thrust vector is backward low thrust
                RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule13"]);

                // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule14"]);

                // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]);

                // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]);

                #endregion

                #region X Velocity Right Dangerzone Rules

                #region Rule 16: if distance is right high dangerzone then thrust vector is backward high thrust

                RuleSetThrustVec["Rule16"] = Rule.IS(safeX, DistanceSets["Right High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule16"]);

                /*
                // if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust
                RuleSetThrustVec["Rule0"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]);

                // if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust
                RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]);

                // if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust
                RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]);

                // if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust
                RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule3"]);
                */

                #endregion

                // if distance is right moderate dangerzone and X vel is high right then thrust vector is backward high thrust
                RuleSetThrustVec["Rule17"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule17"]);

                // if distance is right moderate dangerzone and X vel is moderate right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule18"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule18"]);

                // if distance is right moderate dangerzone and X vel is low right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule19"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule19"]);

                // if distance is right moderate dangerzone and X vel is neutral then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule20"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule20"]);

                // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule21"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule21"]);

                // if distance is right low dangerzone and X vel is moderate right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule22"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule22"]);

                // if distance is right low dangerzone and X vel is low right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule23"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule23"]);

                // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule24"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule24"]);

                #endregion

            }

            if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy) ||
                    Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium))
            {

                #region  X Velocity Left Dangerzone Rules

                #region Rule 0: if distance is left high dangerzone then thrust vector is forward high thrust

                RuleSetThrustVec["Rule0"] = Rule.IS(safeX, DistanceSets["Left High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule0"]);

                //// if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule0"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule0"]);

                //// if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule29"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule29"]);

                //// if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule30"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule30"]);

                //// if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule31"] = Rule.OR(safeX, DistanceSets["Left High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule31"]);

                #endregion

                // if distance is left moderate dangerzone and X vel is high left then thrust vector is forward high thrust
                RuleSetThrustVec["Rule1"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule1"]);

                // if distance is left moderate dangerzone and X vel is moderate left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule2"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule2"]);

                // if distance is left moderate dangerzone and X vel is low left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule3"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule3"]);

                // if distance is left moderate dangerzone and X vel is neutral then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule4"] = Rule.AND(safeX, DistanceSets["Left Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule4"]);

                // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule5"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule5"]);

                // if distance is left low dangerzone and X vel is moderate left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule6"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule6"]);

                // if distance is left low dangerzone and X vel is low left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule7"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule7"]);

                // if distance is left low dangerzone and X vel is high left then thrust vector is forward moderate thrust
                RuleSetThrustVec["Rule8"] = Rule.AND(safeX, DistanceSets["Left Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule8"]);

                #endregion

                #region X Velocity Safezone Rules

                if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Easy))
                {

                    // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust
                    RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]);

                    // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust
                    RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule10"]);

                    // if distance is safe zone and X vel is low left then thrust vector is forward low thrust
                    RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule11"]);

                    // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust
                    RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]);

                    // if distance is safe zone and X vel is low right then thrust vector is backward low thrust
                    RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule13"]);

                    // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                    RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule14"]);

                    // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust
                    RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]);

                    // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                    //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]);
                }

                if (Globals.Simulator.Difficulty.Equals(SimDifficultyEnum.Medium))
                {

                    // if distance is safe zone and X vel is high left then thrust vector is forward moderate thrust
                    RuleSetThrustVec["Rule9"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward High Thrust"], RuleSetThrustVec["Rule9"]);

                    // if distance is safe zone and X vel is moderate left then thrust vector is forward moderate thrust
                    RuleSetThrustVec["Rule10"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Moderate Thrust"], RuleSetThrustVec["Rule10"]);

                    // if distance is safe zone and X vel is low left then thrust vector is forward low thrust
                    RuleSetThrustVec["Rule11"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Forward Low Thrust"], RuleSetThrustVec["Rule11"]);

                    // if distance is safe zone and X vel is neutral then thrust vector is neutral thrust
                    RuleSetThrustVec["Rule12"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Neutral Thrust"], RuleSetThrustVec["Rule12"]);

                    // if distance is safe zone and X vel is low right then thrust vector is backward low thrust
                    RuleSetThrustVec["Rule13"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule13"]);

                    // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                    RuleSetThrustVec["Rule14"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule14"]);

                    // if distance is safe zone and X vel is high right then thrust vector is backward moderate thrust
                    RuleSetThrustVec["Rule15"] = Rule.AND(safeX, DistanceSets["Safe Zone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule15"]);

                    // if distance is safe zone and X vel is moderate right then thrust vector is backward moderate thrust
                    //RuleSetThrustVec[""] = Rule.AND(safeX, DistanceSets[""], speedX, XVelocitySets[""], ref thrustVectorOutput, ThrustVecSets[""], RuleSetThrustVec[""]);
                }

                #endregion

                #region X Velocity Right Dangerzone Rules

                #region Rule 16: if distance is right high dangerzone then thrust vector is backward high thrust

                RuleSetThrustVec["Rule16"] = Rule.IS(safeX, DistanceSets["Right High Dangerzone"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule16"]);

                //// if distance is left high dangerzone and X vel is high left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule25"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["High Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule25"]);

                //// if distance is left high dangerzone and X vel is moderate left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule26"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Moderate Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule26"]);

                //// if distance is left high dangerzone and X vel is Low left then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule27"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Low Left Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule27"]);

                //// if distance is left high dangerzone and X vel is Neutral then thrust vector is forward high thrust
                //RuleSetThrustVec["Rule28"] = Rule.AND(safeX, DistanceSets["Right High Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule28"]);

                #endregion

                // if distance is right moderate dangerzone and X vel is high right then thrust vector is backward high thrust
                RuleSetThrustVec["Rule17"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward High Thrust"], RuleSetThrustVec["Rule17"]);

                // if distance is right moderate dangerzone and X vel is moderate right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule18"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule18"]);

                // if distance is right moderate dangerzone and X vel is low right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule19"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule19"]);

                // if distance is right moderate dangerzone and X vel is neutral then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule20"] = Rule.AND(safeX, DistanceSets["Right Moderate Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule20"]);

                // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule21"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["High Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule21"]);

                // if distance is right low dangerzone and X vel is moderate right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule22"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Moderate Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Moderate Thrust"], RuleSetThrustVec["Rule22"]);

                // if distance is right low dangerzone and X vel is low right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule23"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Low Right Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule23"]);

                // if distance is right low dangerzone and X vel is high right then thrust vector is backward moderate thrust
                RuleSetThrustVec["Rule24"] = Rule.AND(safeX, DistanceSets["Right Low Dangerzone"], speedX, XVelocitySets["Neutral Velocity"], ref thrustVectorOutput, ThrustVecSets["Backward Low Thrust"], RuleSetThrustVec["Rule24"]);

                #endregion

            }

            #endregion

            ThrottleAccum["ThrottleOutput"] = new FuzzySet(throttleOutput);
            ThrustVecAccum["ThrustVector"] = new FuzzySet(thrustVectorOutput);

            //Switch for how to adjust throttle settings ('AutoPilot' Checkbox on form)
            if (!Manual)
            {
                harrier.Throttle = _throttle;
                harrier.ThrustVector = _tv;
            }
            else
            {
               harrier.Throttle = Operations.DeFuzzifyCOG(ThrottleAccum["ThrottleOutput"]);
               harrier.ThrustVector = Operations.DeFuzzifyCOG(ThrustVecAccum["ThrustVector"]);
            }

            //THESE ARE UP TO YOU TO TUNE!!
            harrier.Throttle += 20;
            harrier.ThrustVector += 90;

            //END
            ((HarrierSim) Globals.Simulator).Harrier = harrier;
        }
        private void SetupExampleSet2()
        {
            //Add a new Fuzzy Set to the Collection
            ExampleSets.Add("Example 2", new FuzzySet());

            //Initialize the new Fuzzy Set
            ExampleSets["Example 2"] = new FuzzySet("Example 2", 0, 100);
            ExampleSets["Example 2"].LineColour = new SolidBrush(Color.Blue);

            //Now, define the points in the Set
            ExampleSets["Example 2"].AddPoint(0, 0);
            ExampleSets["Example 2"].AddPoint(10, 1);
            ExampleSets["Example 2"].AddPoint(40, 0.2);
            ExampleSets["Example 2"].AddPoint(50, 0.1);
            ExampleSets["Example 2"].AddPoint(70, 0.1);
            ExampleSets["Example 2"].AddPoint(90, 0.5);
            ExampleSets["Example 2"].AddPoint(100, 0);
        }
示例#15
0
 // static
 /// <summary>
 /// Checks if the Low and High range of two sets are equal
 /// </summary>
 /// <param name="fs1"></param>
 /// <param name="fs2"></param>
 /// <returns></returns>
 public static bool RangeEqual(FuzzySet fs1, FuzzySet fs2)
 {
     if (fs1 == null || fs2 == null) { return false; }
     if (!Operations.AEqual(fs1.GetHighRange(), fs2.GetHighRange())) return false;
     if (!Operations.AEqual(fs1.GetLowRange(), fs2.GetLowRange())) return false;
     return true;
 }
示例#16
0
 /**
 * Defuzzify a set using the Sugeno style aproximation function
 * if it fails it returns -1 (which may be a valid answer)
 */
 /// <summary>
 ///  Defuzzify a set using the Sugeno style aproximation function
 // if it fails it returns -1 (which may be a valid answer)
 /// </summary>
 /// <param name="fs"></param>
 /// <returns></returns>
 public static double DeFuzzifySFI(FuzzySet fs)
 {
     if (fs == null) { return -1; }
     if (fs.Invalid()) { fs.Err = 10; return -1; }
     double sumTop = 0;
     double sumBottom = 0;
     double w, s;
     int i;
     for (i = 0; i < fs.GetNumPoints(); i++)
     {
         w = fs.WorldValue[i];
         s = fs.SetValue[i];
         sumTop = sumTop + s * w;
         sumBottom = sumBottom + s;
     }
     if (Operations.AEqual(0, sumBottom)) { fs.Err = 15; return -1; }
     return sumTop / sumBottom;
 }
示例#17
0
        /// <summary>
        /// Performs a SCALE on a Fuzzy Set
        /// </summary>
        /// <param name="fs">The Fuzzy Set to Scale</param>
        /// <param name="val">The scalar amount to Scale the Set</param>
        /// <returns></returns>
        public static FuzzySet ScaleFS(FuzzySet fs, double val)
        {
            FuzzySet retSet = new FuzzySet();

            if (fs == null)
            {
                retSet.SetErr(10);
                return retSet;
            }

            retSet = new FuzzySet(fs);

            if (retSet.Invalid())
            {
                retSet.SetErr(10);
                return retSet;
            }

            int i;
            for (i = 0; i < retSet.GetNumPoints(); i++)
            {
                double w = retSet.GetWorldValue(i);
                double s = retSet.GetSetValue(i) * val;
                if (s > 1) s = 1;
                if (s < 0) s = 0;
                retSet.AdjustPoint(i, w, s);
            }

            return retSet;
        }
示例#18
0
        /// <summary>
        /// Performs a UNION of two Fuzzy Sets
        /// </summary>
        /// <param name="fs1">Fuzzy Set 1</param>
        /// <param name="fs2">Fuzzy Set 2</param>
        /// <param name="colour">The colour to render the result</param>
        /// <returns>Result Set</returns>
        public static FuzzySet UnionFS(FuzzySet fs1, FuzzySet fs2, Brush colour)
        {
            FuzzySet result = new FuzzySet(); // just for error checking and returning

            //verify...
            if (fs1 == null || fs2 == null || fs1.Invalid() || fs2.Invalid())
            {
                result.SetErr(10);
                return result;
            }

            if (!RangeEqual(fs1, fs2))
            {
                result.SetErr(11); return result;
            }

            result = new FuzzySet(fs1);

            result.Clear();

            //lets get to work
            result.SetRange(fs1.GetLowRange(), fs1.GetHighRange());

            double x = 0, y = 0;
            double fs1x1, fs1x2, fs1y1, fs1y2;
            double fs2x3, fs2x4, fs2y3, fs2y4;
            double fs1s, fs1w, fs2s, fs2w;
            int i, k, rc;

            // traverse fs1 add all its points above fs2
            for (i = 0; i < fs1.GetNumPoints(); i++)
            {
                fs1w = fs1.GetWorldValue(i);
                fs1s = fs1.GetSetValue(i);
                fs2s = fs2.Fuzzify(fs1w);
                if (fs1s > fs2s || Operations.AEqual(fs1s, fs2s))
                {
                    result.AddPoint(fs1w, fs1s, false, false);
                }
            }

            // traverse fs2 add all its points above fs1
            for (i = 0; i < fs2.GetNumPoints(); i++)
            {
                fs2w = fs2.GetWorldValue(i);
                fs2s = fs2.GetSetValue(i);
                fs1s = fs1.Fuzzify(fs2w);
                if (fs2s > fs1s)
                {
                    result.AddPoint(fs2w, fs2s, false, false);
                }
            }

            // now traverse all line segments in fs1 testing for intersection with fs2
            for (i = 1; i < fs1.GetNumPoints(); i++)
            {
                fs1x1 = fs1.GetWorldValue(i - 1);
                fs1y1 = fs1.GetSetValue(i - 1);
                fs1x2 = fs1.GetWorldValue(i);
                fs1y2 = fs1.GetSetValue(i);
                for (k = 1; k < fs2.GetNumPoints(); k++)
                {
                    fs2x3 = fs2.GetWorldValue(k - 1);
                    fs2y3 = fs2.GetSetValue(k - 1);
                    fs2x4 = fs2.GetWorldValue(k);
                    fs2y4 = fs2.GetSetValue(k);

                    rc = Intersect(ref x, ref y,
                       fs1x1, fs1y1, fs1x2, fs1y2,
                       fs2x3, fs2y3, fs2x4, fs2y4);

                    if (rc == 0)
                    {
                        result.AddPoint(x, y, false, false);
                    }
                }
            }
            result.ColapseSet();

            result.LineColour = colour;

            return result;
        }