?? compare_first.cpp
字號(hào):
// Compare.cpp : 實(shí)現(xiàn)文件
//
#include "stdafx.h"
#include "AI.h"
#include "Compare_first.h"
#include <cmath>
#include ".\Compare_first.h"
// CCompare_first 對(duì)話框
IMPLEMENT_DYNAMIC(CCompare_first, CDialog)
CCompare_first::CCompare_first(CWnd* pParent /*=NULL*/)
: CDialog(CCompare_first::IDD, pParent)
{
comp[1].search = &dfs;
comp[2].search = &bdfs; //有界
comp[3].search = &bfs;
comp[4].search = &tbfs;
comp[5].search = &astar1; //啟發(fā)
comp[6].search = &astar2;
comp[7].search = &idfs;
comp[8].search = &ida;
for(int i = 1, j = IDC_STEP_1, m = IDC_NODE_1, k = IDC_KEY_1; i <= 8; ++i, ++j, ++m, ++k){
comp[i].step_item = j;
comp[i].node_item = m;
comp[i].key_item = k;
}
}
CCompare_first::~CCompare_first()
{
}
void CCompare_first::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CCompare_first, CDialog)
ON_BN_CLICKED(IDC_COMP_SEARCH, OnBnClickedCompSearch)
END_MESSAGE_MAP()
// CCompare_first 消息處理程序
//線程執(zhí)行函數(shù):
DWORD WINAPI CompSearchProc(LPVOID lpParameter){
CCompare_first *p = (CCompare_first *) lpParameter;
p->stop = 0;
//搜索、顯示
for(int i = 1; i <= 8 && !p->stop; ++i){
int ans;
if(i == 2)
ans = p->comp[i].search->search(p->m_begin, p->m_end, p->stop, p->m_maxstep);
else
ans = p->comp[i].search->search(p->m_begin, p->m_end, p->stop, p->m_heuristic);
if(ans == -1 ){
p->MessageBox("此圖無解!");
break;
}else if(ans == -2){
p->MessageBox("用戶終止搜索!");
break;
}else if(!ans){ //有解找不到解
p->SetDlgItemText(p->comp[i].step_item, "未得解");
p->SetDlgItemText(p->comp[i].node_item, "未得解");
p->SetDlgItemText(p->comp[i].key_item, "未得解");
}else{
p->SetDlgItemInt(p->comp[i].step_item, p->comp[i].search->getStep() );
p->SetDlgItemInt(p->comp[i].node_item, p->comp[i].search->getTotalnode() );
char s[10];
double B = p->comp[i].search->getB();
if(fabs(B - 1.0) < 1e-2)
sprintf(s, "難求解");
else
sprintf(s, "%.3lf", B );
p->SetDlgItemText(p->comp[i].key_item, s);
}
}
p->SetDlgItemText(IDC_COMP_SEARCH, "開始搜索");
return 0;
}
void CCompare_first::OnBnClickedCompSearch()
{
// TODO: 在此添加控件通知處理程序代碼
CString str;
if(GetDlgItemText(IDC_COMP_SEARCH, str), str == "停止搜索"){
stop = 1;
return;
}
SetDlgItemText(IDC_COMP_SEARCH, "停止搜索");
HANDLE hThread1 = CreateThread(NULL, 0, CompSearchProc, this, 0, NULL);
CloseHandle(hThread1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -