Exemplo n.º 1
0
        public void TestOptimizationProblemContext()
        {
            var in1                = new ContinuousDimension("in_1", 0, 10);
            var in2                = new DiscreteDimension("in_2", 1, 20);
            var inputHypergrid     = new Hypergrid("input", in1, in2);
            var out1               = new ContinuousDimension("out_1", -5, 7);
            var objectiveHypergrid = new Hypergrid("output", out1);
            var context1           = new DiscreteDimension("ctx_1", -100, -0);
            var contextHypergrid   = new Hypergrid("context", context1);
            var objectives         = new OptimizationObjective[]
            {
                new OptimizationObjective("out_1", true),
                new OptimizationObjective("nonExistent", false),
            };
            var optimizationProblem = new OptimizationProblem(inputHypergrid, contextHypergrid, objectiveHypergrid, objectives);
            var serialized          = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem);
            var deserialized        = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized);

            Assert.Equal(optimizationProblem.ParameterSpace.Name, deserialized.ParameterSpace.Name);
            Assert.Equal(optimizationProblem.ObjectiveSpace.Name, deserialized.ObjectiveSpace.Name);
            Assert.Equal(optimizationProblem.ContextSpace.Name, deserialized.ContextSpace.Name);

            Assert.Equal(optimizationProblem.Objectives[0].Name, objectives[0].Name);
            Assert.Equal(optimizationProblem.Objectives[0].Minimize, objectives[0].Minimize);
            Assert.Equal(optimizationProblem.Objectives[1].Name, objectives[1].Name);
            Assert.Equal(optimizationProblem.Objectives[1].Minimize, objectives[1].Minimize);

            // This is not a rigorous test but it should be sufficient given the other tests in this set.
            Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[0].Name, deserialized.ParameterSpace.Dimensions[0].Name);
            Assert.Equal(optimizationProblem.ParameterSpace.Dimensions[1].Name, deserialized.ParameterSpace.Dimensions[1].Name);
            Assert.Equal(optimizationProblem.ObjectiveSpace.Dimensions[0].Name, deserialized.ObjectiveSpace.Dimensions[0].Name);
            Assert.Equal(optimizationProblem.ContextSpace.Dimensions[0].Name, deserialized.ContextSpace.Dimensions[0].Name);
        }
Exemplo n.º 2
0
        public void TestHypergrid()
        {
            var dataDim1     = new object[] { "a", "b", false, 2, 5.8, "c " };
            var dim0         = new CategoricalDimension("dim0", false, "a", "b", false, 2, 5.8, "c ");
            var dim1         = new ContinuousDimension("dim1", 0, 10.2, false, true);
            var hypergrid    = new Hypergrid("hypergrid", dim0, dim1);
            var serialized   = OptimizerServiceEncoder.EncodeHypergrid(hypergrid);
            var deserialized = OptimizerServiceDecoder.DecodeHypergrid(serialized);

            Assert.Equal(deserialized.Name, hypergrid.Name);
            Assert.True(deserialized.Dimensions[0] is CategoricalDimension);
            Assert.True(deserialized.Dimensions[1] is ContinuousDimension);

            Assert.True(
                ((CategoricalDimension)deserialized.Dimensions[0]).Values.SequenceEqual(
                    ((CategoricalDimension)hypergrid.Dimensions[0]).Values));
            Assert.Equal(
                ((ContinuousDimension)deserialized.Dimensions[1]).Name,
                dim1.Name);
            Assert.Equal(
                ((ContinuousDimension)deserialized.Dimensions[1]).Min,
                dim1.Min);
            Assert.Equal(
                ((ContinuousDimension)deserialized.Dimensions[1]).Max,
                dim1.Max);
            Assert.Equal(
                ((ContinuousDimension)deserialized.Dimensions[1]).IncludeMin,
                dim1.IncludeMin);
            Assert.Equal(
                ((ContinuousDimension)deserialized.Dimensions[1]).IncludeMax,
                dim1.IncludeMax);
        }
Exemplo n.º 3
0
 private void UpdateSubcontrols()
 {
     if (_min < _max)
     {
         Dimension = new ContinuousDimension("", "", "", (decimal)_min, (decimal)_max);
         PositiveControl.Dimension = Dimension;
         NegativeControl.Dimension = Dimension;
     }
     PositiveControl.ShallUpdateChart = false;
     NegativeControl.ShallUpdateChart = false;
     PositiveControl.Max = _max;
     NegativeControl.Max = _max;
     PositiveControl.Min = _min;
     NegativeControl.Min = _min;
     PositiveControl.ShallUpdateChart = true;
     NegativeControl.ShallUpdateChart = true;
     PositiveControl.UpdateChart();
     NegativeControl.UpdateChart();
     if (TitleP != null)
     {
         PositiveControl.Title = TitleP;
     }
     if (TitleN != null)
     {
         NegativeControl.Title = TitleN;
     }
 }
 public static OptimizerService.ContinuousDimension EncodeContinuousDimension(ContinuousDimension dimension)
 {
     return(new OptimizerService.ContinuousDimension
     {
         Name = dimension.Name,
         Min = dimension.Min,
         Max = dimension.Max,
         IncludeMin = dimension.IncludeMin,
         IncludeMax = dimension.IncludeMax,
     });
 }
        private void Awake()
        {
            m_Car = GetComponent <CarController>();

            inputSpeed    = new ContinuousDimension("", "", "", -100, 180);
            backwardSpeed = new RightQuadraticSet(inputSpeed, "", -100, -10, 0);
            zeroSpeed     = new BellSet(inputSpeed, "", 0, 5, 10);
            lowSpeed      = new QuadraticSet(inputSpeed, "", 10, 40, 0, 50, 5, 45);
            //private FuzzySet medSpeed;
            highSpeed = new LeftQuadraticSet(inputSpeed, "", 40, 45, 50);


            inputSideBoundDistance = new ContinuousDimension("", "", "", -10, 10);
            dangerousRight         = new LeftQuadraticSet(inputSideBoundDistance, "", 0, 9, 10);
            dangerousLeft          = new RightQuadraticSet(inputSideBoundDistance, "", -10, -9, 0);
            safe = new TrapezoidalSet(inputSideBoundDistance, "", -5, 5, -7, 7);


            inputFrontBoundDistance = new ContinuousDimension("", "", "", 0, 150);
            far            = new LeftLinearSet(inputFrontBoundDistance, "", 20, 40);
            close          = new TrapezoidalSet(inputFrontBoundDistance, "", 15, 20, 10, 25);
            dangerousClose = new RightLinearSet(inputFrontBoundDistance, "", 10, 15);


            outputGas    = new ContinuousDimension("", "", "", -100, 100);
            pedalToMetal = new LeftQuadraticSet(outputGas, "", 0, 80, 100);
            clutch       = new SingletonSet(outputGas, "", 0);
            brake        = new RightLinearSet(outputGas, "", -100, 0);


            outputBrakes = new ContinuousDimension("", "", "", 0, 1);


            outputAction = new DiscreteDimension("", "");


            outputSteeringWheel = new ContinuousDimension("", "", "", -100, 100);
            turnLeft            = new RightLinearSet(outputSteeringWheel, "", -100, 0);
            turnRight           = new LeftLinearSet(outputSteeringWheel, "", 0, 100);
            forward             = new TriangularSet(outputSteeringWheel, "", 0, -10, 10);


            simpleSteeringRules =
                (dangerousLeft & turnRight) |
                (dangerousRight & turnLeft) |
                (safe & forward);

            simpleGasRules =
                (far & pedalToMetal) |
                ((close & lowSpeed) & clutch) |
                ((close & highSpeed) & brake) |
                ((close & zeroSpeed) & brake) |
                (dangerousClose & brake);
        }
Exemplo n.º 6
0
        public FuzzyControl()
        {
            _max      = 100;
            _min      = 0;
            IsLeft    = false;
            Dimension = new ContinuousDimension("Name", "Description", "Unit", (decimal)_min, (decimal)_max);
            InitializeComponent();

            UpdateChart();
            IsLinear = true;
            OnPropertyChanged("IsLinear");
        }
Exemplo n.º 7
0
    void Calc()
    {
        #region Definitions
        //Definition of dimensions on which we will measure the input values
        ContinuousDimension height = new ContinuousDimension("Height", "Personal height", "cm", 100, 250);
        ContinuousDimension weight = new ContinuousDimension("Weight", "Personal weight", "kg", 30, 200);

        //Definition of dimension for output value
        ContinuousDimension consequent = new ContinuousDimension("Suitability for basket ball", "0 = not good, 5 = very good", "grade", 0, 5);

        //Definition of basic fuzzy sets with which we will work
        //  input sets:
        FuzzySet tall    = new LeftLinearSet(height, "Tall person", 170, 185);
        FuzzySet weighty = new LeftLinearSet(weight, "Weighty person", 80, 100);
        //  output set:
        FuzzySet goodForBasket = new LeftLinearSet(consequent, "Good in basket ball", 0, 5);

        //Definition of antedescent
        FuzzyRelation lanky = tall & !weighty;

        //Implication
        FuzzyRelation term = (lanky & goodForBasket) | (!lanky & !goodForBasket);
        #endregion

        #region Input values
        //Console.Write("Enter your height in cm:");
        //decimal inputHeight = decimal.Parse(Console.ReadLine());
        decimal inputHeight = _inputHeight;

        //Console.Write("Enter your weight in kg:");
        //decimal inputWeight = decimal.Parse(Console.ReadLine());
        decimal inputWeight = _inputWeight;
        #endregion

        #region Deffuzification of the output set
        Defuzzification result = new MeanOfMaximum(
            term,
            new Dictionary <IDimension, decimal> {
            { height, inputHeight },
            { weight, inputWeight }
        }
            );

        //Console.WriteLine(String.Format("Your disposition to be a basketball player is {0:F3} out of <0,...,5>", result.CrispValue));
//        Debug.Log("Your disposition to be a basketball player is {0:F3} out of <0,...,5>" + result.CrispValue);
        ans       = (double)result.CrispValue;
        text.text = ans.ToString();

        //Console.WriteLine("Press any key to exit");
        //Console.ReadKey();
        #endregion
    }
Exemplo n.º 8
0
        public void TestContinuousDimension()
        {
            var dimension    = new ContinuousDimension("Test_Continuous \0", -150, 12.24, false, true);
            var serialized   = OptimizerServiceEncoder.EncodeContinuousDimension(dimension);
            var deserialized = OptimizerServiceDecoder.DecodeContinuousDimension(serialized);

            Assert.Equal(deserialized.Name, dimension.Name);
            Assert.Equal(deserialized.IncludeMax, dimension.IncludeMax);
            Assert.Equal(deserialized.IncludeMin, dimension.IncludeMin);
            Assert.Equal(deserialized.Max, dimension.Max);
            Assert.Equal(deserialized.Min, dimension.Min);
            Assert.True(deserialized.ObjectType == dimension.ObjectType);
        }
Exemplo n.º 9
0
    void Start()
    {
        _rigidbody = GetComponent <Rigidbody>();

        altitude = new ContinuousDimension("Altitude", "Altitude", "units", -100, 100);
        velocity = new ContinuousDimension("Velocity", "Velocity", "units/s", -50, 50);

        Adim = new ContinuousDimension("", "", "", 0, 10);
        Bdim = new ContinuousDimension("", "", "", 0, 10);
        Cdim = new ContinuousDimension("", "", "", 0, 10);

        A = new TriangularSet(Adim, "", 2, 0, 4);
        B = new TriangularSet(Bdim, "", 4, 3, 5);
        C = new TriangularSet(Cdim, "", 5, 0, 10);


        AlarsB = (A & B) / C;

        var projection = AlarsB.Project(new Dictionary <IDimension, decimal> {
            { Adim, 3 }, { Bdim, 4 }
        });

        for (decimal i = 0; i < 10; i += 1)
        {
            Debug.Log(i + "  " + projection.IsMember(i));
        }

        upSpeed   = new LeftLinearSet(velocity, "up speed", 5, 30);
        downSpeed = new RightLinearSet(velocity, "down speed", -30, -5);
        noSpeed   = new TriangularSet(velocity, "no speed", 0, -10, 10);
        high      = new LeftLinearSet(altitude, "high", 5, 20);
        low       = new RightLinearSet(altitude, "l", -20, -5);
        mid       = new TriangularSet(altitude, "l", 0, -10, 10);

        term = (high / downSpeed) %
               (low / upSpeed) %
               (mid / noSpeed);

/*
 *      lowUp = (low * upSpeed);
 *      highDown = (high * downSpeed);
 *      midno = mid * noSpeed;
 *
 *      for (decimal x = -30; x<= 30; x++) {
 *          for (decimal y = -30; y <= 30 ; y++) {
 *              Debug.Log("low(" + x + ") && upSpeed(" + y + ") = " + lowUp.IsMember(new Dictionary<IDimension, decimal> { {altitude, x}, {velocity, y} }));
 *          }
 *
 *      }
 */
    }
Exemplo n.º 10
0
 public MainWindow()
 {
     InitializeComponent();
     //Relation.Text = "((tall & !weighty) & goodForBasket) | (!(tall & !weighty) & !goodForBasket)";
     RainControl.Value        = 5;
     FogControl.Value         = 5;
     TemperatureControl.Value = 5;
     //DarknessControl.Value = 5;
     CondDimension             = new ContinuousDimension("", "", "", 0, 10);
     GoodCondControl.Dimension = CondDimension;
     BadCondControl.Dimension  = CondDimension;
     GoodCondControl.Max       = 10;
     GoodCondControl.Min       = 0;
     BadCondControl.Max        = 10;
     BadCondControl.Min        = 0;
 }
Exemplo n.º 11
0
        public TestSerializingAndDeserializing()
        {
            /* FIXME: This needs better cross-plat support and error handling.
             * - We should include C:\Python37 as another PYTHONHOME location to look for by default
             * - Currently this doesn't handle Linux very well
             * - On Ubuntu Python 3.7 needs to be installed from a separate
             *   repo, which installs as libpython3.7m.so which fails tobe
             *   found due to the trailing "m".
             */

            string pathToVirtualEnv = Environment.GetEnvironmentVariable("PYTHONHOME");

            if (string.IsNullOrEmpty(pathToVirtualEnv))
            {
                pathToVirtualEnv = @"c:\ProgramData\Anaconda3";
            }
            else
            {
                Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
            }

            string pathToPythonPkg = $"{pathToVirtualEnv}\\pkgs\\python-3.7.4-h5263a28_0";

            Environment.SetEnvironmentVariable("PATH", $"{pathToVirtualEnv};{pathToPythonPkg}", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib", EnvironmentVariableTarget.Process);

            continuous = new ContinuousDimension(name: "continuous", min: 1, max: 10);
            discrete   = new DiscreteDimension(name: "discrete", min: 1, max: 10);
            ordinal    = new OrdinalDimension(name: "ordinal", orderedValues: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }, ascending: true);
            categorical = new CategoricalDimension(name: "categorical", values: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            });
            allKindsOfDimensions = new Hypergrid(
                name: "all_kinds_of_dimensions",
                dimensions: new IDimension[]
            {
                continuous,
                discrete,
                ordinal,
                categorical,
            });
        }
Exemplo n.º 12
0
        public void TestOptimizationProblemNoContext()
        {
            var in1                = new ContinuousDimension("in_1", 0, 10);
            var in2                = new DiscreteDimension("in_2", 1, 20);
            var inputHypergrid     = new Hypergrid("input", in1, in2);
            var out1               = new ContinuousDimension("out_1", -5, 7);
            var objectiveHypergrid = new Hypergrid("output", out1);
            var objectives         = new OptimizationObjective[]
            {
                new OptimizationObjective("out_1", true),
                new OptimizationObjective("nonExistent", false),
            };
            var optimizationProblem = new OptimizationProblem(inputHypergrid, objectiveHypergrid, objectives);
            var serialized          = OptimizerServiceEncoder.EncodeOptimizationProblem(optimizationProblem);
            var deserialized        = OptimizerServiceDecoder.DecodeOptimizationProblem(serialized);

            Assert.Null(deserialized.ContextSpace);
        }
Exemplo n.º 13
0
        private void UpdateChart()
        {
            try
            {
                _dimension = new ContinuousDimension(FuzzyName, Description, Unit, (decimal)Min, (decimal)Max);

                _fuzzySet = new QuadraticSet(_dimension, FuzzyName, LeftTop, RightTop, LeftBot, RightBot, LeftMid, RightMid);
                //_fuzzySet = new RightQuadraticSet(_dimension, FuzzyName, Top, Mid,Bot);
                var           chart    = (PictureBox)Wfh.Child;
                RelationImage imgBuyIt = new RelationImage(_fuzzySet);
                Bitmap        bmpBuyIt = new Bitmap(chart.Width, chart.Height);
                imgBuyIt.DrawImage(Graphics.FromImage(bmpBuyIt));
                chart.Image = bmpBuyIt;
            }
            catch
            {
            }
        }
Exemplo n.º 14
0
        public TestSerializingAndDeserializing()
        {
            string pathToVirtualEnv = Environment.GetEnvironmentVariable("PYTHONHOME");

            if (string.IsNullOrEmpty(pathToVirtualEnv))
            {
                pathToVirtualEnv = @"c:\ProgramData\Anaconda3";
            }
            else
            {
                Environment.SetEnvironmentVariable("PYTHONHOME", pathToVirtualEnv, EnvironmentVariableTarget.Process);
            }

            string pathToPythonPkg = $"{pathToVirtualEnv}\\pkgs\\python-3.7.4-h5263a28_0";

            Environment.SetEnvironmentVariable("PATH", $"{pathToVirtualEnv};{pathToPythonPkg}", EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable("PYTHONPATH", $"{pathToVirtualEnv}\\Lib\\site-packages;{pathToVirtualEnv}\\Lib", EnvironmentVariableTarget.Process);

            continuous = new ContinuousDimension(name: "continuous", min: 1, max: 10);
            discrete   = new DiscreteDimension(name: "discrete", min: 1, max: 10);
            ordinal    = new OrdinalDimension(name: "ordinal", orderedValues: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            }, ascending: true);
            categorical = new CategoricalDimension(name: "categorical", values: new List <object>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            });
            allKindsOfDimensions = new SimpleHypergrid(
                name: "all_kinds_of_dimensions",
                dimensions: new List <IDimension>()
            {
                continuous,
                discrete,
                ordinal,
                categorical,
            });
        }
Exemplo n.º 15
0
        // public decimal Work(decimal rain, decimal visibility, decimal temperature, decimal hour)
        public Defuzzification Work(decimal rainValue, decimal temperatureValue, decimal fogValue /*, decimal darknessValue*/,
                                    DefuzzificationFactory.DefuzzificationMethod method)
        {
            FuzzySet zimno        = _temperatureParam.NegativeSet;
            FuzzySet cieplo       = _temperatureParam.PositiveSet;
            FuzzySet mokro        = _rainParam.PositiveSet;
            FuzzySet sucho        = _rainParam.NegativeSet;
            FuzzySet mgliscie     = _fogParam.NegativeSet;
            FuzzySet przejrzyscie = _fogParam.PositiveSet;
            // FuzzySet ciemno = _darknessParam.PositiveSet;
            //  FuzzySet jasno = _darknessParam.NegativeSet;

            //Definition of dimensions on which we will measure the input values
            //ContinuousDimension height = new ContinuousDimension("Height", "Personal height", "cm", 100, 250);
            //ContinuousDimension weight = new ContinuousDimension("Weight", "Personal weight", "kg", 30, 200);

            //Definition of dimension for output value
            ContinuousDimension consequent = new ContinuousDimension("", "0 = not good, 10 = very good", "grade", 0, 10);

            //Definition of basic fuzzy sets with which we will work
            //  input sets:
            //FuzzySet tall = new LeftQuadraticSet(height, "Tall person", 150, 180, 200);
            //FuzzySet weighty = new LeftLinearSet(weight, "Weighty person", 80, 100);
            //_tall = new LeftQuadraticSet(height, "Tall person", 150, 180, 200);
            //_weighty = new LeftLinearSet(weight, "Weighty person", 80, 100);

            //  output set:
            FuzzySet goodConditions = _resultParam.PositiveSet; //*/new LeftQuadraticSet(consequent, "Good conditions", 5, 7.5m, 10);
            FuzzySet badConditions  = _resultParam.NegativeSet; //*/new RightQuadraticSet(consequent, "Bad conditions", 5, 7.5m, 10);
            //FuzzySet badConditions = new RightLinearSet(consequent, "Good in basket ball", 0, 10);
            //FuzzySet mediumConditions = new TrapezoidalSet(consequent, "", 4,6,2,8);



            //Implication
            //FuzzyRelation term =/* ((tall & !weighty) & goodForBasket); |*/ (!(tall & !weighty) & !goodForBasket);
            //FuzzyRelation term = ((_rainParam.PositiveSet & !_temperatureParam.PositiveSet) & goodForBasket) | ((!_rainParam.PositiveSet & _temperatureParam.PositiveSet) & !goodForBasket);
            FuzzyRelation term =
                //((zimno) & badConditions) |
                ((sucho & cieplo) & goodConditions) |
                ((zimno & mokro) & badConditions) |
                ((sucho & przejrzyscie) & goodConditions) |
                ((cieplo & przejrzyscie) & goodConditions) |
                ((mgliscie & zimno) & badConditions) |
                ((mgliscie & mokro) & badConditions);
            //((mglisto & mokro) & badConditions) |
            //((mglisto & mokro) & badConditions) |
            //((mglisto & mokro) & badConditions) |
            //((mglisto & mokro) & badConditions);
            //((zimno & deszcz & mgla & noc) & badConditions) |
            //((zimno & deszcz & brakMgly & dzien) & badConditions) |
            //((zimno & deszcz & brakMgly & noc) & badConditions) |
            //((cieplo & brakDeszczu & mgla & dzien) & goodConditions) |
            //((cieplo & brakDeszczu & mgla & noc) & mediumConditions) |
            //((cieplo & brakDeszczu & brakMgly & dzien) & goodConditions) |
            //((cieplo & brakDeszczu & brakMgly & noc) & goodConditions) |
            //((cieplo & deszcz & mgla & dzien) & mediumConditions) |
            //((cieplo & deszcz & mgla & noc) & mediumConditions) |
            //((cieplo & deszcz & brakMgly & dzien) & goodConditions) |
            //((cieplo & deszcz & brakMgly & noc) & goodConditions);

            var result = DefuzzificationFactory.GetDefuzzification(term, new Dictionary <IDimension, decimal>
            {
                { _rainParam.Dimension, rainValue },
                { _temperatureParam.Dimension, temperatureValue },
                { _fogParam.Dimension, fogValue },
                // { _darknessParam.Dimension, darknessValue },
            }, method);

            //Defuzzification result = new MeanOfMaximum(
            //    term,
            //    new Dictionary<IDimension, decimal>{
            //        { _rainParam.Dimension, rainValue },
            //       { _temperatureParam.Dimension, temperatureValue },
            //        { _fogParam.Dimension, fogValue },
            //       // { _darknessParam.Dimension, darknessValue },
            //    }
            //);

            return(result);
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            #region Definitions
            //Definition of dimensions on which we will measure the input values
            ContinuousDimension height = new ContinuousDimension("Height", "Personal height", "cm", 100, 250);
            ContinuousDimension weight = new ContinuousDimension("Weight", "Personal weight", "kg", 30, 200);

            //Definition of dimension for output value
            ContinuousDimension consequent = new ContinuousDimension("Suitability for basket ball", "0 = not good, 5 = very good", "grade", 0, 5);

            //Definition of basic fuzzy sets with which we will work
            //  input sets:
            FuzzySet tall    = new LeftLinearSet(height, "Tall person", 170, 185);
            FuzzySet weighty = new LeftLinearSet(weight, "Weighty person", 80, 100);
            //  output set:
            FuzzySet goodForBasket = new LeftLinearSet(consequent, "Good in basket ball", 0, 5);

            //Definition of antedescent
            FuzzyRelation lanky = tall & !weighty;

            //Implication
            FuzzyRelation term = (lanky & goodForBasket) | (!lanky & !goodForBasket);
            #endregion

            #region Input values
            Console.Write("Enter your height in cm:");
            decimal inputHeight = decimal.Parse(Console.ReadLine());

            Console.Write("Enter your weight in kg:");
            decimal inputWeight = decimal.Parse(Console.ReadLine());
            #endregion


            #region Auxiliary messages; just for better understanding and not necessary for the final defuzzification
            double isLanky = lanky.IsMember(
                new Dictionary <IDimension, decimal> {
                { height, inputHeight },
                { weight, inputWeight }
            }
                );

            System.Console.WriteLine(String.Format("You are lanky to the {0:F3} degree out of range <0,1>.", isLanky));

            System.Console.WriteLine("Membership distribution in the output set for given inputs:");
            for (decimal i = 0; i <= 5; i++)
            {
                double membership = term.IsMember(
                    new Dictionary <IDimension, decimal> {
                    { height, inputHeight },
                    { weight, inputWeight },
                    { consequent, i }
                }
                    );

                System.Console.WriteLine(String.Format("µrelation(height={0:F0},weight={1:F0},consequent={2:F0}) = {3:F3}", inputHeight, inputWeight, i, membership));
            }
            System.Console.WriteLine();
            #endregion


            #region Deffuzification of the output set
            Defuzzification result = new MeanOfMaximum(
                term,
                new Dictionary <IDimension, decimal> {
                { height, inputHeight },
                { weight, inputWeight }
            }
                );

            Console.WriteLine(String.Format("Your disposition to be a basketball player is {0:F3} out of <0,...,5>", result.CrispValue));
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
            #endregion
        }
Exemplo n.º 17
0
    void Start()
    {
        if (fs == null)
        {
            fs = this;
        }
        #region Definitions
        //Definition of dimensions on which we will measure the input values
        volume = new ContinuousDimension("Volume", "Vehicle per hour", "veh/hr", 0, 1200);
        queue  = new ContinuousDimension("Weight", "Vehicle lenth on proper direction", "veh", 0, 30);


        //Definition of dimension for output value
        greenLight = new ContinuousDimension("Green Time", "green phase duration of Traffic Light", "s", 5, 60);

        //Definition of basic fuzzy sets with which we will work
        //  input sets:
        Volume_small      = new RightLinearSet(volume, "Small", 100, 300);
        Volume_middle     = new TrapezoidalSet(volume, "Middle", 300, 400, 100, 600);
        Volume_large      = new TrapezoidalSet(volume, "Large", 600, 700, 400, 900);
        Volume_extraLarge = new LeftLinearSet(volume, "Extra Large", 700, 900);

        Queue_small      = new RightLinearSet(queue, "Small", 0, 7);
        Queue_middle     = new TriangularSet(queue, "Middle", 10, 14);
        Queue_large      = new TriangularSet(queue, "Large", 17, 14);
        Queue_extraLarge = new LeftLinearSet(queue, "Extra Large", 17, 23);

        //  output set:
        Time_veryShort = new RightLinearSet(greenLight, "veryshort", 7, 15);
        Time_short     = new TrapezoidalSet(greenLight, "short", 15, 23, 7, 30);
        Time_middle    = new TrapezoidalSet(greenLight, "middle", 30, 38, 23, 45);
        Time_long      = new TrapezoidalSet(greenLight, "long", 45, 53, 38, 60);
        Time_veryLong  = new LeftLinearSet(greenLight, "verylong", 53, 60);

        //Definition of antedescent
        //relation =
        //    ((Volume_small & Queue_small) & Time_veryShort) |
        //    ((Volume_small & Queue_middle) & Time_short) |
        //    ((Volume_small & Queue_large) & Time_short) |
        //    ((Volume_small & Queue_extraLarge) & Time_middle) |
        //    ((Volume_middle & Queue_small) & Time_short) |
        //    ((Volume_middle & Queue_middle) & Time_middle) |
        //    ((Volume_middle & Queue_large) & Time_middle) |
        //    ((Volume_middle & Queue_extraLarge) & Time_long) |
        //    ((Volume_large & Queue_small) & Time_middle) |
        //    ((Volume_large & Queue_middle) & Time_long) |
        //    ((Volume_large & Queue_large) & Time_long) |
        //    ((Volume_large & Queue_extraLarge) & Time_veryLong) |
        //    ((Volume_extraLarge & Queue_small) & Time_middle) |
        //    ((Volume_extraLarge & Queue_middle) & Time_long) |
        //    ((Volume_extraLarge & Queue_large) & Time_veryLong) |
        //    ((Volume_extraLarge & Queue_extraLarge) & Time_veryLong);
        relation =
            ((Volume_small & Queue_small) & Time_veryShort) |
            ((Volume_small & Queue_middle) & Time_short) |
            ((Volume_small & Queue_large) & Time_short) |
            ((Volume_small & Queue_extraLarge) & Time_middle) |
            ((Volume_middle & Queue_small) & Time_veryShort) |
            ((Volume_middle & Queue_middle) & Time_short) |
            ((Volume_middle & Queue_large) & Time_middle) |
            ((Volume_middle & Queue_extraLarge) & Time_long) |
            ((Volume_large & Queue_small) & Time_short) |
            ((Volume_large & Queue_middle) & Time_middle) |
            ((Volume_large & Queue_large) & Time_long) |
            ((Volume_large & Queue_extraLarge) & Time_veryLong) |
            ((Volume_extraLarge & Queue_small) & Time_middle) |
            ((Volume_extraLarge & Queue_middle) & Time_long) |
            ((Volume_extraLarge & Queue_large) & Time_veryLong) |
            ((Volume_extraLarge & Queue_extraLarge) & Time_veryLong);
        #endregion


        //for (int iv = 0; iv < 110; iv++)
        //{
        //    for (int iq = 0; iq < 25; iq++)
        //    {

        //        Instantiate(haha, new Vector3((float)iv * 0.25f, Calc((float)(iv * 10), (float)(iq)) * 0.5f, (float)iq), Quaternion.identity);
        //        Debug.Log("=!=");
        //    }
        //}
        //Debug.Log("=)");
    }