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

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

?? routing.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)
{
	int souNo,desNo;
	bool createFlag,shortFlag;
	VexNode *graph;
	graph = (VexNode *)malloc(sizeof(VexNode));
	if(graph == 0)
		return false;
	createFlag = graph_construct(vexFile,topoFile,attrFile,&graph);
	if(!createFlag)
	{
		graph_destruct(graph);
		return false;
	}
	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
/////////////////////////////////////////////////////////////////
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;
}
/////////////////////////////////////////////////////////////////
//graph destroy function
/////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////
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;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产成a人亚洲精| 亚洲影视在线播放| 亚洲制服丝袜在线| 国产一区二区不卡| 欧美日韩成人综合天天影院| 国产女人水真多18毛片18精品视频| 中文字幕日韩精品一区| 国产在线精品一区二区夜色| 欧美性猛交一区二区三区精品| 久久久影视传媒| 亚洲成人www| 91片在线免费观看| 国产亚洲精品7777| 久久99精品国产麻豆不卡| 欧美色图免费看| 亚洲三级久久久| 成人激情文学综合网| 精品少妇一区二区三区在线视频| 亚洲主播在线观看| 欧美午夜精品久久久久久孕妇| 国产精品高潮呻吟久久| 国产精品白丝av| 337p粉嫩大胆噜噜噜噜噜91av | 亚洲一区二区不卡免费| 成人性生交大合| 国产亚洲精品bt天堂精选| 极品美女销魂一区二区三区免费| 在线成人免费视频| 午夜精品在线视频一区| 欧美三电影在线| 亚洲成人在线免费| 欧美手机在线视频| 亚洲图片自拍偷拍| 精品视频一区 二区 三区| 亚洲香蕉伊在人在线观| 欧美亚男人的天堂| 香港成人在线视频| 欧美高清hd18日本| 美女精品一区二区| 精品国产网站在线观看| 狠狠色狠狠色综合系列| 久久久久国产精品麻豆ai换脸| 国产中文一区二区三区| 国产亚洲欧美日韩俺去了| 丁香啪啪综合成人亚洲小说| 国产精品亲子伦对白| 91色视频在线| 亚洲一卡二卡三卡四卡无卡久久| 欧美曰成人黄网| 日韩va亚洲va欧美va久久| 日韩欧美一区中文| 国产精品中文字幕日韩精品| 欧美国产激情二区三区| 色8久久精品久久久久久蜜| 亚洲成人黄色影院| 欧美日韩五月天| 黄色成人免费在线| 国产精品毛片久久久久久久| 欧美亚洲国产怡红院影院| 免费人成精品欧美精品| 国产性做久久久久久| 99麻豆久久久国产精品免费优播| 一区二区三区国产豹纹内裤在线 | 国产成人午夜精品影院观看视频| 日韩欧美国产综合在线一区二区三区| 极品少妇一区二区三区精品视频| 国产偷国产偷精品高清尤物 | 一本久久a久久免费精品不卡| 亚洲国产日韩a在线播放| 日韩精品一区二区三区三区免费| 韩国v欧美v亚洲v日本v| 一区二区三区精品在线| 欧美一级二级在线观看| 99久精品国产| 经典三级在线一区| 亚洲综合图片区| 久久久99久久| 欧美精选午夜久久久乱码6080| 国产v日产∨综合v精品视频| 午夜精品一区在线观看| 国产精品美女久久久久久久久久久 | 日本高清成人免费播放| 国精品**一区二区三区在线蜜桃| 亚洲免费观看视频| 久久精品亚洲国产奇米99| 欧美日韩不卡一区二区| 成人av在线影院| 精品一区二区三区视频| 亚洲国产精品久久不卡毛片| 国产欧美一区二区三区沐欲| 日韩一区二区不卡| 欧美日本在线一区| 国产精品资源在线| 黄色成人免费在线| 日本va欧美va精品| 亚洲成国产人片在线观看| 中文字幕一区二区视频| 久久久亚洲精品石原莉奈| 91精品在线麻豆| 91九色02白丝porn| 丁香激情综合国产| 国产中文一区二区三区| 蜜乳av一区二区| 视频一区欧美精品| 亚洲影院理伦片| 亚洲精品久久嫩草网站秘色| 欧美老女人第四色| 亚洲欧洲在线观看av| 精品乱码亚洲一区二区不卡| 欧亚一区二区三区| 91美女片黄在线观看91美女| 国产电影精品久久禁18| 国内精品久久久久影院色 | 亚洲精品欧美综合四区| 中文一区在线播放| 国产精品天美传媒| 国产精品网曝门| 中文字幕综合网| 亚洲免费观看在线视频| 亚洲精品福利视频网站| 亚洲一区国产视频| 午夜亚洲福利老司机| 婷婷丁香激情综合| 午夜视频在线观看一区| 日韩电影网1区2区| 精品中文字幕一区二区小辣椒| 麻豆久久久久久| 日韩有码一区二区三区| 日本aⅴ亚洲精品中文乱码| 另类人妖一区二区av| 韩国三级在线一区| 成人高清免费在线播放| 91国偷自产一区二区开放时间| 在线精品国精品国产尤物884a| 欧美日韩久久一区二区| 日韩精品中午字幕| 中文字幕欧美日韩一区| 亚洲综合色婷婷| 免费欧美高清视频| 99精品视频在线观看| 91久久精品网| 日韩你懂的在线播放| 中文字幕欧美国产| 亚洲一二三级电影| 国产专区欧美精品| 91精品福利视频| 精品国产凹凸成av人网站| 国产欧美日本一区视频| 亚洲大片在线观看| 国产中文一区二区三区| 色乱码一区二区三区88| 91精品啪在线观看国产60岁| 日韩电影在线观看电影| 日本中文字幕一区二区视频| 国产成人精品网址| 欧日韩精品视频| 国产亚洲一区二区三区四区| 亚洲国产色一区| 国产白丝网站精品污在线入口| 777欧美精品| 亚洲欧洲成人av每日更新| 蜜桃在线一区二区三区| 99视频超级精品| 久久精品视频网| 免费看欧美女人艹b| 色呦呦日韩精品| 国产午夜精品在线观看| 日本美女视频一区二区| 色婷婷精品大在线视频| 久久精品在线观看| 日韩精品一级中文字幕精品视频免费观看 | 色婷婷久久综合| 久久久精品欧美丰满| 五月婷婷欧美视频| www.亚洲人| 久久久精品日韩欧美| 免费av网站大全久久| 欧美亚洲一区二区在线观看| 国产精品国产a| 国产91精品欧美| 久久九九国产精品| 九九久久精品视频| 日韩一区二区在线观看视频播放| 亚洲精品国产无套在线观| 国产91高潮流白浆在线麻豆| 欧美成人性战久久| 日本美女一区二区三区| 欧美理论在线播放| 日本不卡视频在线| 欧美日韩国产美| 性做久久久久久免费观看欧美| 一本一道久久a久久精品| 中文字幕一区二区三区色视频| 欧美日韩中文精品| 国产精品高潮呻吟| av一二三不卡影片| 亚洲天堂成人网| 色综合视频在线观看| 亚洲一区二区三区四区在线| 91久久精品网|