亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? routing1.cpp

?? 實現最短路徑算法。 實現最短路徑算法。
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This file implement file of the routing program
//It concain functions declared in the roufun.h file
//Program designer:chaidengfeng
//Zhejiang University,Hangzhou,Zhejiang
//e_mail:chaidf@263.net
//Any question about the program can be asked by sending e_mail to chaidf@263.net
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "stdio.h"
#include "stdlib.h"
#include "memory.h"
#include "roufun.h"

DllExport bool routing_short(char *vexFile,char *topoFile,char *attrFile,double xSou,double ySou,double xDes,double yDes,PathsNode **pathDis,PathsNode **pathTim,int N)
{
	
	bool createFlag;
	VexNode *graph;

	graph = (VexNode *)malloc(sizeof(VexNode));
	if(graph == 0)
		return false;

   //	createFlag = graph_construct(vexFile,topoFile,attrFile,&graph);
	createFlag = create_test(&graph,vexFile,topoFile);
	if(!createFlag)
	{
		graph_destruct(graph);
		return false;
	}

        int souNo,desNo;
        bool shortFlag;
	souNo = get_vexNo(graph,xSou,ySou);
	desNo = get_vexNo(graph,xDes,yDes);
	if(souNo == NOVERTEX || desNo == NOVERTEX )
	{
		graph_destruct(graph);
		return false;
	}
        
	//DISTANCE
	shortFlag = graph_Dij_N(graph,souNo,desNo,DISTANCE,pathDis,N);
	//TIME
	shortFlag = graph_Dij_N(graph,souNo,desNo,TIME,pathTim,N);

	graph_destruct(graph);
	if(shortFlag)
		return true;
	else
		return false;
}
/////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////
bool graph_construct(char *vexFile,char *topoFile,char *attrFile,VexNode **graph)
{
	//file name is null
	if(!vexFile || !topoFile || !attrFile)
		return false;
	
	//open files
	FILE *vexFp,*topoFp,*attrFp;
	if(!(vexFp = fopen(vexFile,"r")))
		return false;
	if(!(topoFp = fopen(topoFile,"r")))
		return false;
	if(!(attrFp = fopen(attrFile,"r")))
		return false;
	
	//construct the graph
	if(!(Set_Vex(vexFp,graph)))
		return false;
	if(!(Set_Topo(topoFp,graph)))
		return false;
	if(!(Set_Attr(attrFp,graph)))
		return false;
	if(!(complement(graph)))
		return false;
	
	//close files
	if(vexFp)
		fclose(vexFp);
	if(topoFp)
		fclose(topoFp);
	if(attrFp)
		fclose(attrFp);

	return true;
}
/////////////////////////////////////////////////////////////////
//graph destroy function
/////////////////////////////////////////////////////////////////
DllExport bool graph_destruct(VexNode *graph)
{
	VexNode *currVex,*nextVex;
	ArcNode *currArc,*nextArc;
	currVex = graph;
	while(currVex)
	{
		nextVex = currVex->nextVex;
		currArc = currVex->firstArc;
		while(currArc)
		{
			nextArc = currArc->nextArc;
			free(currArc);
			currArc = nextArc;
		}
		free(currVex);
		currVex = nextVex;
	}
	return true;
}
/////////////////////////////////////////////////////////////////
//path destroy function
/////////////////////////////////////////////////////////////////
DllExport bool path_destruct(PathsNode *path)
{
	PathsNode *currPaths,*nextPaths;
	PathNode  *currPath ,*nextPath;
	currPaths = path;
	while(currPaths)
	{
		nextPaths = currPaths->next;
		currPath = currPaths->path;
		while(currPath)
		{
			nextPath = currPath->next;
			free(currPath);
			currPath = nextPath;
		}
		free(currPaths);
		currPaths = nextPaths;
	}
	return true;
}
/////////////////////////////////////////////////////////////////
//This is the function that find the nearest vertex to point(x,y)
/////////////////////////////////////////////////////////////////
DllExport int get_vexNo(VexNode *graph,double x,double y)
{
	double distance,minDis;
	double dx,dy;
	VexNode *currVex,*minVex;
	currVex = graph;
	if(currVex == 0)
		return NOVERTEX;
	dx = currVex->info.x - x;
	dy = currVex->info.y - y;
	minDis = dx*dx+dy*dy;
	minVex = currVex;
	currVex = currVex->nextVex;
	while(currVex)
	{
		dx = currVex->info.x - x;
		dy = currVex->info.y - y;
		distance = dx*dx+dy*dy;
		if(distance < minDis)
		{
			minDis = distance;
			minVex = currVex;
		}
		currVex = currVex->nextVex;
	}
	return minVex->vexNo;
}
///////////////////////////////////////////////////////////////
//N_shortest path find function
///////////////////////////////////////////////////////////////
DllExport bool graph_Dij_N(VexNode *graph,int souNo,int desNo,int kind,PathsNode **pathCost,int N)
{
	int i,j,k,kk;
	int short_count = 0;
	int headVexNo,tailVexNo;
	double tempCost[MAX_LENGTH],minCost;

	int cut_headNo[MAX_N][MAX_LENGTH],cut_temp_head[MAX_LENGTH];
	int cut_tailNo[MAX_N][MAX_LENGTH],cut_temp_tail[MAX_LENGTH];
	
	ArcNode *currArc;
	VexNode *currVex;
	PathsNode *currPaths,*nextPaths,*insertPaths;
	PathNode  *currPath, *nextPath ,*tempPath;

	///////////////////////////////////////////////
	//initialize
	///////////////////////////////////////////////
	for(i=0;i<MAX_N;i++)
	{
		for(j=0;j<MAX_LENGTH;j++)
		{
			cut_headNo[i][j] = NOVERTEX;
			cut_tailNo[i][j] = NOVERTEX;
		}
	}
	for(j=0;j<MAX_LENGTH;j++)
	{
		cut_temp_head[j] = NOVERTEX;
		cut_temp_tail[j] = NOVERTEX;
	}
	//get paths
	do{
		//get 1-shortest 
		if(short_count == 0)
		{
			tempPath = (PathNode*)malloc(sizeof(PathNode));
			if(tempPath == 0)
				return false;
			if(!(graph_Dij(graph,souNo,desNo,&minCost,kind,&tempPath)))
				return false;
			if(tempPath == 0)
			{
				*pathCost = 0;
				break;
			}
			insertPaths = (PathsNode*)malloc(sizeof(PathsNode));
			if(insertPaths == 0)
				return false;
			insertPaths->pathNo   = 1;
			if(kind == DISTANCE)
			{
				insertPaths->distance = minCost;
				insertPaths->time = 0;
			}
			else
			{
				insertPaths->distance = 0;
				insertPaths->time = minCost;
			}
			insertPaths->path     = tempPath;
			insertPaths->next     = 0;
			*pathCost = insertPaths;

		}
		//get 2 3 . . .-shortest 
		else
		{
			//get path;
			currPaths = *pathCost;
			while(currPaths && currPaths->pathNo != short_count)
				currPaths = currPaths->next;
			if(currPaths == 0)
				break;
			else
			{
				currPath = currPaths->path;
				while(currPath->next)
				{
					//record the head and tail vertex No.
					nextPath = currPath->next;
					headVexNo = currPath->vexNo;
					tailVexNo = nextPath->vexNo;
					int cut_count = 0;
					for(j=0;j<MAX_LENGTH;j++)
					{
						cut_count++;
						cut_temp_head[j] = cut_headNo[short_count-1][j];
						cut_temp_tail[j] = cut_tailNo[short_count-1][j];
						if(cut_temp_tail[j] == NOVERTEX)
						{
							//add to cut arc recorder
							cut_temp_head[j] = headVexNo;
							cut_temp_tail[j] = tailVexNo;
							break;
						}
					}
					//cut arcs recorded by the cut recorder
					for(j=0;j<cut_count;j++)
					{
						headVexNo = cut_temp_head[j];
						tailVexNo = cut_temp_tail[j] ;
						currVex = graph;
						while(currVex && currVex->vexNo != headVexNo)
							currVex = currVex->nextVex;
						currArc = currVex->firstArc;
						while(currArc && currArc->info.tailVexNo != tailVexNo)
							currArc = currArc->nextArc;
						if(currVex->vexNo == headVexNo && currArc->info.tailVexNo == tailVexNo)
						{
							if(kind == DISTANCE)
							{
								tempCost[j] = currArc->info.distance;
								currArc->info.distance = MAXCOST;
							}
							else if(kind == TIME)
							{
								tempCost[j] = currArc->info.time;
								currArc->info.time = MAXCOST;
							}
						}
					}
					//get shortest path in the state of arcs cutted
					tempPath = (PathNode*)malloc(sizeof(PathNode));
					if(tempPath == 0)
						return false;
					if(!(graph_Dij(graph,souNo,desNo,&minCost,kind,&tempPath)))
						return false;
					//come back to fore state
					for(j=0;j<cut_count;j++)
					{
						headVexNo = cut_temp_head[j];
						tailVexNo = cut_temp_tail[j] ;
						currVex = graph;
						while(currVex && currVex->vexNo != headVexNo)
							currVex = currVex->nextVex;
						currArc = currVex->firstArc;
						while(currArc && currArc->info.tailVexNo != tailVexNo)
							currArc = currArc->nextArc;
						if(currVex->vexNo == headVexNo && currArc->info.tailVexNo == tailVexNo)
						{
							if(kind == DISTANCE)
							{
								currArc->info.distance = tempCost[j];
								tempCost[j] = 0.0;
							}
							else if(kind == TIME)
							{
								currArc->info.time = tempCost[j];
								tempCost[j] = 0.0;
							}
						}
					}
					//compare and exchange
					if(tempPath != 0)
					{
						//continue;
						currPaths = *pathCost;
						if(kind == DISTANCE)
						{
							while(currPaths->next && currPaths->next->distance < minCost)
								currPaths = currPaths->next;
						}
						else if(kind == TIME)
						{
							while(currPaths->next && currPaths->next->time < minCost)
								currPaths = currPaths->next;
						}
						if(currPaths->pathNo < N)
						{
							nextPaths = currPaths->next;
							insertPaths = (PathsNode*)malloc(sizeof(PathsNode));
							if(insertPaths == 0)
								return false;
							insertPaths->pathNo   = currPaths->pathNo+1;
							if(kind == DISTANCE)
							{
								insertPaths->distance = minCost;
								insertPaths->time = 0;
							}
							else
							{
								insertPaths->distance = 0;
								insertPaths->time = minCost;
							}
							insertPaths->path     = tempPath;
							insertPaths->next     = nextPaths;
							currPaths->next = insertPaths;
							currPaths = nextPaths;
							while(currPaths)
							{
								currPaths->pathNo++;
								if(currPaths && currPaths->pathNo>N)
								{
									path_destruct(currPaths);
									break;
								}
								else
									currPaths = currPaths->next;
							}
							for(k = N-1;k >= insertPaths->pathNo;k--)
							{
								for(kk=0;kk<MAX_LENGTH;kk++)
								{
									cut_headNo[k][kk] = cut_headNo[k-1][kk];
									cut_tailNo[k][kk] = cut_tailNo[k-1][kk];
								}
							}
							for(kk=0;kk<MAX_LENGTH;kk++)
							{
								cut_headNo[insertPaths->pathNo-1][kk] = cut_temp_head[kk];
								cut_tailNo[insertPaths->pathNo-1][kk] = cut_temp_tail[kk];
							}
							break;
						}
					}
					currPath = nextPath;
				}
			}
		}
		short_count++;
	}while(short_count < N);
	return true;
}
/////////////////////////////////////////////////////////////////////
//construct graph
/////////////////////////////////////////////////////////////////////
bool Set_Vex(FILE *vexFp,VexNode **graph)
{
	int      vexNo,count;
	char     vexName[MAXNAME],desp[MAXDESCRIPTION];
	double   x,y;
	VexNode  *currVex,*nextVex;

	count = 0;
	nextVex = 0;
	while(!feof(vexFp))
	{
		memset(vexName,'\0',MAXNAME);
		if(fscanf(vexFp,"%d %s %lf %lf %s",&vexNo,vexName,&x,&y,desp) == 5)//扔掉一個變量
		{
			nextVex  = (VexNode *)malloc(sizeof(VexNode));
			if(nextVex == 0)
				return false;
			nextVex->vexNo  = vexNo;
			memcpy(nextVex->info.vexName,vexName,MAXNAME);
			nextVex->info.x = x;
			nextVex->info.y = y;
			nextVex->firstArc = 0;
			nextVex->nextVex = 0;
			if(count == 0)
			{
				*graph = nextVex;
				currVex = nextVex;
			}
			else
			{
				currVex->nextVex = nextVex;
				currVex = nextVex;
			}
			count++;
		}
		else
			return false;
	}
	return true;
}
//////////////////////////////////////////////////////////////////
//topo information 
//this function is really construct the graph
/////////////////////////////////////////////////////////////////
bool Set_Topo(FILE *topoFp,VexNode **graph)
{
	int      i;
	bool     addFlag;
	int      arcNo,souNo,desNo;
	char     arcName[MAXNAME];
	double   x1,y1,x2,y2;
	VexNode  *currVex;
	ArcNode  *currArc,*nextArc;
	currArc = 0;
	nextArc = 0;
	while(!feof(topoFp))
	{
		memset(arcName,'\0',MAXNAME);
		if(fscanf(topoFp,"%d %s %d %lf %lf %d %lf %lf",&arcNo,arcName,&souNo,&x1,&y1,&desNo,&x2,&y2) == 8)
		{
			currVex = *graph;
			while(currVex->vexNo != souNo && currVex->nextVex)
				currVex = currVex->nextVex;
			if(currVex->vexNo != souNo)
				return false;
			addFlag = false;
			currArc = currVex->firstArc;
			if(!currArc)
				addFlag = true;
			else
			{
				while(currArc->nextArc && currArc->arcNo != arcNo)
					currArc = currArc->nextArc;
				if(currArc->arcNo == arcNo)
				{
					currArc->arcNo   = arcNo;
					currArc->info.tailVexNo    = desNo;
					memcpy(currArc->info.arcName,arcName,MAXNAME);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品国精品自拍自在线| 亚洲一区在线观看视频| 久久精品视频免费| 欧美精品一区二区三区视频 | 亚洲高清免费观看| 亚洲自拍偷拍av| 亚洲成人综合在线| 婷婷六月综合亚洲| 日韩不卡一二三区| 久久99久久精品欧美| 青青草伊人久久| 久久超碰97人人做人人爱| 麻豆精品一区二区| 国产乱色国产精品免费视频| 国产成人av电影免费在线观看| 国产福利一区二区| 成人福利视频在线看| 97aⅴ精品视频一二三区| 色呦呦国产精品| 欧美日韩日日骚| 精品少妇一区二区三区在线播放 | 亚洲h精品动漫在线观看| 日韩国产一二三区| 久久国内精品自在自线400部| 国产一区二区91| 91在线播放网址| 欧美精品日韩综合在线| 2014亚洲片线观看视频免费| 中文字幕一区免费在线观看| 亚洲愉拍自拍另类高清精品| 日本麻豆一区二区三区视频| 国产精品 日产精品 欧美精品| 99re这里只有精品首页| 欧美日韩小视频| 国产亚洲视频系列| 一区二区三区.www| 激情文学综合丁香| 99视频精品在线| 欧美日韩情趣电影| 国产欧美日韩另类视频免费观看| 亚洲日本在线观看| 日本欧美大码aⅴ在线播放| 成人综合日日夜夜| 欧美日韩国产综合草草| 久久精品一区二区三区av| 亚洲精品中文字幕乱码三区| 蜜桃91丨九色丨蝌蚪91桃色| 波多野结衣亚洲| 欧美一区二区精品在线| 国产精品免费视频网站| 免费人成网站在线观看欧美高清| jlzzjlzz欧美大全| 欧美成人aa大片| 亚洲综合在线视频| 国产精品一二一区| 欧美另类高清zo欧美| 国产精品免费丝袜| 91蜜桃网址入口| 日韩精品在线看片z| 亚洲人一二三区| 国产白丝精品91爽爽久久| 91精品黄色片免费大全| 综合在线观看色| 国产激情偷乱视频一区二区三区| 欧美精品乱码久久久久久| 中文字幕制服丝袜成人av| 蜜臀av性久久久久蜜臀aⅴ流畅 | 日韩三级中文字幕| 一区二区三区在线高清| 国产成人免费xxxxxxxx| 91精品国产aⅴ一区二区| 亚洲蜜臀av乱码久久精品| 国产精品77777竹菊影视小说| 欧美一区二区三级| 亚洲午夜久久久久久久久久久| gogogo免费视频观看亚洲一| 亚洲精品在线一区二区| 日韩高清一区二区| 在线观看欧美日本| 亚洲蜜臀av乱码久久精品| 成人丝袜高跟foot| 久久美女高清视频| 精品一区二区在线免费观看| 欧美一二三四在线| 日韩精品乱码av一区二区| 欧美三区免费完整视频在线观看| 中文字幕综合网| 99国产精品国产精品久久| 国产精品乱码一区二三区小蝌蚪| 国产精品自拍一区| 精品99一区二区| 精品一区二区成人精品| 日韩天堂在线观看| 日本aⅴ亚洲精品中文乱码| 欧美精品久久久久久久多人混战 | 亚洲午夜久久久久久久久久久| 91免费看视频| 亚洲免费观看高清完整| 91在线丨porny丨国产| 一区在线观看视频| 不卡视频一二三| 亚洲天堂成人在线观看| 91蝌蚪porny九色| 亚洲激情在线激情| 欧美色图片你懂的| 亚洲高清免费一级二级三级| 欧美男生操女生| 青青草国产成人av片免费| 欧美一级xxx| 国产精品一区二区x88av| 久久综合中文字幕| 成人丝袜高跟foot| 日韩一区欧美一区| 在线视频国内自拍亚洲视频| 亚洲一区二区欧美激情| 欧美精品日韩综合在线| 久久精品噜噜噜成人88aⅴ| 久久综合给合久久狠狠狠97色69| 国产不卡免费视频| 亚洲色图欧美激情| 欧美日韩综合在线| 男人的天堂久久精品| 久久久精品免费免费| 99久久精品久久久久久清纯| 亚洲激情综合网| 最新成人av在线| 欧美日韩免费高清一区色橹橹 | 色婷婷综合久色| 亚洲大片一区二区三区| 欧美电影免费观看高清完整版在 | 国产一区二区三区不卡在线观看 | 久久夜色精品国产噜噜av | 国产精品卡一卡二| 欧美亚洲高清一区二区三区不卡| 日韩成人免费在线| 欧美国产日韩在线观看| 色呦呦国产精品| 麻豆一区二区三| 中文字幕免费不卡在线| 欧美日韩亚洲综合一区 | 欧美精品一区在线观看| 91无套直看片红桃| 日韩电影一二三区| 国产精品久久99| 日韩一级免费一区| 成人久久18免费网站麻豆| 一片黄亚洲嫩模| 久久综合九色综合97婷婷女人| 在线视频你懂得一区| 国产一区二区影院| 亚洲一区二区四区蜜桃| 精品久久国产老人久久综合| 色综合天天综合给合国产| 丝袜亚洲精品中文字幕一区| 国产精品色婷婷| 91精品国产91综合久久蜜臀| 91在线观看免费视频| 久久99国产精品久久| 夜夜爽夜夜爽精品视频| 久久色在线观看| 欧美肥妇bbw| 色呦呦国产精品| 国产精品18久久久久久久久久久久 | 精品国一区二区三区| 日本久久电影网| 国产激情一区二区三区| 日韩国产欧美三级| 亚洲黄色片在线观看| 国产女人水真多18毛片18精品视频 | 丁香亚洲综合激情啪啪综合| 日韩av中文在线观看| 一区二区三区 在线观看视频| 国产女主播在线一区二区| 欧美xxxxxxxxx| 69堂成人精品免费视频| 91丝袜美女网| 成人av集中营| 国产福利视频一区二区三区| 美女网站色91| 视频一区中文字幕国产| 一区二区三区日本| 中文字幕一区二区三区色视频| 国产亚洲一区二区三区| 欧美va在线播放| 欧美精品自拍偷拍动漫精品| 欧美亚洲一区二区在线观看| eeuss国产一区二区三区| 91视频观看视频| 成人免费视频视频在线观看免费| 国产麻豆精品视频| 国内精品伊人久久久久影院对白| 男女男精品网站| 热久久一区二区| 秋霞av亚洲一区二区三| 天堂一区二区在线免费观看| 一区二区三区精品久久久| 亚洲免费观看高清| 亚洲欧美电影一区二区| 亚洲人妖av一区二区| 亚洲欧洲制服丝袜|