| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 375 人关注过本帖
标题:如何把它改一下结构,输出结果不变
只看楼主 加入收藏
yuandingfa
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-11-1
收藏
 问题点数:0 回复次数:1 
如何把它改一下结构,输出结果不变
#include <stdio.h>
#include <string.h>
#include <math.h>



#define MAX(x, y)    ((x)>(y)?(x):(y))
#define MIN(x, y)    ((x)<(y)?(x):(y))


class FuzzySet_Guass
{
public:
    double m_sigma;
    double m_aver;

    double m_border_left;
    double m_border_right;

    double m_points;

    char  m_name[300];

    double *m_data;

    void ApplyAggregationMethod(FuzzySet_Guass &set1)
    {
        for (int i = 0; i < m_points;i++ )
        {
            m_data[i] = MAX(m_data[i], set1.m_data[i]);
        }
    }


    FuzzySet_Guass(double sigma, double aver, double border_left, double border_right, int points,char *name)
    {
        m_sigma = sigma;
        m_aver = aver;
        m_border_left = border_left;
        m_border_right = border_right;
        m_points = points;
        //m_name = name;
        strcpy(m_name, name);

        m_data=new double[points];


        double x = m_border_left;
        for(int i=0;i <m_points;i++)
        {
            x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
            m_data[i]=Gauss(x, m_sigma, m_aver);
        }
    }

    double FuzzifyInput(double accurate_input)
    {
        return Gauss(accurate_input, m_sigma, m_aver);
    }

    void ApplyImplicationMethod(double a)
    {
        for(int i=0;i <m_points;i++)
        {
            m_data[i] = MIN(a, m_data[i]);
        }
    }

    double Defuzzify()
    {
        double numerator=0;

        double denominator = 0;
        double x=0;

        for (int i = 0; i < m_points; i++ )
        {
            x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
            numerator += x * m_data[i];

            denominator += m_data[i];
        }

        return numerator / denominator;
    }

    void PrintFuzzySetElements()
    {
        printf("Fuzzy Set --%s", m_name);
        int i = 0;
        for(i =0; i<m_points; i++)
        {
            printf("%f", m_data[i]);
        }

        printf("\n") ;

        for (i = 0; i < m_points; i++)
        {
            double x = m_border_left + i * (m_border_right - m_border_left) / (m_points-1);
            printf("i=%d, data=%f, x=%f" , i, m_data[i],x);
        }

        printf("\n") ;
    }

    double Gauss(double x, double sigma, double aver)
    {
        return pow(2.7182818284590451, -pow((x - aver) / sigma, 2)/2);
    }
};

class Program
{
public:
    double ApplyFuzzyOperation(double a,double b)
    {
        return MIN(a, b);
    }
   
    void Run()
    {
        
        while (true)
        {
            //模糊规则
            //if e is E_NB and ec is EC_NB, then u is U_NB
            //if e is E_PB and ec is EC_PB, then u is U_PB
            
            //定义模糊集合
            FuzzySet_Guass U_NB(3, -10, -10, 10, 1001, "U_NB");
            FuzzySet_Guass U_PB(3, 10, -10, 10, 1001, "U_PB");
            
            FuzzySet_Guass E_NB(3, -10, -10, 10, 1001, "E_NB");
            FuzzySet_Guass E_PB(3, 10, -10, 10, 1001, "E_PB");
            
            FuzzySet_Guass EC_NB(3, -10, -10, 10, 1001, "EC_NB");
            FuzzySet_Guass EC_PB(3, 10, -10, 10, 1001, "EC_PB");
            
            
            //输入误差e和误差变化率ec
            printf("e=");
            float input1 = 0.0;
            scanf("%f", &input1);
            
            float input2 = 0.0;
            printf("ec=");
            scanf("%f", &input2);
            
            
            //step1
            double e1 = E_NB.FuzzifyInput(input1);
            double ec1 = EC_NB.FuzzifyInput(input2);
            printf("e1=%e, ec1=%e\n", e1, ec1);
            
            //step2
            double a1=ApplyFuzzyOperation(e1, ec1);
            printf("a1=%e\n", a1);
            
            //step3
            U_NB.ApplyImplicationMethod(a1);//被改变的U_NB
            
            
            //step1
            double e2 = E_PB.FuzzifyInput(input1);
            double ec2 = EC_PB.FuzzifyInput(input2);
            
            
            //step2
            double a2 = ApplyFuzzyOperation(e2, ec2);
            
            
            //step3
            U_PB.ApplyImplicationMethod(a2);//被改变的U_PB
            
            
            //step4
            U_PB.ApplyAggregationMethod(U_NB);//被改变的U_PB
            
            
            //step5
            double u = U_PB.Defuzzify();
            printf("u=%e\n", u);
        }
        
    }
};

void main()
{
    Program pp;
    pp.Run();

}
搜索更多相关主题的帖子: 结构 结果 输出 
2009-11-01 22:59
ljt0000mf
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:104
专家分:157
注 册:2009-7-4
收藏
得分:0 
我操,给钱,有人帮你
2009-11-01 23:07
快速回复:如何把它改一下结构,输出结果不变
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016155 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved