📄 mvsofgadlg.cpp
字号:
// MVSOFGADlg.cpp : implementation file
//
#include "stdafx.h"
#include "MVSOFGA.h"
#include "MVSOFGADlg.h"
#include "CMVSOGA.H"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMVSOFGADlg dialog
CMVSOFGADlg::CMVSOFGADlg(CWnd* pParent /*=NULL*/)
: CDialog(CMVSOFGADlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMVSOFGADlg)
m_csrate = 0.7;
m_mrate = 0.02;
m_popsize = 100;
m_result = 0.0;
m_x1 = 0.0;
m_x10 = 0.0;
m_x11 = 0.0;
m_x12 = 0.0;
m_x13 = 0.0;
m_x14 = 0.0;
m_x15 = 0.0;
m_x16 = 0.0;
m_x2 = 0.0;
m_x3 = 0.0;
m_x4 = 0.0;
m_x5 = 0.0;
m_x6 = 0.0;
m_x7 = 0.0;
m_x8 = 0.0;
m_x9 = 0.0;
m_generation = 50;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMVSOFGADlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMVSOFGADlg)
DDX_Text(pDX, IDC_CrossOver, m_csrate);
DDX_Text(pDX, IDC_Mutation, m_mrate);
DDX_Text(pDX, IDC_PopSize, m_popsize);
DDX_Text(pDX, IDC_Result, m_result);
DDX_Text(pDX, IDC_x1, m_x1);
DDX_Text(pDX, IDC_x10, m_x10);
DDX_Text(pDX, IDC_x11, m_x11);
DDX_Text(pDX, IDC_x12, m_x12);
DDX_Text(pDX, IDC_x13, m_x13);
DDX_Text(pDX, IDC_x14, m_x14);
DDX_Text(pDX, IDC_x15, m_x15);
DDX_Text(pDX, IDC_x16, m_x16);
DDX_Text(pDX, IDC_x2, m_x2);
DDX_Text(pDX, IDC_x3, m_x3);
DDX_Text(pDX, IDC_x4, m_x4);
DDX_Text(pDX, IDC_x5, m_x5);
DDX_Text(pDX, IDC_x6, m_x6);
DDX_Text(pDX, IDC_x7, m_x7);
DDX_Text(pDX, IDC_x8, m_x8);
DDX_Text(pDX, IDC_x9, m_x9);
DDX_Text(pDX, IDC_Gerneration, m_generation);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMVSOFGADlg, CDialog)
//{{AFX_MSG_MAP(CMVSOFGADlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_calNoGuass, OncalNoGuass)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMVSOFGADlg message handlers
BOOL CMVSOFGADlg::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
return TRUE; // return TRUE unless you set the focus to a control
}
void CMVSOFGADlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CMVSOFGADlg::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 CMVSOFGADlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMVSOFGADlg::OncalNoGuass()
{
// TODO: Add your control notification handler code here
UINT generation;
double topx[16], bottomx[16];
double resultx[17];
CMVSOGA cdata;
UpdateData(true);
m_result=0;
topx[0]=1.28;
topx[1]=1.28;
topx[2]=1.28;
topx[3]=1.28;
topx[4]=1.28;
topx[5]=1.28;
topx[6]=1.28;
topx[7]=1.28;
topx[8]=1.28;
topx[9]=1.28;
topx[10]=1.28;
topx[11]=1.28;
topx[12]=1.28;
topx[13]=1.28;
topx[14]=1.28;
topx[15]=1.28;
bottomx[0]=-1.28;
bottomx[1]=-1.28;
bottomx[2]=-1.28;
bottomx[3]=-1.28;
bottomx[4]=-1.28;
bottomx[5]=-1.28;
bottomx[6]=-1.28;
bottomx[7]=-1.28;
bottomx[8]=-1.28;
bottomx[9]=-1.28;
bottomx[10]=-1.28;
bottomx[11]=-1.28;
bottomx[12]=-1.28;
bottomx[13]=-1.28;
bottomx[14]=-1.28;
bottomx[15]=-1.28;
cdata.initialpopulation(m_popsize ,m_generation ,m_csrate ,m_mrate ,topx,bottomx);
cdata.evaluatepopulation();
for (generation=0;generation<m_generation;generation++ )
{
cdata.generatenextpopulation();
cdata.evaluatepopulation();
}
cdata.performevolution();
cdata.GetResult (resultx);
m_x1=resultx[0];
m_x2=resultx[1];
m_x3=resultx[2];
m_x4=resultx[3];
m_x5=resultx[4];
m_x6=resultx[5];
m_x7=resultx[6];
m_x8=resultx[7];
m_x9=resultx[8];
m_x10=resultx[9];
m_x11=resultx[10];
m_x12=resultx[11];
m_x13=resultx[12];
m_x14=resultx[13];
m_x15=resultx[14];
m_x16=resultx[15];
m_result=resultx[16];
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -