📄 yytspview.cpp
字号:
// YYTSPView.cpp : implementation of the CYYTSPView class
//
#include "stdafx.h"
#include "YYTSP.h"
#include "TSP.h"
#include "YYTSPDoc.h"
#include "YYTSPView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CYYTSPView
IMPLEMENT_DYNCREATE(CYYTSPView, CView)
BEGIN_MESSAGE_MAP(CYYTSPView, CView)
//{{AFX_MSG_MAP(CYYTSPView)
ON_COMMAND(ID_TSP, OnTsp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYYTSPView construction/destruction
CYYTSPView::CYYTSPView()
{
// TODO: add construction code here
}
CYYTSPView::~CYYTSPView()
{
}
BOOL CYYTSPView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CYYTSPView drawing
void CYYTSPView::OnDraw(CDC* pDC)
{
CYYTSPDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CYYTSPView diagnostics
#ifdef _DEBUG
void CYYTSPView::AssertValid() const
{
CView::AssertValid();
}
void CYYTSPView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CYYTSPDoc* CYYTSPView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CYYTSPDoc)));
return (CYYTSPDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CYYTSPView message handlers
void CYYTSPView::OnTsp()
{
// TODO: Add your command handler code here
tspInstance = new TSP();
//tspInstance->initial();
//tspInstance->distance();
for(int i=0;i<20;i++)
{
tspInstance->train(300);
tspInstance->printV();
if(i==0)
{
tspInstance->Emin=tspInstance->e;
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
tspInstance->_v[j][k]=tspInstance->v[j][k];
}
else
{
if(tspInstance->e<tspInstance->Emin)
{
tspInstance->Emin=tspInstance->e;
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
tspInstance->_v[j][k]=tspInstance->v[j][k];
}
}
}
drawTSP();
}
void CYYTSPView::drawTSP()
{
int first_city,current_city,next_city;
int i,j;
CBrush brush1(RGB(50,50,200));
CBrush brush2(RGB(100,100,200));
//CPen p1(PS_SOLID,1,(150,150,150));
CClientDC dc(this);
dc.TextOut(200,380,"较佳路径");
dc.TextOut(200,400,"姓名:杨晔,20074228068044 ");
dc.MoveTo(50,350);
dc.LineTo(50,50);
dc.TextOut(50,40,"坐标Y");
dc.MoveTo(50,350);
dc.LineTo(350,350);
dc.TextOut(350,350,"坐标X");
for(i=0;i<N;i++)
{
dc.SelectObject(&brush1);
//dc.SelectObject(&p1);
dc.TextOut((int)(tspInstance->X[i]*300+50),(int)(350-tspInstance->Y[i]*300+20),"城市");
dc.Ellipse((int)(tspInstance->X[i]*300+50)-3,(int)(350-tspInstance->Y[i]*300)-3,
(int)(tspInstance->X[i]*300+50)+3,(int)(350-tspInstance->Y[i]*300)+3);
}
for(i=0 ;i<10;i++)
if(tspInstance->_v[i][0]==1)
first_city=current_city=i;
dc.SelectObject(&brush2);
for(j=1 ;j<10 ;j++)
for(i=0;i<10;i++)
{
if(tspInstance->_v[i][j]==1)
{
next_city=i;
dc.MoveTo((int)(tspInstance->X[current_city]*300+50),(int)(350-tspInstance->Y[current_city]*300));
dc.LineTo((int)(tspInstance->X[next_city]*300+50),(int)(350-tspInstance->Y[next_city]*300));
current_city = next_city;
break;
}
}
dc.MoveTo((int)(tspInstance->X[current_city]*300+50),(int)(350-tspInstance->Y[current_city]*300));
dc.LineTo((int)(tspInstance->X[first_city]*300+50),(int)(350-tspInstance->Y[first_city]*300));
//Invalidate(FALSE);
//GetDocument()->UpdateAllViews(this);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -