📄 mygaview.cpp
字号:
m_iSubpop2=dlg.m_iSubpop2<CPopulation::MaxOptimaNum?dlg.m_iSubpop2:0;
m_iSubpop3=dlg.m_iSubpop3<CPopulation::MaxOptimaNum?dlg.m_iSubpop3:0;
}
if(gGAParam.iSSW==2)OnCalStart();
}
/////////////////////////////////////////////////////////////////////////////
// CDisplayDlg dialog
CDisplayDlg::CDisplayDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDisplayDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDisplayDlg)
m_iResultInterval = 100;
m_bAutoScroll = FALSE;
m_bAllOptimaFitness = FALSE;
m_bAllOptimaGene = FALSE;
m_bAllSubpopFitness = FALSE;
m_bAllSubpopGene = FALSE;
m_bSubpop1 = FALSE;
m_bSubpop2 = FALSE;
m_bSubpop3 = FALSE;
m_iSubpop3 = 0;
m_iSubpop1 = 0;
m_iSubpop2 = 0;
m_bLowSpeed = FALSE;
m_lBreakPos = 1000000;
//}}AFX_DATA_INIT
}
void CDisplayDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDisplayDlg)
DDX_Text(pDX, IDC_EDIT1, m_iResultInterval);
DDV_MinMaxInt(pDX, m_iResultInterval, 1, 2147483647);
DDX_Check(pDX, IDC_CHECK3, m_bAutoScroll);
DDX_Check(pDX, IDC_CHECK1, m_bAllOptimaFitness);
DDX_Check(pDX, IDC_CHECK4, m_bAllOptimaGene);
DDX_Check(pDX, IDC_CHECK5, m_bAllSubpopFitness);
DDX_Check(pDX, IDC_CHECK6, m_bAllSubpopGene);
DDX_Check(pDX, IDC_CHECK7, m_bSubpop1);
DDX_Check(pDX, IDC_CHECK8, m_bSubpop2);
DDX_Check(pDX, IDC_CHECK9, m_bSubpop3);
DDX_Text(pDX, IDC_EDIT16, m_iSubpop3);
DDX_Text(pDX, IDC_EDIT2, m_iSubpop1);
DDX_Text(pDX, IDC_EDIT7, m_iSubpop2);
DDX_Check(pDX, IDC_CHECK10, m_bLowSpeed);
DDX_Text(pDX, IDC_EDIT3, m_lBreakPos);
DDV_MinMaxLong(pDX, m_lBreakPos, 0, 2147483647);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDisplayDlg, CDialog)
//{{AFX_MSG_MAP(CDisplayDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDisplayDlg message handlers
void CFunSelDlg::OnSelchange()
{
// TODO: Add your control notification handler code here
/* static CString str[]={
"LeungF7=99.61630365(n=100),[0,3.14],",
"LeungF6=0,[-50,50],",
"SchafferF6=0,[-100,100],n=2 fixed",
"Schaffer F7=0,[-100,100],n=2 fixed",
"Shubert function,[-10,10],n=2 fixed",
"WxzFun1",
"Back Step Function1 modified by wxz",
"De Jong F2 [-2.048,2.048]",
"De Jong F3 [-5.12,5.12]",
"De Jong F4 [-1.28,1.28]",
"Multi-goal [-2,2]",
"Empty",
"Ackley Function=0 [-20,30]",
"Zhanglin1 [0,1]",
"Zhanglin2 [0,1]",
"Rosenbrock=0, [-5.12,5.12]",
"Rastrigin",
"Gauss [-5.12,5.12]",
"wxz, [-5.12,5.12]",
"Goldstein_Price, [-2,2],Min=3",
"Branin_RCOS,x1:[-5,10],x2:[0,15],Min=0.397887",
"Bohachevsky F3[-50,50]",
"Coliville [-10,10],Min=0",
"SolveEquation1(px); //by wxz,[-Pi,Pi]",
"SolveEquation2(px); //by wxz,[-Pi,Pi]",
"ThemoPowerPlant(px);",
"FletchPowellFun(px)",
"LiPengFun(px); //x[1]>-3,x[2]<3",
"Empty",
"SchwefelFun(px),[-512,511]",
"LeungF2(px),[-5.12,5.12]",
"LeungF4(px),[-600,600]",
"LeungF5(px),[-50,50]",
"LeungF9(Gene-1),[-5,5]",
"LeungF13(px),[-10,10]",
"LeungF14,[-100,100]"
"LeungF15,[-100,100]",
"A Simple Example1,[-1,2]"
}
CComboBox *pComBox=(pComBox*)GetDlgItem(IDC_COMBO3);
int sel=pComBox->GetCurSel();
CEditBox
*/
}
void CMyGAView::OnClrResult()
{
// TODO: Add your command handler code here
if(AfxMessageBox(_T("是否确认清除显示内容?"),MB_YESNO|MB_ICONQUESTION)==IDYES)
{
m_strList.RemoveAll();
ScrollToPosition(CPoint(0,0));
Invalidate();
}
}
/////////////////////////////////////////////////////////////////////////////
// CSubpopSetDlg dialog
CSubpopSetDlg::CSubpopSetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSubpopSetDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSubpopSetDlg)
m_Gap = 0;
m_NoEvolveGen = 0;
m_MaxGen = 0;
m_SigmaCoe = 0.0;
m_MinSigma = 0.0;
m_Lumda = 0;
m_Kap = 0;
m_Mu = 0;
m_Sigma0 = 0.0;
//}}AFX_DATA_INIT
}
void CSubpopSetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSubpopSetDlg)
DDX_Text(pDX, IDC_EDIT10, m_Gap);
DDV_MinMaxLong(pDX, m_Gap, 1, 2147483647);
DDX_Text(pDX, IDC_EDIT11, m_NoEvolveGen);
DDV_MinMaxLong(pDX, m_NoEvolveGen, 1, 2147483647);
DDX_Text(pDX, IDC_EDIT12, m_MaxGen);
DDV_MinMaxLong(pDX, m_MaxGen, 1, 2147483647);
DDX_Text(pDX, IDC_EDIT15, m_SigmaCoe);
DDV_MinMaxDouble(pDX, m_SigmaCoe, 0., 10.);
DDX_Text(pDX, IDC_EDIT4, m_MinSigma);
DDV_MinMaxDouble(pDX, m_MinSigma, 0., 10.);
DDX_Text(pDX, IDC_EDIT5, m_Lumda);
DDV_MinMaxInt(pDX, m_Lumda, 0, 2147483647);
DDX_Text(pDX, IDC_EDIT9, m_Kap);
DDV_MinMaxInt(pDX, m_Kap, 0, 2147483647);
DDX_Text(pDX, IDC_EDIT1, m_Mu);
DDX_Text(pDX, IDC_EDIT17, m_Sigma0);
DDV_MinMaxDouble(pDX, m_Sigma0, 0., 100000.);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSubpopSetDlg, CDialog)
//{{AFX_MSG_MAP(CSubpopSetDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSubpopSetDlg message handlers
/*
double xx1,xx=0;
long int ii;
srand((unsigned)time(NULL));
again:xx=0;
for(ii=0;ii<1000000L;ii++)
{
xx1=GaussX(0,1);
xx+=xx1;
}
CString strx;
strx.Format("%lf",xx/ii);
if(AfxMessageBox(strx,MB_YESNO)==IDYES)goto again;
*/
/////////////////////////////////////////////////////////////////////////////
// CFunCalDlg dialog
CFunCalDlg::CFunCalDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFunCalDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFunCalDlg)
m_x1 = 0.0;
m_x2 = 0.0;
m_x3 = 0.0;
m_x4 = 0.0;
m_result = 0.0;
//}}AFX_DATA_INIT
}
void CFunCalDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFunCalDlg)
DDX_Text(pDX, IDC_EDIT1, m_x1);
DDX_Text(pDX, IDC_EDIT3, m_x2);
DDX_Text(pDX, IDC_EDIT9, m_x3);
DDX_Text(pDX, IDC_EDIT18, m_x4);
DDX_Text(pDX, IDC_EDIT4, m_result);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFunCalDlg, CDialog)
//{{AFX_MSG_MAP(CFunCalDlg)
ON_BN_CLICKED(IDC_FUNCAL, OnFuncal)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFunCalDlg message handlers
void CFunCalDlg::OnFuncal()
{
// TODO: Add your control notification handler code here
CIndividual ind;
UpdateData(true);
ind.Gene[0]=m_x1;ind.Gene[1]=m_x2;ind.Gene[2]=m_x3;
ind.Gene[3]=m_x4;
m_result=ind.Evaluate();
UpdateData(false);
}
void CMyGAView::OnFuncal()
{
// TODO: Add your command handler code here
CFunCalDlg dlg;
dlg.m_x1=dlg.m_x2=dlg.m_x3=dlg.m_x4=0;
dlg.m_result=0;
dlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// GAParaShowDlg dialog
CParaShowDlg::CParaShowDlg(CWnd* pParent /*=NULL*/)
: CDialog(CParaShowDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(GAParaShowDlg)
m_strPara = _T("");
//}}AFX_DATA_INIT
}
void CParaShowDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(GAParaShowDlg)
DDX_Text(pDX, IDC_EDIT1, m_strPara);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParaShowDlg, CDialog)
//{{AFX_MSG_MAP(GAParaShowDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GAParaShowDlg message handlers
void CMyGAView::OnParaShow()
{
// TODO: Add your command handler code here
CParaShowDlg dlg;
dlg.m_strPara=m_strSetup;
dlg.DoModal();
}
void CMyGAView::OnMCStart()
{
// TODO: Add your command handler code here
if(gGAParam.iSSW==4)
{
gGAParam.iSSW=3;
m_pMonteCarlo->ResumeThread();
return;
}
CString str;
CTime t;
t=CTime::GetCurrentTime();
str=t.Format("%Y.%m.%d, %H:%M:%S");
m_strResult.Empty();
m_strResult.Format("%s 函数%03d,%3d个变量,第%ld代,适应值为:%11.5lf σ=%13.8lf ",
str,gGAParam.iFunSel,gGAParam.iVarNum,lGeneration,g_pPop->Ind[0].Fitness,
g_pPop->Sigma);
m_strList.AddTail(m_strResult);
// iCount=m_strList.GetCount()-1;
if(gGAParam.bMonteCarloSave)
{
str.Format("Fun%02dMC.txt",gGAParam.iFunSel);
if((m_pMCFile=fopen(str,"a"))==NULL)m_pMCFile=fopen(str,"w");
fprintf(m_pMCFile,"\n\n%s\n",m_strResult);
}
m_pMonteCarlo=AfxBeginThread(MonteCarloCal,(LPVOID)&gGAParam,THREAD_PRIORITY_NORMAL,0,0);
m_pMonteCarlo->m_bAutoDelete=true;
gGAParam.iSSW=3;
}
void CMyGAView::OnMCPause()
{
// TODO: Add your command handler code here
m_pMonteCarlo->SuspendThread();
gGAParam.iSSW=4;
}
void CMyGAView::OnMCStop()
{
// TODO: Add your command handler code here
if(AfxMessageBox(_T("确实要终止Monte Carlo计算吗?"),MB_YESNO|MB_ICONQUESTION)==IDYES)
{
if(gGAParam.iSSW>=3)m_pMonteCarlo->ResumeThread();
if(m_pMCFile)fclose(m_pMCFile);
gGAParam.iSSW=2;
}
}
void CMyGAView::OnUpdateMCStart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(gGAParam.iSSW==2||gGAParam.iSSW==4);
}
void CMyGAView::OnUpdateMCStop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(gGAParam.iSSW==3||gGAParam.iSSW==4);
}
void CMyGAView::OnUpdateMCPause(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(gGAParam.iSSW==3);
}
long CMyGAView::OnMCResult(WPARAM wParam,LPARAM lParam)
{
CString str;
int i;
int iCount;
CPoint point;
if(m_strList.GetCount()>=m_iLine)
{
for(i=m_iLine/4;i>0;i--)m_strList.RemoveHead();
point.x=0;
point.y=(int)(m_strList.GetCount()/m_iPageLine)*m_iPageLine*m_iLineHeight;
ScrollToPosition(point);
}
CClientDC dc(this);
OnPrepareDC(&dc); //!!否则,以下将使用DP坐标
if(m_bAutoScroll)
{
point.x=0;
point.y=(int)(m_strList.GetCount()/m_iPageLine)*m_iPageLine*m_iLineHeight;
ScrollToPosition(point);
}
MCRESULT *pmc=(MCRESULT *)wParam;
m_strResult.Empty();
m_strResult.Format("%ld %10.5lf(%10.5lf) %ld %10.5lf(%10.5lf) %ld %10.5lf(%10.5lf) %ld %10.5lf(%10.5lf) %13.10lf ",
pmc->pl[0],pmc->pd[0],pmc->pav[0],pmc->pl[1],pmc->pd[1],pmc->pav[1],
pmc->pl[2],pmc->pd[2],pmc->pav[2],
pmc->pl[3],pmc->pd[3],pmc->pav[3],pmc->Sigma);
m_strList.AddTail(m_strResult);
m_pStatus->SetPaneText(0,m_strResult);
iCount=m_strList.GetCount()-1;
int irgb=iCount%2;
dc.SetTextColor(RGB(irgb*255,!irgb*255,0));
dc.TextOut(0,iCount*m_iLineHeight,m_strResult);
if(gGAParam.bMonteCarloSave&&m_pMCFile)
fprintf(m_pMCFile,"%s\n",m_strResult);
gGAParam.bResultNotProcessed=FALSE;
return 0L;
}
long CMyGAView::OnMCFinished(WPARAM wParam,LPARAM lParam)
{
gGAParam.iSSW=2;
if(m_pMCFile)fclose(m_pMCFile);
gGAParam.bResultNotProcessed=FALSE;
return 0L;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -