📄 nnbpdlg.cpp
字号:
// NNBPDlg.cpp : implementation file
//
#include "stdafx.h"
#include "process.h"
#include "NNBPDlg.h"
#include "MainFrm.h"
#include "ProcessView.h"
// Add the user-defined header file
#include "AllDef.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNNBPDlg dialog
CNNBPDlg::CNNBPDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNNBPDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNNBPDlg)
m_strDemoDataInput = _T("");
m_strDemoSaveResult = _T("");
m_nInputLayerNumber = 1;
m_nHideLayerNumber = 12;
m_nOutputLayerNumber = 1;
m_nComboFunc = 2;
m_nSystemError = 0.0;
m_nTrainTimes = 0;
m_nSystemErrorLevel = SYSTEM_ERROR_LEVEL;
m_nMaxTrainTimes = LOOP_MAX_TIMES;
m_strDemoSaveNetwork = _T("");
m_strSimuNetworkFold = _T("");
m_strSimuDataInput = _T("");
m_strSimuResult = _T("");
m_nComboArithmetic = 0;
m_nStep = INIT_STEP;
//}}AFX_DATA_INIT
// Initialize the member variables
m_bStartFlag = false;
m_bSimulateDataFlag = false;
m_SystemErrorNew = MAX_SYSTEM_ERROR;
m_SystemErrorOld = MAX_SYSTEM_ERROR;
m_hThread = NULL;
}
void CNNBPDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNNBPDlg)
DDX_Control(pDX, IDC_COMBO_ARITHMETIC, m_ctrlComboArithmetic);
DDX_Control(pDX, IDC_COMBO_FUNC, m_ctrlComboFunc);
//DDX_Control(pDX, IDC_STATIC_TITLE, m_staticTextTitle);
DDX_Control(pDX, IDC_STATE1, m_btnState);
DDX_Control(pDX, IDC_SIMU_RESULT_BROWSER, m_btnSimuResultBrowser);
DDX_Control(pDX, IDC_SIMU_NETWORK_FOLD_BROWSER, m_btnSimuNetworkFoldBrowser);
DDX_Control(pDX, IDC_SIMU_DATA_INPUT_BROWSER, m_btnSimuDataInputBrowser);
DDX_Control(pDX, IDC_DEMO_SAVE_RESULT_BROWSER, m_btnDemoSaveResultBrowser);
DDX_Control(pDX, IDC_DEMO_SAVE_NETWORK_BROWSER, m_btnDemoSaveNetworkBrowser);
DDX_Control(pDX, IDC_DEMO_DATA_INPUT_BROWSER, m_btnDemoDataInputBrowser);
DDX_Control(pDX, IDC_STOP_TRAIN, m_btnStopTrain);
DDX_Control(pDX, IDC_EXIT, m_btnExit);
// DDX_Control(pDX, IDC_ABOUT_US, m_btnAboutUs);
DDX_Control(pDX, IDC_BEGIN_TRAIN, m_btnBeginTrain);
DDX_Text(pDX, IDC_DEMO_DATA_INPUT, m_strDemoDataInput);
DDX_Text(pDX, IDC_DEMO_SAVE_RESULT, m_strDemoSaveResult);
DDX_Text(pDX, IDC_INPUT_LAYER_NUMBER, m_nInputLayerNumber);
DDX_Text(pDX, IDC_HIDE_LAYER_NUMBER, m_nHideLayerNumber);
DDX_Text(pDX, IDC_OUTPUT_LAYER_NUMBER, m_nOutputLayerNumber);
DDX_CBIndex(pDX, IDC_COMBO_FUNC, m_nComboFunc);
DDX_Text(pDX, IDC_SYSTEM_ERROR, m_nSystemError);
DDX_Text(pDX, IDC_TRAIN_TIMES, m_nTrainTimes);
DDX_Text(pDX, IDC_SYSTEM_LEVEL, m_nSystemErrorLevel);
DDX_Text(pDX, IDC_MAX_TRAIN_TIMES, m_nMaxTrainTimes);
DDX_Text(pDX, IDC_DEMO_SAVE_NETWORK, m_strDemoSaveNetwork);
DDX_Text(pDX, IDC_SIMU_NETWORK_FOLD, m_strSimuNetworkFold);
DDX_Text(pDX, IDC_SIMU_DATA_INPUT, m_strSimuDataInput);
DDX_Text(pDX, IDC_SIMU_RESULT, m_strSimuResult);
DDX_CBIndex(pDX, IDC_COMBO_ARITHMETIC, m_nComboArithmetic);
DDX_Text(pDX, IDC_STEP, m_nStep);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNNBPDlg, CDialog)
//{{AFX_MSG_MAP(CNNBPDlg)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_DEMO_DATA_INPUT_BROWSER, OnDemoDataInputBrowser)
ON_BN_CLICKED(IDC_DEMO_SAVE_NETWORK_BROWSER, OnDemoSaveNetworkBrowser)
ON_BN_CLICKED(IDC_DEMO_SAVE_RESULT_BROWSER, OnDemoSaveResultBrowser)
ON_BN_CLICKED(IDC_SIMU_NETWORK_FOLD_BROWSER, OnSimuNetworkFoldBrowser)
ON_BN_CLICKED(IDC_SIMU_DATA_INPUT_BROWSER, OnSimuDataInputBrowser)
ON_BN_CLICKED(IDC_SIMU_RESULT_BROWSER, OnSimuResultBrowser)
ON_BN_CLICKED(IDC_BEGIN_TRAIN, OnBeginTrain)
ON_BN_CLICKED(IDC_STATE1, OnState)
ON_BN_CLICKED(IDC_STOP_TRAIN, OnStopTrain)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////
void CNNBPDlg::OnExit()
{
// TODO: Add your control notification handler code here
DWORD dwExitCode = 0;
if(::GetExitCodeThread (m_hThread, &dwExitCode))
{
if(dwExitCode == STILL_ACTIVE)
{
::TerminateThread (m_hThread, (DWORD)0);
}
CloseHandle (m_hThread);
m_hThread = NULL;
}
CDialog::OnCancel ();
CDialog::DestroyWindow();
}
void CNNBPDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnTimer(nIDEvent);
}
/////////////////////////////////////////////////////////////////////////////
void CNNBPDlg::OnDemoDataInputBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file to load the data
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal () == IDOK)
{
m_strDemoDataInput = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_DATA_INPUT);
::SetWindowText (hWnd,m_strDemoDataInput);
}
else
{
return;
}
CStdioFile m_File;
CFileException e;
if(!m_File.Open(m_strDemoDataInput,CFile::modeRead, &e))
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
}
double XX,YY ;
CString m_strLine;
CString m_str;
char m_char;
BOOL m_bEnd=TRUE;
int TempDepth,TempData,dot,kk;
int temp;
//显示学习用的数据曲线
memset(DataX,0.0,sizeof(double)*shuzu);
memset(DataY,0.0,sizeof(double)*shuzu);
XX=0.0;
YY=0.0;
TempDepth=0;
TempData=0;
while(m_bEnd)
{
m_bEnd=m_File.ReadString(m_strLine);
if(m_bEnd)//如果读出一行
{
DataNum++;
dot=0;
kk=0;
int num=m_strLine.GetLength();
for(int i=0;i<num;i++)
{
m_char=m_strLine.GetAt(i);
if(m_char!=' ')//当两组数据间用空格分开时为' '
{ //当两组数据间用逗号分开时为','
m_str+=m_char;
}
else
{
dot++;
switch(dot)
{
case 1:
YY=atof(m_str);
DataX[TempDepth]=(double)YY*120;
TempDepth++;
m_str="";
for(kk=i+1;kk<num;kk++)
{ //注意:如果让kk<num-1的话,读出的DataData[]有可能不对!!!
m_char=m_strLine.GetAt(kk);
m_str+=m_char;
}
XX=atof(m_str);
DataY[TempData]=(double)XX*160;
TempData++;
m_str="";
i=num;
break;
default:
break;
}
}
}
}
}
m_File.Close();
CProcessApp *app=(CProcessApp *)AfxGetApp();
memcpy(app->DataX,DataX,sizeof(double)*shuzu);
memcpy(app->DataY,DataY,sizeof(double)*shuzu);
app->DataNum=DataNum;
app->DRAWBPNN=TRUE;
//获得的主框架的句柄
CMainFrame *pFrm=(CMainFrame*)AfxGetMainWnd();
//获得活动视图的句柄
CProcessView *pView=(CProcessView* )pFrm->GetActiveView();
if(pView == NULL)
{
AfxMessageBox("没有活动的视图!");
return;
}
pView->Invalidate();
}
void CNNBPDlg::OnDemoSaveNetworkBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file to save the network
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this );
if(dlg.DoModal ()==IDOK)
{
m_strDemoSaveNetwork = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd,IDC_DEMO_SAVE_NETWORK);
::SetWindowText (hWnd,m_strDemoSaveNetwork);
}
else
{
return;
}
}
void CNNBPDlg::OnDemoSaveResultBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file to save the result
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strDemoSaveResult = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd , IDC_DEMO_SAVE_RESULT);
::SetWindowText (hWnd, m_strDemoSaveResult);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuNetworkFoldBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the network data file
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuNetworkFold = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_NETWORK_FOLD);
::SetWindowText (hWnd, m_strSimuNetworkFold);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuDataInputBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the simulate data file
CFileDialog dlg(TRUE,
lpszDefExt,
NULL,
OFN_READONLY |
OFN_FILEMUSTEXIST |
OFN_PATHMUSTEXIST,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuDataInput = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_DATA_INPUT);
::SetWindowText (hWnd,m_strSimuDataInput);
}
else
{
return;
}
}
void CNNBPDlg::OnSimuResultBrowser()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = TEXT("文本文件(*.txt)|*.txt|All Files (*.*)|*.*||");
static char BASED_CODE lpszDefExt[] = TEXT("txt");
//Create the dialog to select the demo data file
CFileDialog dlg(FALSE,
lpszDefExt,
NULL,
OFN_HIDEREADONLY |
OFN_CREATEPROMPT |
OFN_OVERWRITEPROMPT,
szFilter,
this);
if(dlg.DoModal ()==IDOK)
{
m_strSimuResult = dlg.GetPathName ();
HWND hWnd = ::GetDlgItem (this->m_hWnd ,IDC_SIMU_RESULT);
::SetWindowText (hWnd,m_strSimuResult);
}
else
{
return;
}
}
//////////////////
void CNNBPDlg::OnState()
{
// TODO: Add your control notification handler code here
/////////////////////////////////////////////////////////////////////////
// Change the button flag
m_bSimulateDataFlag = !m_bSimulateDataFlag;
if(m_bSimulateDataFlag)
{
// 程序处在数据仿真状态
// m_btnState.SetIcon (IDI_SIMULATOR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -