Esempio n. 1
0
        MamdaniFuzzySystem CreateSystem()
        {
            //
            // Create empty fuzzy system
            //
            MamdaniFuzzySystem fsTips = new MamdaniFuzzySystem();

            //
            // Create input variables for the system
            //
            FuzzyVariable fvService = new FuzzyVariable("service", 0.0, 10.0);

            fvService.Terms.Add(new FuzzyTerm("poor", new TriangularMembershipFunction(-5.0, 0.0, 5.0)));
            fvService.Terms.Add(new FuzzyTerm("good", new TriangularMembershipFunction(0.0, 5.0, 10.0)));
            fvService.Terms.Add(new FuzzyTerm("excellent", new TriangularMembershipFunction(5.0, 10.0, 15.0)));
            fsTips.Input.Add(fvService);

            FuzzyVariable fvFood = new FuzzyVariable("food", 0.0, 10.0);

            fvFood.Terms.Add(new FuzzyTerm("rancid", new TrapezoidMembershipFunction(0.0, 0.0, 1.0, 3.0)));
            fvFood.Terms.Add(new FuzzyTerm("delicious", new TrapezoidMembershipFunction(7.0, 9.0, 10.0, 10.0)));
            fsTips.Input.Add(fvFood);

            //
            // Create output variables for the system
            //
            FuzzyVariable fvTips = new FuzzyVariable("tips", 0.0, 30.0);

            fvTips.Terms.Add(new FuzzyTerm("cheap", new TriangularMembershipFunction(0.0, 5.0, 10.0)));
            fvTips.Terms.Add(new FuzzyTerm("average", new TriangularMembershipFunction(10.0, 15.0, 20.0)));
            fvTips.Terms.Add(new FuzzyTerm("generous", new TriangularMembershipFunction(20.0, 25.0, 30.0)));
            fsTips.Output.Add(fvTips);

            //
            // Create three fuzzy rules
            //
            try
            {
                MamdaniFuzzyRule rule1 = fsTips.ParseRule("if (service is poor )  or (food is rancid) then tips is cheap");
                MamdaniFuzzyRule rule2 = fsTips.ParseRule("if ((service is good)) then tips is average");
                MamdaniFuzzyRule rule3 = fsTips.ParseRule("if (service is excellent) or (food is delicious) then (tips is generous)");

                fsTips.Rules.Add(rule1);
                fsTips.Rules.Add(rule2);
                fsTips.Rules.Add(rule3);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Parsing exception: {0}", ex.Message));
                return(null);
            }

            return(fsTips);
        }
Esempio n. 2
0
        public static Dictionary <NodeInstance, double> PrioritizeNodes(List <NodeInstance> nodes)
        {
            MamdaniFuzzySystem fsNodeSys = new MamdaniFuzzySystem();

            FuzzyVariable fvCPU = new FuzzyVariable("cpu", 0.0, 1);

            fvCPU.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(-.50, 0, .50)));
            fvCPU.Terms.Add(new FuzzyTerm("med", new TriangularMembershipFunction(0, .50, 1)));
            fvCPU.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(.50, 1, 1.5)));
            fsNodeSys.Input.Add(fvCPU);

            FuzzyVariable fvBandwidth = new FuzzyVariable("bandwidth", 0.0, 1);

            fvBandwidth.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(-.50, 0, .50)));
            fvBandwidth.Terms.Add(new FuzzyTerm("med", new TriangularMembershipFunction(0, .50, 1)));
            fvBandwidth.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(.50, 1, 1.5)));
            fsNodeSys.Input.Add(fvBandwidth);

            FuzzyVariable fvFreeSpace = new FuzzyVariable("freespace", 0.0, 1);

            fvFreeSpace.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(-.5, 0, .5)));
            fvFreeSpace.Terms.Add(new FuzzyTerm("moderate", new TriangularMembershipFunction(0, .5, 1)));
            fvFreeSpace.Terms.Add(new FuzzyTerm("ample", new TriangularMembershipFunction(.5, 1, 1.5)));
            fsNodeSys.Input.Add(fvFreeSpace);

            //
            // Create output variables for the system
            //
            FuzzyVariable fvRank = new FuzzyVariable("rank", 0, 1);

            fvRank.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(-0.25, 0, 0.25)));
            fvRank.Terms.Add(new FuzzyTerm("med_low", new TriangularMembershipFunction(0, 0.25, 0.50)));
            fvRank.Terms.Add(new FuzzyTerm("med", new TriangularMembershipFunction(0.25, 0.50, 0.75)));
            fvRank.Terms.Add(new FuzzyTerm("med_high", new TriangularMembershipFunction(0.50, 0.75, 1)));
            fvRank.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(0.75, 1, 1.25)));

            fsNodeSys.Output.Add(fvRank);

            MamdaniFuzzyRule rule1  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is high) and (freespace is ample) then rank is med");
            MamdaniFuzzyRule rule2  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is high) and (freespace is moderate) then rank is med_low");
            MamdaniFuzzyRule rule3  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is high) and (freespace is low) then rank is low");
            MamdaniFuzzyRule rule4  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is med) and (freespace is ample) then rank is med_high");
            MamdaniFuzzyRule rule5  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is med) and (freespace is moderate) then rank is med_high");
            MamdaniFuzzyRule rule6  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is med) and (freespace is low) then rank is med_low");
            MamdaniFuzzyRule rule7  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is low) and (freespace is ample) then rank is high");
            MamdaniFuzzyRule rule8  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is low) and (freespace is moderate) then rank is med_high");
            MamdaniFuzzyRule rule9  = fsNodeSys.ParseRule("if (cpu is low) and (bandwidth is low) and (freespace is low) then rank is med_low");
            MamdaniFuzzyRule rule10 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is high) and (freespace is ample) then rank is med");
            MamdaniFuzzyRule rule11 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is high) and (freespace is moderate) then rank is med_low");
            MamdaniFuzzyRule rule12 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is high) and (freespace is low) then rank is med_low");
            MamdaniFuzzyRule rule13 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is med) and (freespace is ample) then rank is med");
            MamdaniFuzzyRule rule14 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is med) and (freespace is moderate) then rank is med");
            MamdaniFuzzyRule rule15 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is med) and (freespace is low) then rank is low");
            MamdaniFuzzyRule rule16 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is low) and (freespace is ample) then rank is med_high");
            MamdaniFuzzyRule rule17 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is low) and (freespace is moderate) then rank is med_high");
            MamdaniFuzzyRule rule18 = fsNodeSys.ParseRule("if (cpu is med) and (bandwidth is low) and (freespace is low) then rank is low");
            MamdaniFuzzyRule rule19 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is high) and (freespace is ample) then rank is med");
            MamdaniFuzzyRule rule20 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is high) and (freespace is moderate) then rank is med_low");
            MamdaniFuzzyRule rule21 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is high) and (freespace is low) then rank is low");
            MamdaniFuzzyRule rule22 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is med) and (freespace is ample) then rank is med");
            MamdaniFuzzyRule rule23 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is med) and (freespace is moderate) then rank is med_low");
            MamdaniFuzzyRule rule24 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is med) and (freespace is low) then rank is low");
            MamdaniFuzzyRule rule25 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is low) and (freespace is ample) then rank is med_low");
            MamdaniFuzzyRule rule26 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is low) and (freespace is moderate) then rank is med");
            MamdaniFuzzyRule rule27 = fsNodeSys.ParseRule("if (cpu is high) and (bandwidth is low) and (freespace is low) then rank is low");

            fsNodeSys.Rules.Add(rule1);
            fsNodeSys.Rules.Add(rule2);
            fsNodeSys.Rules.Add(rule3);
            fsNodeSys.Rules.Add(rule4);
            fsNodeSys.Rules.Add(rule5);
            fsNodeSys.Rules.Add(rule6);
            fsNodeSys.Rules.Add(rule7);
            fsNodeSys.Rules.Add(rule8);
            fsNodeSys.Rules.Add(rule9);
            fsNodeSys.Rules.Add(rule10);
            fsNodeSys.Rules.Add(rule11);
            fsNodeSys.Rules.Add(rule12);
            fsNodeSys.Rules.Add(rule13);
            fsNodeSys.Rules.Add(rule14);
            fsNodeSys.Rules.Add(rule15);
            fsNodeSys.Rules.Add(rule16);
            fsNodeSys.Rules.Add(rule17);
            fsNodeSys.Rules.Add(rule18);
            fsNodeSys.Rules.Add(rule19);
            fsNodeSys.Rules.Add(rule20);
            fsNodeSys.Rules.Add(rule21);
            fsNodeSys.Rules.Add(rule22);
            fsNodeSys.Rules.Add(rule23);
            fsNodeSys.Rules.Add(rule24);
            fsNodeSys.Rules.Add(rule25);
            fsNodeSys.Rules.Add(rule26);
            fsNodeSys.Rules.Add(rule27);

            var rankedNodes = new Dictionary <NodeInstance, double>();

            for (int i = 0; i < nodes.Count; i++)
            {
                //
                // Fuzzify input values
                //
                Dictionary <FuzzyVariable, double> inputValues = new Dictionary <FuzzyVariable, double>();
                inputValues.Add(fvCPU, nodes[i].CPU_Utilization);
                inputValues.Add(fvBandwidth, nodes[i].UsedBandwidth / nodes[i].MaxBandwidth);
                inputValues.Add(fvFreeSpace, nodes[i].FreeSpace / nodes[i].MaxBackupSpace);

                //
                // Calculate the result
                //
                Dictionary <FuzzyVariable, double> result = fsNodeSys.Calculate(inputValues);

                double rank = result[fvRank];
                rankedNodes.Add(nodes[i], rank);

                //Console.WriteLine(nodes[i].ToString());
                //Console.WriteLine("Rank: " + Math.Round(rank, 2).ToString());
                //Console.WriteLine();
            }
            var sortedNodes
                = (from entry in rankedNodes orderby entry.Value descending select entry)
                  .ToDictionary(pair => pair.Key, pair => pair.Value);

            return(sortedNodes);
        }
Esempio n. 3
0
        private FuzzySystemResultDTO GenerateSystem(GetRuleDTO rules, double inputValue)
        {
            FuzzySystemResultDTO result = new FuzzySystemResultDTO();
            MamdaniFuzzySystem   fsSoil = new MamdaniFuzzySystem();

            foreach (var variable in rules.VariableList)
            {
                if (variable.DegiskenTipID == (byte)Enums.VariableType.Input)
                {
                    FuzzyVariable fvInput       = new FuzzyVariable(variable.DegiskenGorunenAdi, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.DegiskenID == variable.DegiskenID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        if (inputValue == variableItems[i].MinDeger)
                        {
                            inputValue++;
                        }
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].MaxDeger == variableItems[i + 1].MinDeger)
                            {
                                maxValue = variableItems[i].MaxDeger - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].MaxDeger;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].MaxDeger;
                        }

                        fvInput.Terms.Add(new FuzzyTerm(variableItems[i].DegiskenItemGorunenAdi, new TriangularMembershipFunction(variableItems[i].MinDeger, (variableItems[i].MinDeger + variableItems[i].MaxDeger) / 2, maxValue)));
                    }
                    fsSoil.Input.Add(fvInput);
                }
                else
                {
                    FuzzyVariable fvOutput      = new FuzzyVariable(variable.DegiskenGorunenAdi, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.DegiskenID == variable.DegiskenID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].MaxDeger == variableItems[i + 1].MinDeger)
                            {
                                maxValue = variableItems[i].MaxDeger - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].MaxDeger;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].MaxDeger;
                        }

                        fvOutput.Terms.Add(new FuzzyTerm(variableItems[i].DegiskenItemGorunenAdi, new TriangularMembershipFunction(variableItems[i].MinDeger, (variableItems[i].MinDeger + variableItems[i].MaxDeger) / 2, maxValue)));
                    }
                    fsSoil.Output.Add(fvOutput);
                }
            }

            foreach (var ruleText in rules.RuleListText)
            {
                MamdaniFuzzyRule rule = fsSoil.ParseRule(ruleText.KuralText);
                fsSoil.Rules.Add(rule);
            }

            result.System     = fsSoil;
            result.InputValue = inputValue;
            return(result);
        }
Esempio n. 4
0
        private FuzzySystemResultDTO CreateSystem(FetchRuleDTO rules, double inputValue)
        {
            FuzzySystemResultDTO result   = new FuzzySystemResultDTO();
            MamdaniFuzzySystem   fsGround = new MamdaniFuzzySystem();

            rules.VariableList     = session.variables;
            rules.RuleListText     = session.rules;
            rules.VariableItemList = session.variableItems;

            foreach (var variable in rules.VariableList)
            {
                if (variable.variableTypeID == (byte)Enums.VariableType.Input)
                {
                    FuzzyVariable fvInput       = new FuzzyVariable(variable.visibleVariableName, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.variableID == variable.variableID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        if (inputValue == variableItems[i].minValue)
                        {
                            inputValue++;
                        }
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].maxValue == variableItems[i + 1].minValue)
                            {
                                maxValue = variableItems[i].maxValue - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].maxValue;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].maxValue;
                        }

                        fvInput.Terms.Add(new FuzzyTerm(variableItems[i].variableItemVisibleName, new TriangularMembershipFunction(variableItems[i].minValue, (variableItems[i].minValue + variableItems[i].maxValue) / 2, maxValue)));
                    }
                    fsGround.Input.Add(fvInput);
                }
                else
                {
                    FuzzyVariable fvOutput      = new FuzzyVariable(variable.visibleVariableName, 0.0, 1000.0);
                    var           variableItems = rules.VariableItemList.Where(k => k.variableID == variable.variableID).ToList();
                    for (int i = 0; i < variableItems.Count; i++)
                    {
                        double maxValue;
                        if (i != variableItems.Count - 1)
                        {
                            if (variableItems[i].maxValue == variableItems[i + 1].minValue)
                            {
                                maxValue = variableItems[i].maxValue - 1;
                            }
                            else
                            {
                                maxValue = variableItems[i].maxValue;
                            }
                        }
                        else
                        {
                            maxValue = variableItems[i].maxValue;
                        }

                        fvOutput.Terms.Add(new FuzzyTerm(variableItems[i].variableItemVisibleName, new TriangularMembershipFunction(variableItems[i].minValue, (variableItems[i].minValue + variableItems[i].maxValue) / 2, maxValue)));
                    }
                    fsGround.Output.Add(fvOutput);
                }
            }

            foreach (var ruleText in rules.RuleListText)
            {
                MamdaniFuzzyRule rule = fsGround.ParseRule(ruleText.ruleText);
                fsGround.Rules.Add(rule);
            }

            result.System     = fsGround;
            result.InputValue = inputValue;
            return(result);
        }
Esempio n. 5
0
        MamdaniFuzzySystem CrearSistemaCostoCalidad()
        {
            MamdaniFuzzySystem fsCostoCalidad = new MamdaniFuzzySystem();

            FuzzyVariable fvCalidadProducto = new FuzzyVariable("calidad_producto", 0.0, 1.0);

            fvCalidadProducto.Terms.Add(new FuzzyTerm("muy_mala", new TrapezoidMembershipFunction(0.0, 0.0, 0.1, 0.3)));
            fvCalidadProducto.Terms.Add(new FuzzyTerm("mala", new TriangularMembershipFunction(0.1, 0.3, 0.5)));
            fvCalidadProducto.Terms.Add(new FuzzyTerm("regular", new TriangularMembershipFunction(0.3, 0.5, 0.7)));
            fvCalidadProducto.Terms.Add(new FuzzyTerm("buena", new TriangularMembershipFunction(0.5, 0.7, 0.9)));
            fvCalidadProducto.Terms.Add(new FuzzyTerm("excelente", new TrapezoidMembershipFunction(0.7, 0.9, 1.0, 1.0)));
            fsCostoCalidad.Input.Add(fvCalidadProducto);

            FuzzyVariable fvCostoTotal = new FuzzyVariable("costo_total", 0.0, 1.0);

            fvCostoTotal.Terms.Add(new FuzzyTerm("no_tiene", new TrapezoidMembershipFunction(0.0, 0.0, 0.1, 0.3)));
            fvCostoTotal.Terms.Add(new FuzzyTerm("bajo", new TriangularMembershipFunction(0.1, 0.3, 0.5)));
            fvCostoTotal.Terms.Add(new FuzzyTerm("regular", new TriangularMembershipFunction(0.3, 0.5, 0.7)));
            fvCostoTotal.Terms.Add(new FuzzyTerm("alto", new TriangularMembershipFunction(0.5, 0.7, 0.9)));
            fvCostoTotal.Terms.Add(new FuzzyTerm("muy_alto", new TrapezoidMembershipFunction(0.7, 0.9, 1.0, 1.0)));
            fsCostoCalidad.Input.Add(fvCostoTotal);



            FuzzyVariable fvPuntajeSoftware = new FuzzyVariable("puntaje_software", 0.0, 1.0);

            fvPuntajeSoftware.Terms.Add(new FuzzyTerm("muy_malo", new TrapezoidMembershipFunction(0.0, 0.0, 0.1, 0.3)));
            fvPuntajeSoftware.Terms.Add(new FuzzyTerm("malo", new TriangularMembershipFunction(0.1, 0.3, 0.5)));
            fvPuntajeSoftware.Terms.Add(new FuzzyTerm("regular", new TriangularMembershipFunction(0.3, 0.5, 0.7)));
            fvPuntajeSoftware.Terms.Add(new FuzzyTerm("bueno", new TriangularMembershipFunction(0.5, 0.7, 0.9)));
            fvPuntajeSoftware.Terms.Add(new FuzzyTerm("excelente", new TrapezoidMembershipFunction(0.7, 0.9, 1.0, 1.0)));
            fsCostoCalidad.Output.Add(fvPuntajeSoftware);

            try
            {
                MamdaniFuzzyRule r0  = fsCostoCalidad.ParseRule("if (calidad_producto is muy_mala) and (costo_total is no_tiene) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r1  = fsCostoCalidad.ParseRule("if (calidad_producto is mala) and (costo_total is no_tiene) then puntaje_software is malo");
                MamdaniFuzzyRule r2  = fsCostoCalidad.ParseRule("if (calidad_producto is regular) and (costo_total is no_tiene) then puntaje_software is regular");
                MamdaniFuzzyRule r3  = fsCostoCalidad.ParseRule("if (calidad_producto is buena) and (costo_total is no_tiene) then puntaje_software is bueno");
                MamdaniFuzzyRule r4  = fsCostoCalidad.ParseRule("if (calidad_producto is excelente) and (costo_total is no_tiene) then puntaje_software is excelente");
                MamdaniFuzzyRule r5  = fsCostoCalidad.ParseRule("if (calidad_producto is muy_mala) and (costo_total is bajo) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r6  = fsCostoCalidad.ParseRule("if (calidad_producto is mala) and (costo_total is bajo) then puntaje_software is malo");
                MamdaniFuzzyRule r7  = fsCostoCalidad.ParseRule("if (calidad_producto is regular) and (costo_total is bajo) then puntaje_software is regular");
                MamdaniFuzzyRule r8  = fsCostoCalidad.ParseRule("if (calidad_producto is buena) and (costo_total is bajo) then puntaje_software is bueno");
                MamdaniFuzzyRule r9  = fsCostoCalidad.ParseRule("if (calidad_producto is excelente) and (costo_total is bajo) then puntaje_software is excelente");
                MamdaniFuzzyRule r10 = fsCostoCalidad.ParseRule("if (calidad_producto is muy_mala) and (costo_total is regular) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r11 = fsCostoCalidad.ParseRule("if (calidad_producto is mala) and (costo_total is regular) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r12 = fsCostoCalidad.ParseRule("if (calidad_producto is regular) and (costo_total is regular) then puntaje_software is regular");
                MamdaniFuzzyRule r13 = fsCostoCalidad.ParseRule("if (calidad_producto is buena) and (costo_total is regular) then puntaje_software is regular");
                MamdaniFuzzyRule r14 = fsCostoCalidad.ParseRule("if (calidad_producto is excelente) and (costo_total is regular) then puntaje_software is bueno");
                MamdaniFuzzyRule r15 = fsCostoCalidad.ParseRule("if (calidad_producto is muy_mala) and (costo_total is alto) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r16 = fsCostoCalidad.ParseRule("if (calidad_producto is mala) and (costo_total is alto) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r17 = fsCostoCalidad.ParseRule("if (calidad_producto is regular) and (costo_total is alto) then puntaje_software is malo");
                MamdaniFuzzyRule r18 = fsCostoCalidad.ParseRule("if (calidad_producto is buena) and (costo_total is alto) then puntaje_software is regular");
                MamdaniFuzzyRule r19 = fsCostoCalidad.ParseRule("if (calidad_producto is excelente) and (costo_total is alto) then puntaje_software is regular");
                MamdaniFuzzyRule r20 = fsCostoCalidad.ParseRule("if (calidad_producto is muy_mala) and (costo_total is muy_alto) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r21 = fsCostoCalidad.ParseRule("if (calidad_producto is mala) and (costo_total is muy_alto) then puntaje_software is muy_malo");
                MamdaniFuzzyRule r22 = fsCostoCalidad.ParseRule("if (calidad_producto is regular) and (costo_total is muy_alto) then puntaje_software is malo");
                MamdaniFuzzyRule r23 = fsCostoCalidad.ParseRule("if (calidad_producto is buena) and (costo_total is muy_alto) then puntaje_software is malo");
                MamdaniFuzzyRule r24 = fsCostoCalidad.ParseRule("if (calidad_producto is excelente) and (costo_total is muy_alto) then puntaje_software is regular");



                fsCostoCalidad.Rules.Add(r0);
                fsCostoCalidad.Rules.Add(r1);
                fsCostoCalidad.Rules.Add(r2);
                fsCostoCalidad.Rules.Add(r3);
                fsCostoCalidad.Rules.Add(r4);
                fsCostoCalidad.Rules.Add(r5);
                fsCostoCalidad.Rules.Add(r6);
                fsCostoCalidad.Rules.Add(r7);
                fsCostoCalidad.Rules.Add(r8);
                fsCostoCalidad.Rules.Add(r9);
                fsCostoCalidad.Rules.Add(r10);
                fsCostoCalidad.Rules.Add(r11);
                fsCostoCalidad.Rules.Add(r12);
                fsCostoCalidad.Rules.Add(r13);
                fsCostoCalidad.Rules.Add(r14);
                fsCostoCalidad.Rules.Add(r15);
                fsCostoCalidad.Rules.Add(r16);
                fsCostoCalidad.Rules.Add(r17);
                fsCostoCalidad.Rules.Add(r18);
                fsCostoCalidad.Rules.Add(r19);
                fsCostoCalidad.Rules.Add(r20);
                fsCostoCalidad.Rules.Add(r21);
                fsCostoCalidad.Rules.Add(r22);
                fsCostoCalidad.Rules.Add(r23);
                fsCostoCalidad.Rules.Add(r24);
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Parsing exception: {0}", ex.Message));
                //MessageBox.Show(string.Format("Parsing exception: {0}", ex.Message));
                return(null);
            }
            return(fsCostoCalidad);
        }
Esempio n. 6
0
    void initAstronaut()
    {
        _fsAstronaut = new MamdaniFuzzySystem();

        fvHunger = new FuzzyVariable("Hunger", 0.0, 1.0);
        fvHunger.Terms.Add(new FuzzyTerm("minimal", new TrapezoidMembershipFunction(0.0, 0.0, 0.2, 0.2)));
        fvHunger.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(0.0, 0.3, 0.5)));
        fvHunger.Terms.Add(new FuzzyTerm("normal", new TriangularMembershipFunction(0.2, 0.5, 0.8)));
        fvHunger.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(0.5, 0.7, 1.0)));
        fvHunger.Terms.Add(new FuzzyTerm("maximal", new TrapezoidMembershipFunction(0.8, 0.8, 1.0, 1.0)));
        _fsAstronaut.Input.Add(fvHunger);

        fvThirst = new FuzzyVariable("Thirst", 0.0, 1.0);
        fvThirst.Terms.Add(new FuzzyTerm("minimal", new TrapezoidMembershipFunction(0.0, 0.0, 0.2, 0.2)));
        fvThirst.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(0.0, 0.3, 0.5)));
        fvThirst.Terms.Add(new FuzzyTerm("normal", new TriangularMembershipFunction(0.2, 0.5, 0.8)));
        fvThirst.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(0.5, 0.7, 1.0)));
        fvThirst.Terms.Add(new FuzzyTerm("maximal", new TrapezoidMembershipFunction(0.8, 0.8, 1.0, 1.0)));
        _fsAstronaut.Input.Add(fvThirst);

        fvTiredness = new FuzzyVariable("Tiredness", 0.0, 1.0);
        fvTiredness.Terms.Add(new FuzzyTerm("minimal", new TrapezoidMembershipFunction(0.0, 0.0, 0.2, 0.2)));
        fvTiredness.Terms.Add(new FuzzyTerm("low", new TriangularMembershipFunction(0.0, 0.3, 0.5)));
        fvTiredness.Terms.Add(new FuzzyTerm("normal", new TriangularMembershipFunction(0.2, 0.5, 0.8)));
        fvTiredness.Terms.Add(new FuzzyTerm("high", new TriangularMembershipFunction(0.5, 0.7, 1.0)));
        fvTiredness.Terms.Add(new FuzzyTerm("maximal", new TrapezoidMembershipFunction(0.8, 0.8, 1.0, 1.0)));
        _fsAstronaut.Input.Add(fvTiredness);

        FuzzyVariable svTarget = new FuzzyVariable("Target", 0, 1.0);

        svTarget.Terms.Add(new FuzzyTerm("sleep", new TrapezoidMembershipFunction(0.0, 0.0, 0.3, 0.6)));
        svTarget.Terms.Add(new FuzzyTerm("eat", new TrapezoidMembershipFunction(0.3, 0.5, 0.6, 0.7)));
        svTarget.Terms.Add(new FuzzyTerm("work", new TrapezoidMembershipFunction(0.6, 0.6, 1.0, 1.0)));
        _fsAstronaut.Output.Add(svTarget);

        MamdaniFuzzyRule rule1 = _fsAstronaut.ParseRule("if (Hunger is high) or (Thirst is high) or (Hunger is maximal) or (Thirst is maximal) then (Target is eat)");
        MamdaniFuzzyRule rule2 = _fsAstronaut.ParseRule("if (Tiredness is normal) or(Tiredness is high) or (Tiredness is maximal) then (Target is sleep)");
        MamdaniFuzzyRule rule3 = _fsAstronaut.ParseRule("if (Hunger is low) and (Thirst is low) and (Tiredness is low) then (Target is work)");
        MamdaniFuzzyRule rule4 = _fsAstronaut.ParseRule("if (Hunger is normal) and (Thirst is normal) and (Tiredness is low) then (Target is work)");

        //MamdaniFuzzyRule rule5 = _fsAstronaut.ParseRule("if (Hunger is minimal) and (Thirst is minimal) then (Target is not eat)");

        _fsAstronaut.Rules.Add(rule2);
        _fsAstronaut.Rules.Add(rule1);
        _fsAstronaut.Rules.Add(rule3);
        _fsAstronaut.Rules.Add(rule4);
        //_fsAstronaut.Rules.Add(rule5);

        System.Random rnd = new System.Random();
        _stats.Stress   = (float)rnd.NextDouble();
        _stats.Agility  = (float)rnd.NextDouble();
        _stats.Strength = (float)rnd.NextDouble();
        _stats.Health   = 1f;
        foreach (BaseModule module in Base.Instance.BaseModules)
        {
            if (module.HasFreeWorkingPlace)
            {
                currentLocation = module;
                var workingPlaces = currentLocation.GetComponent <ModuleWorkingPlaces>();
                transform.position = workingPlaces.ReserveWorkingPlace(this).position;
                currentLocation.AstronautEnter(this);
                break;
            }
        }
    }