⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgvrptw.cpp

📁 一个求解车辆路径问题的粒子群算法的源码
💻 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 + -