📄 cbadlg.cpp
字号:
// CBADlg.cpp : implementation file
//
#include "stdafx.h"
#include "CBA_SYSTEM.h"
#include "CBADlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCBADlg dialog
//静态成员初始化
int *CCBADlg::p_num_HNodes =NULL;
float *CCBADlg::p_num_HNodesPy = NULL;
float *CCBADlg::p_num_INodesPy=NULL;
float *CCBADlg::p_weight= NULL;
CWeight *CCBADlg::m_wp = NULL;
int CCBADlg::NumberofOlayerNode = 1;
int CCBADlg::NumberofHlayer = 1;
int CCBADlg::NumberofIlayerNode = 6;
int CCBADlg::IndexofStopMode = 0;
short CCBADlg::w_num = 0;
CCBADlg::CCBADlg(CWnd* pParent /*=NULL*/)
: CDialog(CCBADlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCBADlg)
m_mxqz = 0.1f;
m_sccpyz = 0.0f;
m_xljg = _T("");
m_yccpyz = 0.0f;
m_sccjds = 1;
m_srcjds = 6;
m_yccjds = 1;
m_yccs = 1;
m_stop = 1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
CCBADlg::~CCBADlg()
{
delete []p_num_HNodes;
delete []p_num_HNodesPy;
delete []p_num_INodesPy;
delete []m_wp;
delete []p_weight;
}
int * CCBADlg::GetHNodes()
{
return p_num_HNodes;
}
float * CCBADlg::GetHNodesPy()
{
return p_num_HNodesPy;
}
float * CCBADlg::GetONodesPy()
{
return p_num_INodesPy;
}
CWeight *CCBADlg::GetWeight()
{
return m_wp;
}
int CCBADlg::GetNumberofHlayer()
{
return NumberofHlayer;
}
int CCBADlg::GetNumberofOlayerNode()
{
return NumberofOlayerNode;
}
int CCBADlg::GetNumberofIlayerNode()
{
return NumberofIlayerNode;
}
int CCBADlg::GetStopModeindex()
{
return IndexofStopMode;
}
int CCBADlg::GetStopMode()
{
return m_stop;
}
int CCBADlg::GetW_Num()
{
return w_num;
}
void CCBADlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCBADlg)
DDX_Control(pDX, IDC_STOP_COMBO, m_stopcombo);
DDX_Control(pDX, IDC_NOFYCS_COMBO1, m_nofycscombo);
DDX_Control(pDX, IDC_YCCPY_COMBO2, m_yccpycombo);
DDX_Control(pDX, IDC_SCCPY_COMBO3, m_sccpycomb);
DDX_Control(pDX, IDC_MXQZ_COMBO4, m_mxqzcombo);
DDX_Control(pDX,IDC_BUTTON1,m_surebutton);
DDX_Text(pDX, IDC_MXQZZ_EDIT2, m_mxqz);
DDV_MinMaxFloat(pDX, m_mxqz, -1.f, 1.f);
DDX_Text(pDX, IDC_SCCPYZ_EDIT3, m_sccpyz);
DDV_MinMaxFloat(pDX, m_sccpyz, -1.f, 1.f);
DDX_Text(pDX, IDC_YCCPYZ_EDIT1, m_yccpyz);
DDV_MinMaxFloat(pDX, m_yccpyz, -1.f, 1.f);
DDX_Text(pDX, IDC_SCCJDS_EDIT3, m_sccjds);
DDV_MinMaxInt(pDX, m_sccjds, 1, 10000);
DDX_Text(pDX, IDC_SRCJDS_EDIT1, m_srcjds);
DDV_MinMaxInt(pDX, m_srcjds, 1, 10000);
DDX_Text(pDX, IDC_YCCJDS_EDIT2, m_yccjds);
DDV_MinMaxInt(pDX, m_yccjds, 1, 10000);
DDX_Text(pDX, IDC_YCCS_EDIT2, m_yccs);
DDV_MinMaxInt(pDX, m_yccs, 1, 10000);
DDX_Text(pDX, IDC_STOP_EDIT, m_stop);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCBADlg, CDialog)
//{{AFX_MSG_MAP(CCBADlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SETFOCUS(IDC_NOFYCS_COMBO1, OnSetfocusNofycsCombo)
ON_EN_KILLFOCUS(IDC_YCCS_EDIT2, OnKillfocusYccs)
ON_EN_KILLFOCUS(IDC_YCCJDS_EDIT2, OnKillfocusYccjdsEdit2)
ON_CBN_SELCHANGE(IDC_NOFYCS_COMBO1, OnSelchangeNofycsCombo)
ON_CBN_SETFOCUS(IDC_YCCPY_COMBO2, OnSetfocusYccpyCombo)
ON_CBN_SELCHANGE(IDC_YCCPY_COMBO2, OnSelchangeYccpyCombo)
ON_EN_KILLFOCUS(IDC_YCCPYZ_EDIT1, OnKillfocusYccpyzEdit)
ON_CBN_SETFOCUS(IDC_SCCPY_COMBO3, OnSetfocusSccpyCombo)
ON_EN_KILLFOCUS(IDC_SCCPYZ_EDIT3, OnKillfocusSccpyzEdit)
ON_EN_KILLFOCUS(IDC_SCCJDS_EDIT3, OnKillfocusSccjdsEdit)
ON_CBN_SELCHANGE(IDC_SCCPY_COMBO3, OnSelchangeSccpyCombo)
ON_CBN_SETFOCUS(IDC_MXQZ_COMBO4, OnSetfocusMxqzCombo)
ON_CBN_SELCHANGE(IDC_MXQZ_COMBO4, OnSelchangeMxqzCombo)
ON_EN_KILLFOCUS(IDC_MXQZZ_EDIT2, OnKillfocusMxqzzEdit)
ON_BN_CLICKED(IDC_BUTTON1, OnInitNetwork)
ON_WM_SYSCOMMAND()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCBADlg message handlers
BOOL CCBADlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//////////////////////////////MycodeHere///////////////////////////////////
//初始化combo m_nofycscombo
for(int i = 1;i<m_yccs+1;i++)
{
CString str="";
str.Format("%d",i);
str = "层" + str;
m_nofycscombo.AddString(str);
}
m_nofycscombo.SetCurSel(0);
p_num_HNodes = new int[m_yccs];
for(i = 0;i<m_yccs;i++)
{
p_num_HNodes[i] = 0;
}
//初始化标识isInit;
isInit = FALSE;
//为数组指针开辟初始空间并赋值
p_num_HNodesPy = new float[1];
p_num_HNodesPy = 0;
p_num_INodesPy = new float[1];
p_num_INodesPy[0] = 0;
m_wp = new CWeight[1];
p_weight = new float[1];
p_weight[0] = 0;
//初始化combo m_stopcombo
for(int j=1;j<3;j++)
{
CString tempstr = "";
tempstr.Format("%d",j);
tempstr = "模式"+tempstr;
m_stopcombo.AddString(tempstr);
}
m_stopcombo.SetCurSel(0);
/////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCBADlg::OnPaint()
{
CRect rect;
CPaintDC dc(this);
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(255,255,255)); //设置为白色背景
CDialog::OnPaint();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCBADlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCBADlg::OnSetfocusNofycsCombo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_nofycscombo.ResetContent();
for(int i = 1;i<m_yccs+1;i++)
{
CString str="";
str.Format("%d",i);
str = "层" + str;
m_nofycscombo.AddString(str);
}
m_nofycscombo.SetCurSel(0);
}
void CCBADlg::OnKillfocusYccs()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
p_num_HNodes = new int[m_yccs];
for(int i = 0;i<m_yccs;i++)
{
p_num_HNodes[i] = 0;
}
}
void CCBADlg::OnKillfocusYccjdsEdit2()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int i;
i = m_nofycscombo.GetCurSel();
p_num_HNodes[i] = m_yccjds;
int j = 0;
for(i = 0;i<m_yccs;i++)
{
j = j+ p_num_HNodes[i];
}
p_num_HNodesPy = new float[j];
for(i = 0;i<j;i++)
{
p_num_HNodesPy[i] = 0;
}
}
void CCBADlg::OnSelchangeNofycsCombo()
{
// TODO: Add your control notification handler code here
int i;
i = m_nofycscombo.GetCurSel();
m_yccjds = p_num_HNodes[i];
UpdateData(FALSE);
}
void CCBADlg::OnSetfocusYccpyCombo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_yccpycombo.ResetContent();
CString str="";
int j = 0;
for(int i = 0;i<m_yccs;i++)
{
j = j+ p_num_HNodes[i];
}
for(int k=1;k<j+1;k++)
{
str.Format("%d",k);
m_yccpycombo.AddString(str);
}
m_yccpycombo.SetCurSel(0);
}
void CCBADlg::OnSelchangeYccpyCombo()
{
// TODO: Add your control notification handler code here
int i = m_yccpycombo.GetCurSel();
m_yccpyz = p_num_HNodesPy[i];
UpdateData(FALSE);
}
void CCBADlg::OnKillfocusYccpyzEdit()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int i;
i = m_yccpycombo.GetCurSel();
p_num_HNodesPy[i] = m_yccpyz;
}
void CCBADlg::OnSetfocusSccpyCombo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_sccpycomb.ResetContent();
CString str;
for(int k=1;k<m_sccjds+1;k++)
{
str.Format("%d",k);
m_sccpycomb.AddString(str);
}
m_sccpycomb.SetCurSel(0);
}
void CCBADlg::OnKillfocusSccpyzEdit()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int i = m_sccpycomb.GetCurSel();
p_num_INodesPy[i] = m_sccpyz;
}
void CCBADlg::OnKillfocusSccjdsEdit()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
p_num_INodesPy = new float[m_sccjds];
for (int i=0;i<m_sccjds;i++) {
p_num_INodesPy[i]=0;
}
SetNetWorkWeight();
}
void CCBADlg::OnSelchangeSccpyCombo()
{
// TODO: Add your control notification handler code here
int i = m_sccpycomb.GetCurSel();
m_sccpyz = p_num_INodesPy[i];
UpdateData(FALSE);
}
void CCBADlg::SetNetWorkWeight()
{
UpdateData(TRUE);
/*权值的个数由公式:输入层节点数x隐藏层节点数+隐藏层节点数x输出层节点数*/
short ih_w_num,ho_w_num,hh_w_num=0; //w_num权值总数,ih_w_num输入层到隐藏层的权值总数,ho_w_num隐藏层到输出层的权值总数
//hh_w_num隐藏层第一层到隐藏层最后一层权值总数
ih_w_num = m_srcjds*p_num_HNodes[0];
for(int ii_h=0;ii_h<m_yccs-1;ii_h++)
{
hh_w_num = hh_w_num+p_num_HNodes[ii_h]*p_num_HNodes[ii_h+1];
}
ho_w_num = p_num_HNodes[m_yccs-1]*m_sccjds;
w_num = ih_w_num+hh_w_num+ho_w_num;
m_wp = new CWeight[w_num];
p_weight = new float[w_num];
for(int i=0;i<w_num;i++)
{
p_weight[i] = 0;
}
}
void CCBADlg::OnSetfocusMxqzCombo()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_mxqzcombo.ResetContent();
short ih_w_num,ho_w_num,hh_w_num=0; //w_num权值总数,ih_w_num输入层到隐藏层的权值总数,ho_w_num隐藏层到输出层的权值总数
//hh_w_num隐藏层第一层到隐藏层最后一层权值总数
CString str="";
ih_w_num = m_srcjds*p_num_HNodes[0];
for(int ii_h=0;ii_h<m_yccs-1;ii_h++)
{
hh_w_num = hh_w_num+p_num_HNodes[ii_h]*p_num_HNodes[ii_h+1];
}
ho_w_num = p_num_HNodes[m_yccs-1]*m_sccjds;
w_num = ih_w_num+hh_w_num+ho_w_num;
for(int i=0;i<w_num;i++)
{
str.Format("%d",i);
str = "w"+str;
m_mxqzcombo.AddString(str);
}
m_mxqzcombo.SetCurSel(0);
}
void CCBADlg::OnSelchangeMxqzCombo()
{
// TODO: Add your control notification handler code here
int i = m_mxqzcombo.GetCurSel();
m_mxqz = p_weight[i];
UpdateData(FALSE);
}
void CCBADlg::OnKillfocusMxqzzEdit()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int i = m_mxqzcombo.GetCurSel();
p_weight[i] = m_mxqz;
for(int j=0;j<w_num;j++)
{
m_wp[j].SetW_w(p_weight[j]);
}
}
void CCBADlg::OnInitNetwork()
{
// TODO: Add your control notification handler code here
if(m_sccjds==0||m_srcjds==0||m_yccjds ==0)
{
MessageBox("请正确配置模型参数",NULL,MB_OK|MB_ICONINFORMATION);
return;
}
//数据准备
UpdateData(TRUE);
NumberofIlayerNode = m_srcjds;
NumberofOlayerNode = m_sccjds;
NumberofHlayer = m_yccs;
IndexofStopMode = m_stopcombo.GetCurSel();
MessageBox("配置成功!",NULL,MB_OK|MB_ICONINFORMATION);
/*CString out_str="";
float data[119][7];
float num_of_data[1];
//float a[] = {1,0,1,1};
//初始化ADO
if(ado.ReadConfigFile("DataConfig.txt"))
{
if(!ado.OnInitADOConn())
{
return;
}
CString temp = ado.username;
if(ado.GetData(num_of_data,"select count(*) from train_data"))
{
if(ado.GetData(data[0],"select * from train_data"))
{
isInit = true;
}
}
else
{
MessageBox("数据库中没有训练数据!",NULL,MB_OK);
ado.ExitConnect();
return;
}
ado.ExitConnect();
/////////////////////////////////////////////////////
CNeural_NetWork network(m_yccs);
network.InitNeural_NetWork(m_srcjds,m_sccjds,p_num_HNodes,p_num_HNodesPy,p_num_INodesPy,m_wp);
int indexofmode;
indexofmode = m_stopcombo.GetCurSel();
switch(indexofmode)
{
case 0:
network.Train(data[0],num_of_data[0],m_stop);
break;
case 1:
network.SK_Train(data[0],num_of_data[0],m_stop);
break;
}
}
else
{
MessageBox("读取配置连接失败,请检查配置!",NULL,MB_OK|MB_ICONINFORMATION);
return;
}
*/
//out_str = network.GetResult();
//m_xljg = out_str;
//UpdateData(FALSE);
}
HBRUSH CCBADlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == IDC_STATIC)
{
// Set the text color to red
hbr = CreateSolidBrush(RGB(255,255,255));
pDC->SetTextColor(RGB(0, 0, 0));
// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object
//hbr = m_brush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -