📄 jsgadlg.cpp
字号:
// jsgaDlg.cpp : implementation file
//
#include "stdafx.h"
#include "jsga.h"
#include "jsgaDlg.h"
#include "person.h"
#include "jspga.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CJsgaDlg dialog
SYSPARA gasp; //定义遗传算法的全局参数
CJsgaDlg::CJsgaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJsgaDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CJsgaDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CJsgaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJsgaDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJsgaDlg, CDialog)
//{{AFX_MSG_MAP(CJsgaDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_APP, OnBtnApp)
ON_CBN_SELCHANGE(IDC_CMB_PARAGROUP, OnSelchangeCmbParagroup)
ON_BN_CLICKED(IDC_BTN_CALC, OnBtnCalc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJsgaDlg message handlers
BOOL CJsgaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CComboBox *pcomb = (CComboBox *)GetDlgItem(IDC_CMB_PARAGROUP);
for(int i = 0; i < 5; i++)
{
CString strTemp;
strTemp.Format("%d:%d参数组",i,i);
pcomb->AddString(strTemp);
}
pcomb->SetCurSel(0);
gasp.LoadPara(1);
ShowPara();
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 CJsgaDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CJsgaDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJsgaDlg::OnBtnApp()
{
// TODO: Add your control notification handler code here
}
BOOL CJsgaDlg::ShowPara()
{
CString strTemp;
CEdit *pEdit = (CEdit *)GetDlgItem(IDC_EDT_POPSIZE);
strTemp.Format("%d",gasp.popsize);
pEdit->SetWindowText(strTemp);
pEdit = (CEdit *)GetDlgItem(IDC_EDT_CALGENNUM);
strTemp.Format("%d",gasp.calgennum);
pEdit->SetWindowText(strTemp);
pEdit = (CEdit *)GetDlgItem(IDC_EDT_PC);
strTemp.Format("%f",gasp.pc);
pEdit->SetWindowText(strTemp);
pEdit = (CEdit *)GetDlgItem(IDC_EDT_PM);
strTemp.Format("%f",gasp.pm);
pEdit->SetWindowText(strTemp);
pEdit = (CEdit *)GetDlgItem(IDC_EDT_GENENUM);
strTemp.Format("%d",gasp.genenum);
pEdit->SetWindowText(strTemp);
pEdit = (CEdit *)GetDlgItem(IDC_EDT_CHROMNUM);
strTemp.Format("%d",gasp.chromnum);
pEdit->SetWindowText(strTemp);
UpdateData(FALSE);
return TRUE;
}
void CJsgaDlg::OnSelchangeCmbParagroup()
{
// TODO: Add your control notification handler code here
CComboBox *pcomb = (CComboBox *)GetDlgItem(IDC_CMB_PARAGROUP);
int nTemp = pcomb->GetCurSel();
gasp.LoadPara(nTemp + 1);
ShowPara();
}
void CJsgaDlg::OnBtnCalc()
{
// TODO: Add your control notification handler code here
SGA sgaExample;
CButton *btn = (CButton *) GetDlgItem(IDC_BTN_CALC);
btn->EnableWindow(FALSE);
sgaExample.InitPops();
int ngen = 0;
while(ngen < gasp.calgennum)
{
ngen++;
sgaExample.Select();
sgaExample.Crsover();
sgaExample.Mutate();
}
btn->EnableWindow(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -