亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
一区二区欧美国产| 视频一区二区三区入口| 91国产视频在线观看| 免费看黄色91| 自拍偷拍欧美精品| 久久亚洲免费视频| 欧美三级电影一区| av电影在线观看完整版一区二区 | 亚洲一区二区三区免费视频| 精品国产青草久久久久福利| 欧美在线三级电影| 成人开心网精品视频| 美女久久久精品| 亚洲一区二区偷拍精品| 国产精品免费网站在线观看| 欧美大片一区二区| 欧美浪妇xxxx高跟鞋交| av电影在线观看一区| 福利一区二区在线| 国产一区二区视频在线| 日韩在线一区二区| 亚洲愉拍自拍另类高清精品| 中文字幕色av一区二区三区| 久久免费看少妇高潮| 日韩一区二区不卡| 欧美日韩精品欧美日韩精品一| 99精品桃花视频在线观看| 国产精品综合二区| 国产精品资源在线看| 极品少妇xxxx精品少妇偷拍| 日韩和欧美的一区| 天堂在线亚洲视频| 午夜精品久久久久久久99水蜜桃| 国产精品亚洲а∨天堂免在线| 韩国三级在线一区| 久草热8精品视频在线观看| 污片在线观看一区二区| 午夜视频在线观看一区二区| 亚洲最大色网站| 亚洲一区二区三区美女| 亚洲精品视频在线看| 亚洲欧美经典视频| 亚洲三级在线看| 亚洲视频1区2区| 亚洲精品精品亚洲| 一区二区三区四区不卡视频| 一区二区三区国产精华| 亚洲午夜在线电影| 亚州成人在线电影| 日产精品久久久久久久性色| 久久精品72免费观看| 久久精品国产一区二区三| 激情欧美日韩一区二区| 国产成a人亚洲精| 一本色道亚洲精品aⅴ| 在线一区二区视频| 欧美久久久一区| 精品国产区一区| 国产精品视频一二三区| 一区二区在线观看不卡| 一二三四社区欧美黄| 免费视频一区二区| 国产九色精品成人porny| 成人高清av在线| 在线精品视频小说1| 91精品免费观看| 久久久三级国产网站| 中文字幕一区av| 亚洲国产aⅴ成人精品无吗| 免费人成黄页网站在线一区二区| 国产丶欧美丶日本不卡视频| 99riav一区二区三区| 欧美年轻男男videosbes| 欧美精品一区二区在线观看| 国产精品日日摸夜夜摸av| 亚洲一区二区三区不卡国产欧美| 久久99久久精品欧美| a4yy欧美一区二区三区| 欧美精品在线视频| 久久激情五月激情| 成人激情开心网| 欧美丝袜第三区| 久久九九久久九九| 亚洲综合色自拍一区| 久久精品999| 色综合天天做天天爱| 欧美本精品男人aⅴ天堂| 国产精品福利电影一区二区三区四区| 亚洲综合免费观看高清在线观看| 久久国产福利国产秒拍| 91网页版在线| 日韩欧美国产麻豆| 亚洲乱码一区二区三区在线观看| 日本aⅴ精品一区二区三区| 国产91丝袜在线播放| 欧美日韩美女一区二区| 国产精品免费视频网站| 美女被吸乳得到大胸91| 91视频国产资源| 2017欧美狠狠色| 午夜精品久久久久久不卡8050| 成人av影院在线| 欧美v日韩v国产v| 一区二区三区精品在线| 国产精品亚洲一区二区三区妖精| 欧美日本国产一区| 国产精品福利影院| 国产一区二区在线观看视频| 欧美日韩一区三区四区| 国产午夜亚洲精品午夜鲁丝片| 亚洲高清中文字幕| 99精品偷自拍| 日本一区二区免费在线观看视频| 日韩精品一级中文字幕精品视频免费观看 | 亚洲午夜久久久久久久久电影院| 国产精品资源网站| 欧美岛国在线观看| 五月婷婷久久综合| 欧美熟乱第一页| 一区二区三区精品在线观看| 成人a区在线观看| 2014亚洲片线观看视频免费| 乱一区二区av| 91精品国产91热久久久做人人| 亚洲精品免费视频| youjizz国产精品| 中国色在线观看另类| 国产高清不卡二三区| 精品福利一区二区三区| 日韩国产精品大片| 亚洲在线免费播放| 色噜噜偷拍精品综合在线| 中文字幕一区二区三区视频| 成人黄色综合网站| 中文字幕日韩精品一区| 成人黄色在线看| 国产精品乱码一区二三区小蝌蚪| 国产99精品在线观看| 国产精品色哟哟| 不卡一二三区首页| 亚洲丝袜制服诱惑| 欧美少妇一区二区| 午夜国产精品影院在线观看| 欧美精品xxxxbbbb| 蜜臀av性久久久久蜜臀aⅴ| 日韩欧美一区二区三区在线| 激情久久五月天| 国产精品人人做人人爽人人添| 成人国产精品免费| 一区二区三区中文在线| 欧美三级韩国三级日本一级| 日本aⅴ免费视频一区二区三区| 日韩欧美在线网站| 国产综合久久久久久久久久久久| 国产三级久久久| 成人午夜av在线| ㊣最新国产の精品bt伙计久久| 97se亚洲国产综合在线| 一区二区三区资源| 91麻豆精品国产自产在线观看一区 | 精品嫩草影院久久| 国产jizzjizz一区二区| 亚洲蜜臀av乱码久久精品蜜桃| 欧美在线|欧美| 视频一区视频二区中文字幕| 欧美本精品男人aⅴ天堂| 成年人国产精品| 成人免费毛片aaaaa**| 99re这里都是精品| aaa欧美大片| a在线欧美一区| 国产亚洲福利社区一区| 99精品黄色片免费大全| 一区二区在线免费观看| 欧美一区二区三区思思人| 国产乱理伦片在线观看夜一区 | 亚洲一区成人在线| 日韩精品一区二区三区中文精品| 丰满少妇在线播放bd日韩电影| 亚洲精品老司机| 日韩美女在线视频| 色久综合一二码| 国产一区三区三区| 亚洲影院在线观看| 久久综合久久久久88| 色婷婷av一区二区三区大白胸| 久久精品免费看| 亚洲自拍欧美精品| 国产三级一区二区三区| 欧美视频中文字幕| 成人免费av在线| 日韩高清在线电影| 亚洲欧美自拍偷拍| 精品国产免费视频| 欧美性大战久久久久久久蜜臀| 国产不卡高清在线观看视频| 蜜桃一区二区三区四区| 一区二区三区视频在线看| 久久久久久日产精品| 91精品国产综合久久国产大片|