www.pudn.com > KSP.rar > MainP.cpp


#pragma warning(disable: 4786) 
#include  
 
#include "QYKShortestPaths.h" 
#include 
#include "city.h" 
 
using namespace std; 
using namespace asu_emit_qyan; 
 
struct indexterm 
{ 
	string key; 
	int low,high; 
}; 
 
struct indexterm index[26];//以二十六个字母为索引 
int search(string temp,string *city,indexterm *index,string whole_name) 
//temp地名首字母,*city为地名数组,*index是索引表,whole_name是城市的全名 
{ 
	  for(int i=index[*temp.c_str()-97].low;i<=index[*temp.c_str()-97].high;i++) 
	  { 
		  if(city[i]==whole_name)//如果找到,返回在数组中的位置 
		  return i; 
	  } 
	  return -1;//如果找不到 
} 
 
int main(int argc, char* argv[]) 
{ 
	string start_city,end_city,temp_start,temp_end; 
	cout<<"Input your start city:"; 
	cin>>start_city; 
	cout<<"Input your destination:"; 
	cin>>end_city; 
	temp_start=start_city.substr(0,1); //取第一个字符串,准备分块查找 
	temp_end=end_city.substr(0,1); 
 
	//初始化索引表 
	index[0].key='a'; 
	index[0].low=0; 
	index[0].high=2; 
	char str='b'; 
	for(int n=1;n<26;n++) 
	{ 
		index[n].key=str; 
		index[n].low=index[n-1].high+1; 
		index[n].high=index[n-1].high+3; 
		str++; 
	} 
	index[1].high=4; 
	index[2].low =5; 
	index[25].high=79; 
 
	//------------- 
	int start_position,end_position;//查找起始和终点城市的编号 
	start_position=search(temp_start,city,index,start_city);  
	//start_position为城市在数组中的下标,city为地名数组 
	end_position=search(temp_end,city,index,end_city); 
	//cout<<"Start:"<>k; 
	cout< topK_shortest_paths = ksp.GetTopKShortestPaths(); 
	int cont=0; 
 
	for (vector::iterator pos=topK_shortest_paths.begin(); pos!=topK_shortest_paths.end(); ++pos) 
	{ 
		cout<<++cont<PrintOut(cout); 
		cout  << endl; 
	} 
 
//   	for_each (topK_shortest_paths.begin(), topK_shortest_paths.end(),  
//   		bind2nd(mem_fun(&CQYDirectedPath::PrintOut), cout)); 
	system   ("PAUSE"); 
}