?? dlgvrptw.cpp
字號:
// DlgVrptw.cpp : implementation file
//
#include "stdafx.h"
#include "VRP.h"
#include "PsoVrptw.h"
#include "DlgVrptw.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgVrptw dialog
CDlgVrptw::CDlgVrptw(CWnd* pParent /*=NULL*/)
: CDialog(CDlgVrptw::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgVrptw)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgVrptw::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgVrptw)
DDX_Control(pDX, IDC_LIST1, m_ResultList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgVrptw, CDialog)
//{{AFX_MSG_MAP(CDlgVrptw)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgVrptw message handlers
void CDlgVrptw::OnOK()
{
// TODO: Add extra validation here
char* pszFileName1 = "Vrptw1.dat";
char* pszFileName2 = "Vrptw2.dat";
CFile myFile;
CFileException fileException;
char szBuffer[1024];
int nActual;
int i,data,pos,base;
double data1;
int index,x,y;
double weight,time_p,start_time,end_time;
double data_Vrp,Alll_data,min_data;
DWORD dwStart, dwStop, dwLast,All_time;
char xu[12]="20";
LVITEM lvi;
int nNumofCount;
CPsoVrptw Vrp;
if ( !myFile.Open(pszFileName1,CFile::modeRead), &fileException )
{
TRACE( "Can't open file %s, error = %u\n", pszFileName1, fileException.m_cause );
}
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read(szBuffer, sizeof(szBuffer));
myFile.Close();
pos=0;
for(i=1;i<=TASKTW;i++)
{
data=0;
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0'){
data=data*10+szBuffer[pos]-'0';
pos++;
}
//讀取整數序號
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
index=data;
data=0;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0'){
data=data*10+szBuffer[pos]-'0';
pos++;
}
x=data;
data1=0;
//跳開間隔符
if(szBuffer[pos]=='.')
{
base=1;
pos++;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0')
{
data1=data1*10+szBuffer[pos]-'0';
pos++;
base=base*10;
}
data1=(double)data1/base;
}
weight=data+data1;
//讀取貨運量
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
data=0;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0'){
data=data*10+szBuffer[pos]-'0';
pos++;
}
//跳開間隔符
y=data;
data1=0;
//跳開間隔符
if(szBuffer[pos]=='.')
{
base=1;
pos++;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0')
{
data1=data1*10+szBuffer[pos]-'0';
pos++;
base=base*10;
}
data1=(double)data1/base;
}
time_p=data+data1;
//讀取貨運量
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
data=0;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0'){
data=data*10+szBuffer[pos]-'0';
pos++;
}
//讀取整數序號
//while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
data1=0;
//跳開間隔符
if(szBuffer[pos]=='.')
{
base=1;
pos++;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0')
{
data1=data1*10+szBuffer[pos]-'0';
pos++;
base=base*10;
}
data1=(double)data1/base;
}
start_time=data+data1;
//讀取開始時間
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
data=0;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0'){
data=data*10+szBuffer[pos]-'0';
pos++;
}
//讀取整數序號
data1=0;
//跳開間隔符
if(szBuffer[pos]=='.')
{
base=1;
pos++;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0')
{
data1=data1*10+szBuffer[pos]-'0';
pos++;
base=base*10;
}
data1=(double)data1/base;
}
end_time=data+data1;
//讀取開始時間
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
Vrp.GPNode.index[i]=index;
Vrp.GPNode.weight[i]=weight;
Vrp.GPNode.time[i]=time_p;
Vrp.GPNode.start_time[i]=start_time;
Vrp.GPNode.end_time[i]=end_time;
}
//讀取dat1的文件
if ( !myFile.Open(pszFileName2,CFile::modeRead), &fileException )
{
TRACE( "Can't open file %s, error = %u\n", pszFileName2, fileException.m_cause );
}
myFile.Seek( 0, CFile::begin );
nActual = myFile.Read(szBuffer, sizeof(szBuffer));
myFile.Close();
pos=0;
for(i=0;i<=TASKTW;i++)
for(int j=0;j<=TASKTW;j++)
{
data=0;
while(szBuffer[pos]<='9'&&szBuffer[pos]>='0')
{
data=data*10+szBuffer[pos]-'0';
pos++;
}
//讀取整數序號
while(szBuffer[pos]>'9'||szBuffer[pos]<'0')pos++;
//跳開間隔符
Vrp.dist_M[j][i]=data;
}
srand( (unsigned)time( NULL ) );
lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
int Step;
for(int Try=0;Try<MAXTRY;Try++)
{
dwStart = GetTickCount();
data_Vrp=Vrp.Vrp_Pso(&Step);
dwStop = GetTickCount();
dwLast = dwStop - dwStart;
//測試產生數據
All_time+=dwLast;
nNumofCount = m_ResultList.GetItemCount();
lvi.iItem = nNumofCount+1;
lvi.pszText = xu;
_itoa(nNumofCount,xu,10);
m_ResultList.InsertItem(nNumofCount,xu);
data=(int)data_Vrp;
_itoa(data,xu,10);
m_ResultList.SetItemText(nNumofCount,1, xu);
_ltoa(dwLast,xu,10);
m_ResultList.SetItemText(nNumofCount,2, xu);
_itoa(Step,xu,10);
m_ResultList.SetItemText(nNumofCount,3, xu);
}
}
BOOL CDlgVrptw::OnInitDialog()
{
CString strTemp[4] = {"序號","仿真結果", "完成時間","截止代數"};
int size[4] = {50,80,100,50};
int i;
CDialog::OnInitDialog();
for(i = 0; i < 4; i++)
{
m_ResultList.InsertColumn(i, strTemp[i],LVCFMT_LEFT,size[i]);
}
m_ResultList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);
m_ResultList.DeleteAllItems();
UpdateData(FALSE);
m_ResultList.Invalidate();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -