tspview.cpp
来自「使用蚁群算法解决旅行商问题」· C++ 代码 · 共 130 行
CPP
130 行
// TspView.cpp : implementation of the CTspView class
//
#include "stdafx.h"
#include "Tsp.h"
#include "TspDoc.h"
#include "TspView.h"
#include "MyTsp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern int besttour[iCityCount];
/////////////////////////////////////////////////////////////////////////////
// CTspView
project AntTsp;
IMPLEMENT_DYNCREATE(CTspView, CView)
BEGIN_MESSAGE_MAP(CTspView, CView)
//{{AFX_MSG_MAP(CTspView)
ON_COMMAND(IDM_ANTTSP, OnAnttsp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTspView construction/destruction
CTspView::CTspView()
{
// TODO: add construction code here
}
CTspView::~CTspView()
{
}
BOOL CTspView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTspView drawing
void CTspView::OnDraw(CDC* pDC)
{
CTspDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int i;
POINT temp;
CString strNumber;
if(besttour[0]==0&&besttour[1]==0)
{
pDC->TextOut(480,30,"city ");
for(i=0; i<iCityCount; i++)
{
temp.x = 10*AntTsp.cc[i].x+200;
temp.y = 7*AntTsp.cc[i].y+80;
pDC->SetPixel(temp,RGB(0,0,255));
strNumber.Format("%d",AntTsp.cc[i].num);
pDC->TextOut(temp.x-15,temp.y-18,strNumber);
}
}
else
{
pDC->TextOut(480,30,"result");
for(i=0; i<iCityCount-1; i++)
{
temp.x = 10*AntTsp.cc[besttour[i]].x+200;
temp.y = 7*AntTsp.cc[besttour[i]].y+80;
pDC->MoveTo(temp);
temp.x = 10*AntTsp.cc[besttour[i+1]].x+200;
temp.y = 7*AntTsp.cc[besttour[i+1]].y+80;
pDC->LineTo(temp);
strNumber.Format("%d",AntTsp.cc[besttour[i]].num);
pDC->TextOut(temp.x,temp.y,strNumber);
}
strNumber.Format("%d",AntTsp.cc[besttour[iCityCount-1]].num);
pDC->TextOut(temp.x,temp.y,strNumber);
strNumber.Format("E");
pDC->TextOut(10*AntTsp.cc[besttour[iCityCount-1]].x+200-5,7*AntTsp.cc[besttour[iCityCount-1]].y+80+5,strNumber);
strNumber.Format("S");
pDC->TextOut(10*AntTsp.cc[besttour[0]].x+200-5,7*AntTsp.cc[besttour[0]].y+80+5,strNumber);
}
}
/////////////////////////////////////////////////////////////////////////////
// CTspView diagnostics
#ifdef _DEBUG
void CTspView::AssertValid() const
{
CView::AssertValid();
}
void CTspView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTspDoc* CTspView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTspDoc)));
return (CTspDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTspView message handlers
void CTspView::OnAnttsp()
{
// TODO: Add your command handler code here
AntTsp.GetAnt();
AntTsp.StartSearch();
Invalidate();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?