⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fuzzysysview.cpp

📁 利用人工智能中的模糊控制算法模拟水温控制的过程
💻 CPP
字号:
// FuzzySysView.cpp : implementation of the CFuzzySysView class
//

#include "stdafx.h"
#include "FuzzySys.h"

#include "FuzzySysDoc.h"
#include "FuzzySysView.h"
#include "ParameterInputDlg.h"
#include "FuzzyVar.h"
#include "FuzzyRule.h"

#include <stdlib.h>
#include <time.h>


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFuzzySysView

IMPLEMENT_DYNCREATE(CFuzzySysView, CView)

BEGIN_MESSAGE_MAP(CFuzzySysView, CView)
	//{{AFX_MSG_MAP(CFuzzySysView)
	ON_COMMAND(ID_PARAMETER_INPUT, OnParameterInput)
	ON_UPDATE_COMMAND_UI(ID_PARAMETER_INPUT, OnUpdateParameterInput)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFuzzySysView construction/destruction

CFuzzySysView::CFuzzySysView()
{
	// TODO: add construction code here

}

CFuzzySysView::~CFuzzySysView()
{
}

BOOL CFuzzySysView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFuzzySysView drawing

void CFuzzySysView::OnDraw(CDC* pDC)
{
	CFuzzySysDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	CRect rectClient;

    GetClientRect(rectClient);
    pDC->SetMapMode(MM_ANISOTROPIC);
    pDC->SetWindowExt(2000, 2000);
    pDC->SetViewportExt(rectClient.right, -rectClient.bottom);
    pDC->SetViewportOrg(10, rectClient.bottom / 2);

	pDC->MoveTo(-10, 0);
	pDC->LineTo(2000, 0);
	
	pDC->MoveTo(0, 1000);
	pDC->LineTo(0, -1000);

	pDC->LineTo(m_pointNew);


}

/////////////////////////////////////////////////////////////////////////////
// CFuzzySysView diagnostics

#ifdef _DEBUG
void CFuzzySysView::AssertValid() const
{
	CView::AssertValid();
}

void CFuzzySysView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CFuzzySysDoc* CFuzzySysView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFuzzySysDoc)));
	return (CFuzzySysDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFuzzySysView message handlers

void CFuzzySysView::OnParameterInput() 
{
	// TODO: Add your command handler code here
	ParameterInputDlg paraInputDlg;
	if (paraInputDlg.DoModal() != IDOK)
		return;


	
	double e, deltaE, w;

	e = 200 * paraInputDlg.GetE();
	deltaE = 200 * paraInputDlg.GetDeltaE();
	CClientDC dc(this);
	
    CRect rectClient;
    GetClientRect(rectClient);
	dc.SetMapMode(MM_ANISOTROPIC);
    dc.SetWindowExt(2000, 2000);
    dc.SetViewportExt(rectClient.right, -rectClient.bottom);
    dc.SetViewportOrg(10, rectClient.bottom / 2);

	CPen newPen;
	newPen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
	CPen* pOldPen = dc.SelectObject(&newPen);

	srand( (unsigned)time( NULL ) );
	
	int x = 0;
	dc.MoveTo(x=0, (int)e);

	int step = 8;
	for (x+=step; x<2000; x+=step)
	{
		FuzzyVar fv1(e), fv2(deltaE);
		FuzzyRule fr(fv1, fv2);
		w = fr.CalculateW();

		double f;
		if (x == step)
			f = 0.2;
		else
			f = 1;//0.999999;
		int r = rand() % 100 - 45;
		deltaE = f*deltaE + 0.07 * (w+r);

//		int r = rand() % 100 - 45;
//		deltaE = 0.999999*deltaE + 0.0678 * (w+r);
//		int r = rand() % 900 - 450;
//		deltaE = 0.0692 * (w+r);
//		int r = rand() % 800 - 400;
//		deltaE = 0.0918 * (w+r);

		e += deltaE;

//		m_pointNew = CPoint(x, e);
//		Invalidate(true);

		dc.LineTo(x, (int)e);
	}

	dc.SelectObject(pOldPen);
}

void CFuzzySysView::OnUpdateParameterInput(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -