亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
日本高清成人免费播放| 久久久亚洲精华液精华液精华液| 日本一区二区三区电影| 香蕉乱码成人久久天堂爱免费| 国产精品91xxx| 欧美系列一区二区| 国产精品国产三级国产aⅴ入口| 亚洲高清免费一级二级三级| 99久久99久久免费精品蜜臀| 国产精品自拍av| 欧美区视频在线观看| 日韩理论片中文av| 成人精品鲁一区一区二区| 欧美电影免费观看高清完整版在| 亚洲国产一区二区三区| 寂寞少妇一区二区三区| 亚洲h精品动漫在线观看| 奇米影视在线99精品| 99视频一区二区| 欧美亚洲尤物久久| 综合电影一区二区三区| 国产精品综合视频| 欧美精品一区二区三区久久久| 轻轻草成人在线| 26uuu精品一区二区三区四区在线| 丝袜亚洲另类丝袜在线| 99精品欧美一区| 亚洲免费在线看| 成人精品免费视频| 欧美经典一区二区| 91亚洲国产成人精品一区二区三 | 中文字幕在线观看不卡| 成人免费av资源| 亚洲人成影院在线观看| 欧美性一区二区| 国内一区二区在线| 91精品福利在线一区二区三区| 午夜视黄欧洲亚洲| 国产女主播一区| 欧美无砖专区一中文字| 婷婷一区二区三区| 91麻豆精品国产91久久久更新时间| 国内精品久久久久影院薰衣草| 国产精品福利一区二区三区| 欧美精品乱码久久久久久按摩| 国产一区激情在线| 亚洲成人自拍一区| 欧美国产日韩精品免费观看| 91精品欧美综合在线观看最新| 国产一区二区三区免费看| 亚洲自拍都市欧美小说| 日本一区二区视频在线| 欧美精品乱人伦久久久久久| 国产suv精品一区二区6| 午夜欧美视频在线观看| 国产精品久久久99| 久久久久久日产精品| 91福利在线免费观看| 天天影视网天天综合色在线播放| 国产精品欧美久久久久一区二区| 337p亚洲精品色噜噜狠狠| 91成人在线精品| 色综合一个色综合| 91一区二区在线观看| 青青草国产精品亚洲专区无| 亚洲第一成人在线| 午夜久久久久久| 国产精品久久久久影视| 欧美一区二区精品在线| 欧美人体做爰大胆视频| 波多野结衣欧美| 成人免费视频一区二区| 国产成a人亚洲精品| 成人不卡免费av| 欧美综合一区二区三区| 欧美这里有精品| 日韩一区二区三区观看| 欧美精品色一区二区三区| 成人国产精品免费网站| 91香蕉视频mp4| 91免费精品国自产拍在线不卡| 在线视频综合导航| 8x福利精品第一导航| 精品国产一区二区在线观看| 精品国产sm最大网站免费看| 亚洲精品在线网站| 亚洲六月丁香色婷婷综合久久| 国产精品久久精品日日| 亚洲1区2区3区视频| 国产精品18久久久| 91国产视频在线观看| 欧美高清一级片在线| 日本一区二区视频在线| 五月天激情综合网| 成人一区二区在线观看| 日韩一区二区精品葵司在线| 久久精品人人做| 亚洲一区在线观看视频| 风间由美一区二区三区在线观看 | 国产在线国偷精品免费看| 国产激情视频一区二区三区欧美 | 亚洲妇女屁股眼交7| 亚洲一区电影777| 精品综合免费视频观看| 91一区在线观看| 欧美精品一区二区三区蜜桃 | 欧美日韩在线三级| 国产精品美女一区二区在线观看| 天天综合色天天| av中文一区二区三区| 欧美日韩亚洲综合一区| 亚洲最新在线观看| 一本一道久久a久久精品综合蜜臀 一本一道综合狠狠老 | 九九视频精品免费| 欧亚一区二区三区| 亚州成人在线电影| 色哟哟国产精品| 亚洲免费在线看| 在线看日本不卡| 亚洲丝袜另类动漫二区| 91麻豆福利精品推荐| 亚洲色图欧美在线| 色嗨嗨av一区二区三区| 日韩福利视频网| 国产三级欧美三级| 国产馆精品极品| 亚洲男人的天堂一区二区| 欧美吞精做爰啪啪高潮| 亚洲国产欧美一区二区三区丁香婷| 成人黄色片在线观看| 日韩欧美激情一区| 国产精品一区二区视频| 亚洲美女屁股眼交| 欧美日韩综合在线| 蜜臀久久久99精品久久久久久| 奇米影视7777精品一区二区| 国产一区二区精品久久91| 在线国产亚洲欧美| 日韩国产欧美在线播放| 国产婷婷精品av在线| 欧美视频在线一区| 国产精品99久久久久久似苏梦涵 | 日本一区二区三区dvd视频在线| 暴力调教一区二区三区| 日韩在线观看一区二区| 国产精品久久久久影院亚瑟| 日韩一区二区三区视频在线| 色av成人天堂桃色av| 国产精品正在播放| 久久精品国产999大香线蕉| 一区二区欧美在线观看| 日韩欧美不卡一区| 欧美性视频一区二区三区| 从欧美一区二区三区| 极品美女销魂一区二区三区免费 | 韩国av一区二区三区| 午夜精品久久久久久久久久久| 亚洲欧美日韩一区二区三区在线观看 | 欧美一区二区精品久久911| 奇米影视7777精品一区二区| 亚洲欧美日韩中文播放| 国产精品国产三级国产aⅴ入口| 精品久久久久av影院| 欧美一区在线视频| 日韩免费性生活视频播放| 欧美精品 日韩| 91捆绑美女网站| 一本大道久久a久久综合婷婷| 99精品国产99久久久久久白柏| 成人黄色网址在线观看| 97久久精品人人做人人爽| 91原创在线视频| 欧美人牲a欧美精品| 欧美一级xxx| 日韩欧美你懂的| 欧美日韩亚洲综合在线| 日韩美女视频在线| 久久精品人人做人人爽97| 久久先锋资源网| 国产精品美女久久久久高潮| 国产人久久人人人人爽| 一区二区在线电影| 麻豆精品一区二区av白丝在线| 国产高清不卡一区| 欧美日韩国产一级片| 欧美酷刑日本凌虐凌虐| 91国产福利在线| 亚洲国产激情av| 日韩国产在线观看| 99re热视频这里只精品| 欧美日韩视频在线观看一区二区三区| 91麻豆精品国产综合久久久久久| 欧美激情一区二区三区四区| 久久这里只有精品视频网| 亚洲欧美中日韩| 久久er99热精品一区二区| 欧美丝袜丝交足nylons| 日本一区二区三区高清不卡 | 日韩亚洲欧美一区二区三区| 欧洲精品一区二区|