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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? routing1.cpp

?? 實(shí)現(xiàn)最短路徑算法。 實(shí)現(xiàn)最短路徑算法。
?? 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)//扔掉一個(gè)變量
		{
			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);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩一区三区| 日韩美女视频一区二区| 91麻豆精品91久久久久久清纯| 成人国产亚洲欧美成人综合网| 狠狠色狠狠色综合| 国产在线视频不卡二| 国内一区二区视频| 国产一区二区三区精品视频| 国内不卡的二区三区中文字幕 | 国产精品毛片久久久久久| 精品国产不卡一区二区三区| 国产九九视频一区二区三区| 免费看日韩a级影片| 日韩一区精品字幕| 日本欧美一区二区三区乱码 | 99在线热播精品免费| 日本不卡视频在线观看| 青草av.久久免费一区| 日本成人在线电影网| 激情偷乱视频一区二区三区| 大美女一区二区三区| 91蜜桃在线观看| 欧美人牲a欧美精品| 欧美电影免费提供在线观看| 国产喂奶挤奶一区二区三区| 综合久久给合久久狠狠狠97色 | 日本不卡的三区四区五区| 秋霞电影网一区二区| 国产真实乱偷精品视频免| 丁香亚洲综合激情啪啪综合| 日本韩国一区二区三区| 777午夜精品免费视频| 久久蜜桃香蕉精品一区二区三区| 国产肉丝袜一区二区| 夜夜夜精品看看| 奇米影视一区二区三区小说| 国产福利91精品一区| 欧洲亚洲精品在线| 日韩欧美国产一区二区三区| 国产欧美一区二区在线观看| 亚洲精品写真福利| 久久97超碰色| 一本在线高清不卡dvd| 91精品国产91久久久久久最新毛片 | 一区二区三区日本| 裸体健美xxxx欧美裸体表演| 福利一区福利二区| 欧美日韩一级视频| 久久精品视频一区二区三区| 亚洲综合一区二区精品导航| 国内不卡的二区三区中文字幕| 一本大道久久a久久综合| 日韩精品专区在线影院重磅| 亚洲视频一区在线观看| 精彩视频一区二区| 欧美午夜一区二区三区| 久久精品亚洲麻豆av一区二区 | 精品亚洲国产成人av制服丝袜| 99久久精品久久久久久清纯| 日韩视频永久免费| 一区二区三区四区乱视频| 国内精品在线播放| 欧美久久久久久蜜桃| 国产精品欧美综合在线| 久久99精品一区二区三区三区| 91精品办公室少妇高潮对白| 久久―日本道色综合久久| 亚洲国产人成综合网站| 成人激情小说网站| 精品日韩欧美在线| 香港成人在线视频| 99热国产精品| 久久久精品2019中文字幕之3| 亚洲成人久久影院| 91在线国产福利| 国产欧美一区二区在线| 蜜臀久久99精品久久久久宅男| 91麻豆免费观看| 中文字幕 久热精品 视频在线 | 91在线小视频| 国产欧美一区视频| 狠狠久久亚洲欧美| 精品人伦一区二区色婷婷| 五月婷婷欧美视频| 日本韩国视频一区二区| 欧美国产一区视频在线观看| 国产一区日韩二区欧美三区| 欧美一级在线免费| 天堂一区二区在线免费观看| 在线视频国内自拍亚洲视频| 综合久久给合久久狠狠狠97色 | 中文字幕+乱码+中文字幕一区| 精品一区二区三区久久| 91精品中文字幕一区二区三区| 亚洲韩国一区二区三区| 欧美写真视频网站| 亚洲风情在线资源站| 欧美艳星brazzers| 亚洲午夜精品17c| 欧美三片在线视频观看| 亚洲综合男人的天堂| 欧美亚洲国产一区在线观看网站| 一区二区三区中文免费| 91亚洲资源网| 亚洲欧美日韩国产成人精品影院 | 在线观看免费一区| 亚洲国产另类精品专区| 欧美三级视频在线播放| 亚洲国产综合色| 91精品福利在线一区二区三区| 免费日韩伦理电影| 精品国产91乱码一区二区三区| 狠狠色丁香久久婷婷综| 国产亚洲欧美色| 不卡免费追剧大全电视剧网站| 国产精品不卡一区二区三区| 一本在线高清不卡dvd| 亚洲成人av福利| 日韩欧美国产精品一区| 国产精品一区二区果冻传媒| 欧美国产激情一区二区三区蜜月| gogogo免费视频观看亚洲一| 亚洲人成电影网站色mp4| 欧美在线不卡视频| 视频一区中文字幕| 欧美精品一区二| 北岛玲一区二区三区四区| 一区二区三区精品视频| 欧美一级夜夜爽| 成人一级片网址| 亚洲中国最大av网站| 91精品国产综合久久国产大片| 国产精品自产自拍| 亚洲人成在线播放网站岛国| 91精品久久久久久久99蜜桃| 久久精品久久久精品美女| 日本一区二区高清| 欧美猛男超大videosgay| 久草热8精品视频在线观看| 国产精品精品国产色婷婷| 欧美久久婷婷综合色| 国产激情一区二区三区四区| 亚洲综合在线视频| 欧美mv日韩mv亚洲| av一区二区久久| 日本女人一区二区三区| 国产精品麻豆视频| 制服.丝袜.亚洲.中文.综合| 国产91精品一区二区麻豆网站 | 水野朝阳av一区二区三区| 久久久久久久电影| 欧美亚洲国产一区在线观看网站| 久久99精品一区二区三区| 亚洲美女一区二区三区| 精品欧美乱码久久久久久1区2区| 91色porny| 久久99国产精品免费| 亚洲综合一二三区| 国产欧美日韩在线看| 欧美军同video69gay| 成人动漫一区二区| 日韩成人一区二区| 亚洲人精品午夜| 久久久噜噜噜久噜久久综合| 在线区一区二视频| 粉嫩一区二区三区在线看| 免费久久99精品国产| 亚洲精品视频在线观看网站| 国产网红主播福利一区二区| 69av一区二区三区| 色综合久久综合网欧美综合网| 极品瑜伽女神91| 午夜精品一区二区三区三上悠亚 | 国内不卡的二区三区中文字幕| 亚洲一区二区三区四区在线| 中文字幕的久久| 欧美精品一区二区三区高清aⅴ| 99国产精品久| 国产成人综合亚洲网站| 美日韩一区二区| 午夜视频一区在线观看| 夜夜嗨av一区二区三区网页| 国产精品视频第一区| 精品国产乱码久久久久久夜甘婷婷| 在线观看日韩精品| 色综合中文字幕国产| 成人av网在线| 激情久久五月天| 久久se精品一区精品二区| 午夜精品福利在线| 亚洲综合在线免费观看| 亚洲激情综合网| 亚洲视频一区二区免费在线观看 | 福利一区福利二区| 国产一区二区三区在线观看免费 | 日本丰满少妇一区二区三区| fc2成人免费人成在线观看播放| 国产91丝袜在线18| 福利电影一区二区三区| 成人亚洲一区二区一|