Ejemplo n.º 1
0
        public static MembershipFunction CreateConstant(float refPoint)
        {
            MembershipFunction result = new MembershipFunction();

            result.Type = MFtype.constant;

            result.Params[0] = refPoint;

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a triangle MF generated using the given parameters
        /// </summary>
        /// <param name="referencePoint">The tip of the triangle</param>
        /// <returns></returns>
        public static MembershipFunction CreateTriangle(float referencePoint, float bottomSize)
        {
            // Initialize
            MembershipFunction result = new MembershipFunction();

            // Set data
            result.Type = MFtype.trimf;

            // Set coordinates
            result.Params[0] = referencePoint + bottomSize * 0.5f;
            result.Params[1] = referencePoint;
            result.Params[2] = referencePoint + bottomSize * 0.5f;

            // Set values
            result.Values[0] = 0.0f;
            result.Values[1] = 1.0f;
            result.Values[2] = 0.0f;

            // Return result
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Automatically generate equal sized trapezoid MF-s for each MF.
        /// </summary>
        /// <param name="baseRatio">bigger(bottom) base * baseRatio = smaller(top) base</param>
        /// <param name="input">bigger(bottom) base * baseRatio = smaller(top) base</param>
        /// <param name="output">bigger(bottom) base * baseRatio = smaller(top) base</param>
        public void GenerateTrapezoidMFs(float baseRatio = 1.0f / 3.0f, bool input = true, bool output = true)
        {
            // Create input MFs
            if (input)
            {
                for (int i = 0; i < NumInputs; i++)
                {
                    // calculate the steps at which we make steps between the specified trapeze points:
                    // (total range) / (2 * NumMF - 1)
                    float stepSize = (Inputs[i].Range[1] - Inputs[i].Range[0]) / (2.0f * Inputs[i].NumMFs - 1.0f);

                    // create the trapeze shapes
                    for (int j = 0; j < Inputs[i].NumMFs; j++)
                    {
                        Inputs[i].MFs[j] = MembershipFunction.CreateTrapezoid(Inputs[i].Range[0] + stepSize * (j * 2 - 1 + 1.5f), stepSize * 3.0f, stepSize * 3.0f * baseRatio);
                    }
                }
            }

            if (output)
            {
                // Create output MFs
                for (int i = 0; i < NumOutputs; i++)
                {
                    // calculate the steps at which we make steps between the specified trapeze points:
                    // (total range) / (2 * NumMF - 1)
                    float stepSize = (Outputs[i].Range[1] - Outputs[i].Range[0]) / (2.0f * Outputs[i].NumMFs - 1.0f);

                    // create the trapeze shapes
                    for (int j = 0; j < Outputs[i].NumMFs; j++)
                    {
                        Outputs[i].MFs[j] = MembershipFunction.CreateTrapezoid(Outputs[i].Range[0] + stepSize * (j * 2 - 1 + 1.5f), stepSize * 3.0f, stepSize * 3.0f * baseRatio);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            //input memebership function creation
            Region             very_cold = create_region("very cold", 0.0, 0.0, 60.0, 1.0, 65.0, 0.0, true, false);
            Region             cold      = create_region("cold", 60.0, 0.0, 65.0, 1.0, 70.0, 0.0, false, false);
            Region             warm      = create_region("warm", 65.0, 0.0, 70.0, 1.0, 75.0, 0.0, false, false);
            Region             hot       = create_region("hot", 70.0, 0.0, 75.0, 1.0, 80.0, 0.0, false, false);
            Region             very_hot  = create_region("very hot", 75.0, 0.0, 80.0, 1.0, 0.0, 0.0, false, true);
            MembershipFunction temp      = new MembershipFunction(very_cold, cold, warm, hot, very_hot);

            // output memebership function creation
            string[]           regions   = { "hi cool", "cool", "no change", "heat", "hi heat" };
            Region             hicool    = create_region("hi cool", 0.0, 0.0, -100.0, 1.0, -50.0, 0.0, true, false);
            Region             cool      = create_region("cool", -50.25, 0.0, -50.0, 1.0, -1.0, 0.0, false, false);
            Region             no_change = create_region("no change", -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, false, false);
            Region             heat      = create_region("heat", 1.0, 0.0, 50.0, 1.0, 50.25, 0.0, false, false);
            Region             hiheat    = create_region("hi heat", 50.0, 0.0, 100.0, 1.0, 0.0, 0.0, false, true);
            MembershipFunction heat_cool = new MembershipFunction(hicool, cool, no_change, heat, hiheat);


            // get user input

            bool cont = true;

            while (cont)
            {
                double current_temp = 0;
                double target_temp  = 0;
                bool   current_flag = false;
                bool   target_flag  = false;


                while (!current_flag)
                {
                    Console.WriteLine("Please Enter a current temperature (ex. 75.0)");
                    current_flag = Double.TryParse(Console.ReadLine(), out current_temp);
                }

                while (!target_flag)
                {
                    Console.WriteLine("Please Enter a target temperature (ex. 75.0)");
                    target_flag = Double.TryParse(Console.ReadLine(), out target_temp);
                }

                FuzzySet current_fuzz = new FuzzySet();
                FuzzySet target_fuzz  = new FuzzySet();
                current_fuzz = temp.EvalMembership(current_temp, "y");
                target_fuzz  = temp.EvalMembership(target_temp, "y");
                FuzzySet output = new FuzzySet();
                output = output.BaseRules(target_fuzz, current_fuzz);
                string result = heat_cool.defuzzify(output);
                Console.WriteLine(result);
                Console.WriteLine("would you like to run another execution y/n");
                char cont_char = Convert.ToChar(Console.ReadLine());
                if (cont_char == 'y')
                {
                    cont = true;
                }
                else
                {
                    cont = false;
                }
            }
        }