📄 fuzzyview.cpp
字号:
// fuzzyView.cpp : implementation of the CFuzzyView class
//
#include "stdafx.h"
#include "fuzzy.h"
#include "fuzzyDoc.h"
#include "fuzzyView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFuzzyView
IMPLEMENT_DYNCREATE(CFuzzyView, CFormView)
BEGIN_MESSAGE_MAP(CFuzzyView, CFormView)
//{{AFX_MSG_MAP(CFuzzyView)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFuzzyView construction/destruction
CFuzzyView::CFuzzyView()
: CFormView(CFuzzyView::IDD)
{
//{{AFX_DATA_INIT(CFuzzyView)
m_T = 0;
m_dT = 0;
m_out = 0.0;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CFuzzyView::~CFuzzyView()
{
}
void CFuzzyView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFuzzyView)
DDX_Text(pDX, IDC_EDIT1, m_T);
DDX_Text(pDX, IDC_EDIT2, m_dT);
DDX_Text(pDX, IDC_EDIT3, m_out);
//}}AFX_DATA_MAP
}
BOOL CFuzzyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CFuzzyView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CFuzzyView printing
BOOL CFuzzyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFuzzyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFuzzyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CFuzzyView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CFuzzyView diagnostics
#ifdef _DEBUG
void CFuzzyView::AssertValid() const
{
CFormView::AssertValid();
}
void CFuzzyView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFuzzyDoc* CFuzzyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFuzzyDoc)));
return (CFuzzyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFuzzyView message handlers
void CFuzzyView::following(int T, int dT)
{
float Gas_NM[] = {
1.0, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
float Gas_NS[] = {
0, 0, 0.5, 1.0, 0.5, 0, 0, 0, 0, 0, 0
};
float Gas_Z[] = {
0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 0
};
float Gas_PS[] = {
0, 0, 0, 0, 0, 0, 0.5, 1.0, 0.5, 0, 0
};
float Gas_PM[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0.5, 1.0
};
float Gas_output;
int i;
float map_i, v_i, area, moment;
float t001;
float ut_nm,ut_z,ut_pm;
float dt_nm,dt_z,dt_pm;
float *O_Gas;
O_Gas = (float *) calloc(11,sizeof(float));
/* T is NM */
ut_nm=0.0;
if (T >= 30 && T <= 50)
ut_nm = (float)(45-T)/20;
/* T is Z */
ut_z=0.0;
if ((T>=40) && (T<=60))
ut_z=(float)(T-40)/20;
if (T>60 && T<=80)
ut_z=(float)(80-T)/20;
/* T is PM */
ut_pm=0.0;
if (T>=70 && T<=90)
ut_pm=(float)(T-70)/30;
/* dT is NM */
dt_nm=0.0;
if (dT>=30 && dT<=50)
dt_nm=(float)(50-dT)/20;
/* dT is Z */
dt_z=0.0;
if (dT>=40 && dT <= 60)
dt_z=(float)(dT-40)/20;
if (dT>60 && dT<=80)
dt_z=(float)(80-dT)/20;
/* dT is PM */
dt_pm=0.0;
if (dT>=70 && dT<=90)
dt_pm=(float)(dT-70)/20;
/*************** Rule1 ***************/
/* T IS PM and dT IS PM*/
t001 = min(ut_pm, dt_pm); /* AND */
printf("\nRule 1: %f\n", t001);
/* Gas = NM */
if (t001 != 0.0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_PS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule2 ***************/
/* T IS PM and dT IS Z */
t001 = min(ut_pm, dt_z); /* AND */
printf("Rule 2: %f\n", t001);
/* Gas = NS */
if (t001 != 0.0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_PS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule3 ***************/
/* T IS PM and dT IS NM */
t001 = min(ut_pm,dt_nm); /* AND */
printf("Rule 3: %f\n", t001);
/* Gas = Z */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_PM[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule4 ***************/
/* T IS Z and dT IS PM */
t001 = min(ut_z,dt_pm); /* AND */
printf("Rule 4: %f\n", t001);
/* Gas = NS */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_NS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule5 ***************/
/* T IS Z and dT is Z */
t001 = min(ut_z,dt_z); /* AND */
printf("Rule 5: %f\n", t001);
/* Gas = Z */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_Z[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule6 ***************/
/* T IS Z and dT IS NM*/
t001 = min(ut_z,dt_nm); /* AND */
printf("Rule 6: %f\n", t001);
/* Gas = PS */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_PS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule7 ***************/
/* T IS NM and dT IS PM */
t001 = min(ut_nm,dt_pm); /* AND */
printf("Rule 7: %f\n", t001);
/* Gas = Z */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_NM[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule8 ***************/
/* T IS NM and dT IS Z*/
t001 = min(ut_nm,dt_z); /* AND */
printf("Rule 8: %f\n", t001);
/* Gas = PS */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_NS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/*************** Rule9 ***************/
/* T IS NM and dT IS NM*/
t001 = min(ut_nm,dt_nm); /* AND */
printf("Rule 9: %f\n", t001);
/* Gas = PM */
if (t001 != (float)0) {
for (i=0; i<11; i++) {
map_i = (float)Gas_NS[i];
O_Gas[i] = max(O_Gas[i], min(t001, map_i));
}
}
/***** Calculate crisp value for variable Gas ******/
area = 0.0; moment = 0.0;
for(i=0; i<11; i++) {
map_i = O_Gas[i];
printf("i=%2d map_i=%f\n", i, map_i);
v_i = -5.0 + (float)i;
area += map_i;
moment += map_i * v_i;
}
if (area == 0) { /* Divide by zero error */
Gas_output = 11.0;
}
else
Gas_output = (moment / area);
//free(O_Gas);
CString str;
str.Format("%f",Gas_output);
AfxMessageBox(str);
//m_out = Gas_output;
//UpdateData(0);
}
void CFuzzyView::OnButton1()
{
UpdateData(1);
following(m_T,m_dT);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -