亚洲欧美第一页_禁久久精品乱码_粉嫩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)
{
	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);
	createFlag = create_test(&graph,vexFile,topoFile);
	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
/////////////////////////////////////////////////////////////////
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一区二区三区免费野_久草精品视频
555夜色666亚洲国产免| 风流少妇一区二区| 欧美日韩亚洲国产综合| 亚洲一级在线观看| 91精品欧美福利在线观看| 亚洲午夜日本在线观看| 亚洲精品一区二区三区在线观看| 成人激情小说乱人伦| 一区二区高清免费观看影视大全| 成人午夜伦理影院| 精品va天堂亚洲国产| 成人综合婷婷国产精品久久| 亚洲一区二区偷拍精品| 亚洲激情综合网| 亚洲精品成人悠悠色影视| 午夜久久电影网| 欧美日韩一区在线观看| 天堂av在线一区| 日韩视频一区二区三区在线播放| 日本欧美韩国一区三区| 日韩一级高清毛片| 国产在线不卡一区| 91精选在线观看| 色综合久久九月婷婷色综合| 日本成人在线视频网站| 国产精品久久久久aaaa| 欧美日本在线看| 久久91精品久久久久久秒播| 国产婷婷色一区二区三区在线| 91色综合久久久久婷婷| 国产伦精品一区二区三区免费迷| 国内一区二区视频| 国产精品另类一区| 精品国精品自拍自在线| 色激情天天射综合网| 激情都市一区二区| 亚洲成av人在线观看| 欧美激情一区在线| 日韩免费视频一区| 欧美日韩dvd在线观看| 成人久久18免费网站麻豆| 久久国产精品99久久人人澡| 亚洲小说欧美激情另类| 久久欧美中文字幕| 欧美一区二区网站| 91麻豆精品国产91久久久久| 欧美一区二区在线不卡| 91精品国产福利| 国产91在线观看| 亚洲专区一二三| 国产精品电影一区二区| 亚洲一区二区精品3399| 国产一区二区三区四区五区美女 | 97久久精品人人做人人爽50路| 一区二区三区蜜桃网| 日韩欧美激情四射| 99在线精品视频| 久久久久久久久久久久久女国产乱| 日韩欧美国产综合| 日韩精品一区二区三区四区视频| 日韩午夜av一区| 欧美成人aa大片| 久久久亚洲国产美女国产盗摄 | 欧美日韩亚洲高清一区二区| 91视频.com| 欧美亚洲一区二区在线| 欧美精品v国产精品v日韩精品| 欧美一卡在线观看| 欧美一区二区三区公司| 久久久影视传媒| 中文一区一区三区高中清不卡| 国产精品无码永久免费888| 国产精品毛片无遮挡高清| 亚洲猫色日本管| 亚洲成精国产精品女| 青青青伊人色综合久久| 国产一区二区在线影院| 国产一二精品视频| 91在线免费播放| 欧美一区二区视频免费观看| 日本一区二区三区免费乱视频 | 国产农村妇女毛片精品久久麻豆| 亚洲免费大片在线观看| 在线日韩国产精品| 91麻豆自制传媒国产之光| 一区二区高清在线| 国产欧美日韩在线观看| 欧美丰满嫩嫩电影| 色偷偷一区二区三区| 成人一区二区视频| 激情综合网av| 秋霞午夜av一区二区三区| 亚洲日本在线天堂| 国产欧美综合在线观看第十页| 欧美三级电影在线观看| 亚洲免费观看高清| 国产一区二区三区黄视频 | 欧美一级二级三级乱码| 欧美国产精品久久| 亚洲大片免费看| 99精品热视频| 精品久久久三级丝袜| 亚洲一区二区在线免费观看视频| 国产永久精品大片wwwapp| 欧美伊人久久大香线蕉综合69| 国产性做久久久久久| 国产高清在线精品| 91精品国产91久久久久久一区二区| 国产欧美精品区一区二区三区| 日韩电影在线观看一区| 91色乱码一区二区三区| 国产午夜亚洲精品理论片色戒| 日韩精品久久理论片| 色94色欧美sute亚洲线路一久| 国产精品水嫩水嫩| 国产91精品在线观看| 久久精品一区蜜桃臀影院| 蜜桃视频第一区免费观看| 久久久噜噜噜久久人人看| 国产精品一区三区| 一区二区三区中文字幕| 不卡一区在线观看| 亚洲精品一区二区三区在线观看| 五月开心婷婷久久| 91久久精品一区二区二区| 亚洲欧美视频在线观看| 欧美一区二区高清| 欧美久久一二区| 成人av片在线观看| 亚洲电影一区二区三区| 亚洲成人高清在线| 视频一区二区三区在线| 天堂一区二区在线| 石原莉奈在线亚洲二区| 蜜臀久久久99精品久久久久久| 蜜桃精品在线观看| 久久99国产精品久久| 国产精品影视在线| 美女视频黄a大片欧美| 日韩欧美卡一卡二| 成人一级片在线观看| 亚洲欧美电影院| 久久影音资源网| 国产乱码精品一区二区三区五月婷| 久久这里只有精品视频网| 91精品办公室少妇高潮对白| 亚洲高清免费视频| 精品国产一区二区三区av性色| 日本韩国欧美在线| 日韩午夜电影av| 久久综合色婷婷| 亚洲一二三级电影| 亚洲成av人综合在线观看| 日韩av网站免费在线| 精品伊人久久久久7777人| 国内成人免费视频| 成人黄色小视频| 日本伦理一区二区| 欧美一区二区三区视频免费| 亚洲精品一区二区三区蜜桃下载 | 蜜桃视频第一区免费观看| 精品无人码麻豆乱码1区2区| 国产成人综合网站| 色综合久久综合网97色综合 | 91亚洲男人天堂| 久久99最新地址| 丝袜美腿成人在线| 中文字幕亚洲在| 最新日韩在线视频| 久久综合资源网| 欧美精品第1页| 91麻豆视频网站| 99国产精品一区| 国产麻豆成人精品| 美洲天堂一区二卡三卡四卡视频| ...av二区三区久久精品| 精品美女被调教视频大全网站| 色丁香久综合在线久综合在线观看| 国产美女在线精品| 成人免费在线观看入口| 亚洲成精国产精品女| 国产精品综合一区二区三区| 91国产丝袜在线播放| 欧美电视剧在线看免费| 最新欧美精品一区二区三区| 日韩国产精品久久久| 精品中文字幕一区二区| 捆绑调教美女网站视频一区| 免费在线成人网| 五月天精品一区二区三区| 亚洲午夜久久久久久久久久久 | 欧美一级夜夜爽| 欧美久久高跟鞋激| 91黄色免费版| 欧美日韩视频在线第一区| 欧美伊人精品成人久久综合97| 欧美视频中文字幕| 欧美日韩成人高清| 精品国产伦理网| 中文字幕一区二区三中文字幕|