You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					522 lines
				
				11 KiB
			
		
		
			
		
	
	
					522 lines
				
				11 KiB
			| 
											1 year ago
										 | #include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
 | ||
|  | #include "Astar.h"
 | ||
|  | 
 | ||
|  | Astar astar; | ||
|  | 
 | ||
| 
											1 year ago
										 | void DSU::init(int cnt) | ||
|  | { | ||
|  | 	for (int i = 1; i <= cnt; i++) | ||
|  | 		f[i] = i; | ||
| 
											1 year ago
										 | } | ||
| 
											1 year ago
										 | int DSU::getrt(int x) | ||
|  | { | ||
|  | 	if (x != f[x]) | ||
|  | 		return f[x] = getrt(f[x]); | ||
| 
											1 year ago
										 | 	return x; | ||
|  | } | ||
| 
											1 year ago
										 | void DSU::merge(int x, int y) | ||
|  | { | ||
|  | 	if (x != f[x]) | ||
|  | 		x = getrt(x); | ||
|  | 	if (y != f[y]) | ||
|  | 		y = getrt(y); | ||
| 
											1 year ago
										 | 	f[x] = y; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | bool Node::operator<(Node B) const | ||
|  | { | ||
|  | 	// if(turncnt!=B.turncnt)return turncnt>B.turncnt;
 | ||
|  | 	return dis > B.dis; | ||
| 
											1 year ago
										 | } | ||
| 
											1 year ago
										 | Node::Node() | ||
|  | { | ||
|  | 	xs = 0; | ||
|  | 	dis = 0; | ||
|  | 	turncnt = 0; | ||
| 
											1 year ago
										 | } | ||
| 
											1 year ago
										 | Node::Node(int xs1, int turnc, double dis1) | ||
|  | { | ||
|  | 	xs = xs1; | ||
|  | 	dis = dis1; | ||
|  | 	turncnt = turnc; | ||
| 
											1 year ago
										 | } | ||
|  | 
 | ||
| 
											1 year ago
										 | Astar::Astar() | ||
|  | { | ||
|  | 	pnum = 0; | ||
|  | 	l = bend_r = 0; | ||
|  | 	tnum = 0; | ||
|  | 	pclipSet = &clipSet; | ||
| 
											1 year ago
										 | } | ||
|  | 
 | ||
| 
											1 year ago
										 | void Astar::addBranchTree(BranchTree *pbranchTree) | ||
|  | { | ||
| 
											1 year ago
										 | 	this->pbranchTree = pbranchTree; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | // 初始化
 | ||
|  | void Astar::init() | ||
|  | { | ||
| 
											1 year ago
										 | 	pnum += 2; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | // 添加一个卡箍点
 | ||
|  | void Astar::add_clip(P &p, P &d) | ||
|  | { | ||
|  | 	pnum++; | ||
|  | 	tnum++; | ||
| 
											1 year ago
										 | 	points[pnum] = p; | ||
|  | 	points[pnum].ref = pnum; | ||
|  | 
 | ||
|  | 	P dir = p - d; | ||
|  | 	points[pnum].dx = dir.x; | ||
|  | 	points[pnum].dy = dir.y; | ||
|  | 	points[pnum].dz = dir.z; | ||
|  | 	block[pnum] = 0; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | void Astar::add_clip(Clip &cp) | ||
|  | { | ||
|  | 	pnum++; | ||
|  | 	tnum++; | ||
| 
											1 year ago
										 | 	points[pnum] = cp.coord; | ||
|  | 	block[pnum] = 0; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | // 添加一个分支点
 | ||
|  | void Astar::add_branchPoint(BranchPoint &bp) | ||
|  | { | ||
| 
											1 year ago
										 | 	tnum = max(tnum, clipSet.clipnum + 2); | ||
|  | 	tnum++; | ||
|  | 	points[tnum] = bp.coord; | ||
|  | 	block[tnum] = 0; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | Path Astar::search_pair(P &start, P &goal, P &start_dir, P &goal_dir, double dia) | ||
|  | { | ||
| 
											1 year ago
										 | 	this->start = start; | ||
|  | 	this->goal = goal; | ||
|  | 	this->start_dir = start_dir; | ||
|  | 	this->goal_dir = goal_dir; | ||
|  | 	path.dia = dia; | ||
|  | 	pnum -= 2; | ||
|  | 	path.points.clear(); | ||
|  | 	path.wirelist.clear(); | ||
|  | 	path.dia = dia; | ||
|  | 	search(); | ||
|  | 	return path; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | Path Astar::search_pair(P &start, P &goal, double dia) | ||
|  | { | ||
| 
											1 year ago
										 | 	this->start = start; | ||
|  | 	this->goal = goal; | ||
|  | 	path.dia = dia; | ||
|  | 
 | ||
|  | 	pnum -= 2; | ||
|  | 	path.points.clear(); | ||
|  | 	path.wirelist.clear(); | ||
|  | 	path.dia = dia; | ||
|  | 	search(); | ||
|  | 	return path; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | Path Astar::search_pair(Bund &bd) | ||
|  | { | ||
| 
											1 year ago
										 | 	this->start = bd.start; | ||
|  | 	this->goal = bd.goal; | ||
|  | 	pnum -= 2; | ||
|  | 	path.points.clear(); | ||
|  | 	path.inOut.clear(); | ||
|  | 	path.wirelist = bd.wirenamelist; | ||
|  | 	path.dia = bd.dia; | ||
|  | 	tnum = max(tnum, clipSet.clipnum + 2); | ||
|  | 	search(); | ||
|  | 	return path; | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | void Astar::searchForPreProcess() | ||
|  | { | ||
|  | 	while (!pq.empty()) | ||
|  | 		pq.pop(); | ||
| 
											1 year ago
										 | 	points[++pnum] = start; | ||
|  | 	points[++pnum] = goal; | ||
| 
											1 year ago
										 | 	S = pnum - 1; | ||
|  | 	T = pnum; | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 	for (int i = 1; i <= 2 * tnum + 2; i++) | ||
|  | 		vis[i] = 0, dis[i] = Node(i, 1000, 1e9), pre[i] = 0; | ||
| 
											1 year ago
										 | 
 | ||
|  | 	dis[S * 2] = Node(S * 2, 0, 0); | ||
|  | 
 | ||
|  | 	assert(pre[2 * S] == 0); | ||
|  | 
 | ||
|  | 	pq.push(dis[S * 2]); | ||
| 
											1 year ago
										 | 	vector<pair<int, int>> tempvec = basicEdge.getEXTNextPoint(points[T], pnum, 1); | ||
|  | 	vector<pair<int, int>> pointsConnectedToGoal; | ||
|  | 	for (int i = 0; i < tempvec.size(); i++) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		int xs = tempvec[i].first; | ||
|  | 		if (!bvh.iscollect(points[xs], points[T])) | ||
|  | 			pointsConnectedToGoal.push_back(tempvec[i]); | ||
|  | 	} | ||
|  | 	bool testflag = true; | ||
| 
											1 year ago
										 | 	while (!pq.empty()) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		Node node = pq.top(); | ||
| 
											1 year ago
										 | 		// cout<<pq.top().xs<<endl;
 | ||
| 
											1 year ago
										 | 
 | ||
|  | 		pq.pop(); | ||
| 
											1 year ago
										 | 		while (vis[node.xs] && !pq.empty()) | ||
|  | 			node = pq.top(), pq.pop(); | ||
| 
											1 year ago
										 | 
 | ||
|  | 		vis[node.xs] = 1; | ||
|  | 
 | ||
|  | 		int xs = node.xs; | ||
|  | 		int inOut = xs % 2; | ||
|  | 		xs /= 2; | ||
|  | 
 | ||
|  | 		pair<int, int> currentNode = make_pair(xs, inOut); | ||
|  | 
 | ||
| 
											1 year ago
										 | 		if (xs == T) | ||
|  | 			break; | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 		vector<pair<int, int>> vec; | ||
|  | 		if (xs != S) | ||
|  | 			vec = basicEdge.getNextPoint(xs, inOut, pnum); | ||
|  | 		else if (xs == S && nearClip[points[xs]] != make_pair(0, 0)) | ||
|  | 			vec.push_back(nearClip[points[S]]); | ||
|  | 		else | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			vec = basicEdge.getEXTNextPoint(points[S], pnum, 0); | ||
| 
											1 year ago
										 | 			// cout<<vec.size()<<endl;
 | ||
| 
											1 year ago
										 | 		} | ||
|  | 
 | ||
| 
											1 year ago
										 | 		if (nearClip[points[T]] == make_pair(0, 0)) | ||
|  | 		{ | ||
|  | 			for (int i = 0; i < pointsConnectedToGoal.size(); i++) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				if (pointsConnectedToGoal[i] == currentNode) | ||
|  | 					vec.push_back(make_pair(T, 0)); | ||
|  | 			} | ||
|  | 		} | ||
| 
											1 year ago
										 | 		else if (nearClip[points[T]] == currentNode) | ||
|  | 			vec.push_back(make_pair(T, 0)); | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 		for (int i = 0; i < vec.size(); i++) | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			int v = vec[i].first; | ||
|  | 			int mode = vec[i].second; | ||
|  | 			if (v < pnum - 1) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				// if(!(pclipSet->transitable(v,0,path.dia)))continue;
 | ||
|  | 				// if(block[v])continue;
 | ||
| 
											1 year ago
										 | 				; | ||
|  | 			} | ||
| 
											1 year ago
										 | 			// cout<<v<<endl;
 | ||
|  | 			if (v == xs) | ||
|  | 				cout << "v==xs " << v << endl; | ||
| 
											1 year ago
										 | 			/*
 | ||
|  | 			if(points[xs]==points[v]){ | ||
|  | 				cout<<xs<<"  "<<v<<endl; | ||
|  | 				cout<<points[xs].x<<"  "<<points[xs].y<<"  "<<points[xs].z<<endl; | ||
|  | 			} | ||
|  | 			*/ | ||
|  | 
 | ||
| 
											1 year ago
										 | 			if (points[xs] == points[v]) | ||
|  | 				continue; | ||
| 
											1 year ago
										 | 			assert(xs != v); | ||
|  | 			assert(points[xs] != points[v]); | ||
|  | 			assert(v != pnum - 1); | ||
| 
											1 year ago
										 | 			// assert(pnum==2833);
 | ||
| 
											1 year ago
										 | 			assert(pre[2 * (pnum - 1)] == 0); | ||
|  | 			assert(pre[2 * (pnum - 1) + 1] == 0); | ||
|  | 
 | ||
|  | 			double cst = distan(points[xs], points[v], inOut, mode); | ||
| 
											1 year ago
										 | 			if (points[xs].type == 1 || points[xs].type == 2) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				int bid = points[xs].ref; | ||
| 
											1 year ago
										 | 				BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 				cst = pb->computeWeight(points[v], mode, 0); | ||
|  | 			} | ||
| 
											1 year ago
										 | 			if (points[v].type == 1 || points[v].type == 2) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				int bid = points[v].ref; | ||
| 
											1 year ago
										 | 				BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 				cst = pb->computeWeight(points[xs], inOut, 1); | ||
|  | 			} | ||
|  | 			cst += +dis[xs * 2 + inOut].dis; | ||
|  | 
 | ||
| 
											1 year ago
										 | 			if (dis[2 * v + mode] < Node(2 * v + mode, 0, cst)) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				dis[2 * v + mode] = Node(2 * v + mode, 0, cst); | ||
|  | 				assert(v != pnum - 1); | ||
|  | 				pre[2 * v + mode] = xs * 2 + inOut; | ||
|  | 				pq.push(dis[2 * v + mode]); | ||
|  | 			} | ||
|  | 		} | ||
|  | 	} | ||
|  | 	int top = 0; | ||
|  | 	int tag = T * 2; | ||
| 
											1 year ago
										 | 	while (pre[tag]) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		st[++top] = tag; | ||
|  | 		tag = pre[tag]; | ||
| 
											1 year ago
										 | 		if (testflag) | ||
|  | 			cout << "nodeid " << tag << endl; | ||
| 
											1 year ago
										 | 	} | ||
| 
											1 year ago
										 | 	if (top) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		st[++top] = S * 2; | ||
|  | 	} | ||
| 
											1 year ago
										 | 	for (int i = top; i > 0; i--) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		int id = st[i]; | ||
| 
											1 year ago
										 | 		if (top > 2) | ||
|  | 		{ | ||
|  | 			if (id / 2 != S && id / 2 != T) | ||
|  | 			{ | ||
|  | 				if (i == top - 1) | ||
|  | 					nearClip[points[S]] = make_pair(id / 2, id % 2); | ||
|  | 				if (i == 2) | ||
|  | 					nearClip[points[T]] = make_pair(id / 2, id % 2); | ||
| 
											1 year ago
										 | 			} | ||
|  | 		} | ||
| 
											1 year ago
										 | 		// if(i!=top&&i!=1)pclipSet->addwire(id,dia);
 | ||
| 
											1 year ago
										 | 		path.points.push_back(points[id / 2]); | ||
| 
											1 year ago
										 | 		if (i != top && i != 1 && id / 2 < pnum) | ||
|  | 			path.inOut.push_back(id % 2); | ||
|  | 		else | ||
|  | 			path.inOut.push_back(-1 - id % 2); | ||
| 
											1 year ago
										 | 	} | ||
|  | } | ||
|  | 
 | ||
| 
											1 year ago
										 | void Astar::search() | ||
|  | { | ||
| 
											1 year ago
										 | 	searchNum++; | ||
|  | 	cout << "searchNum " << searchNum << endl; | ||
|  | 
 | ||
| 
											1 year ago
										 | 	while (!pq.empty()) | ||
|  | 		pq.pop(); | ||
| 
											1 year ago
										 | 	points[++pnum] = start; | ||
|  | 	points[++pnum] = goal; | ||
| 
											1 year ago
										 | 	S = pnum - 1; | ||
|  | 	T = pnum; | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 	for (int i = 1; i <= 2 * tnum + 2; i++) | ||
|  | 		vis[i] = 0, dis[i] = Node(i, 1000, 1e9), pre[i] = 0; | ||
| 
											1 year ago
										 | 
 | ||
|  | 	dis[S * 2] = Node(S * 2, 0, 0); | ||
|  | 
 | ||
|  | 	assert(pre[2 * S] == 0); | ||
|  | 
 | ||
|  | 	pq.push(dis[S * 2]); | ||
| 
											1 year ago
										 | 	vector<pair<int, int>> tempvec = basicEdge.getEXTNextPoint(points[T], pnum, 1); | ||
|  | 	vector<pair<int, int>> pointsConnectedToGoal; | ||
|  | 	for (int i = 0; i < tempvec.size(); i++) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		int xs = tempvec[i].first; | ||
|  | 		if (!bvh.iscollect(points[xs], points[T])) | ||
|  | 			pointsConnectedToGoal.push_back(tempvec[i]); | ||
|  | 	} | ||
|  | 	bool testflag = true; | ||
|  | 	int whilenum = 0; | ||
| 
											1 year ago
										 | 	while (!pq.empty()) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		Node node = pq.top(); | ||
| 
											1 year ago
										 | 		// cout<<pq.top().xs<<endl;
 | ||
| 
											1 year ago
										 | 		whilenum++; | ||
| 
											1 year ago
										 | 		if (searchNum == 105) | ||
|  | 			cout << "whilenum " << whilenum << endl; | ||
| 
											1 year ago
										 | 
 | ||
|  | 		pq.pop(); | ||
| 
											1 year ago
										 | 		while (vis[node.xs] && !pq.empty()) | ||
|  | 			node = pq.top(), pq.pop(); | ||
| 
											1 year ago
										 | 
 | ||
|  | 		vis[node.xs] = 1; | ||
|  | 
 | ||
|  | 		int xs = node.xs; | ||
|  | 		int inOut = xs % 2; | ||
|  | 		xs /= 2; | ||
|  | 
 | ||
|  | 		pair<int, int> currentNode = make_pair(xs, inOut); | ||
|  | 
 | ||
| 
											1 year ago
										 | 		if (xs == T) | ||
|  | 			break; | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 		vector<pair<int, int>> vec; | ||
|  | 		if (xs != S) | ||
|  | 			vec = basicEdge.getNextPoint(xs, inOut, pnum); | ||
|  | 		else if (xs == S && nearClip[points[xs]] != make_pair(0, 0)) | ||
|  | 			vec.push_back(nearClip[points[S]]); | ||
|  | 		else | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			vec = basicEdge.getEXTNextPoint(points[S], pnum, 0); | ||
| 
											1 year ago
										 | 			// cout<<vec.size()<<endl;
 | ||
| 
											1 year ago
										 | 		} | ||
|  | 
 | ||
| 
											1 year ago
										 | 		if (nearClip[points[T]] == make_pair(0, 0)) | ||
|  | 		{ | ||
|  | 			for (int i = 0; i < pointsConnectedToGoal.size(); i++) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				if (pointsConnectedToGoal[i] == currentNode) | ||
|  | 					vec.push_back(make_pair(T, 0)); | ||
|  | 			} | ||
|  | 		} | ||
| 
											1 year ago
										 | 		else if (nearClip[points[T]] == currentNode) | ||
|  | 			vec.push_back(make_pair(T, 0)); | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 		for (int i = 0; i < vec.size(); i++) | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			int v = vec[i].first; | ||
|  | 			int mode = vec[i].second; | ||
|  | 			if (v < pnum - 1) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				// if(!(pclipSet->transitable(v,0,path.dia)))continue;
 | ||
|  | 				// if(block[v])continue;
 | ||
| 
											1 year ago
										 | 				; | ||
|  | 			} | ||
| 
											1 year ago
										 | 			// cout<<v<<endl;
 | ||
|  | 			if (v == xs) | ||
|  | 				cout << "v==xs " << v << "  " << points[v].type << endl; | ||
| 
											1 year ago
										 | 
 | ||
| 
											1 year ago
										 | 			if (vis[v * 2 + mode]) | ||
|  | 				continue; | ||
| 
											1 year ago
										 | 			/*
 | ||
|  | 			if(points[xs]==points[v]){ | ||
|  | 				cout<<xs<<"  "<<v<<endl; | ||
|  | 				cout<<points[xs].x<<"  "<<points[xs].y<<"  "<<points[xs].z<<endl; | ||
|  | 			} | ||
|  | 			*/ | ||
|  | 
 | ||
| 
											1 year ago
										 | 			if (points[xs] == points[v]) | ||
|  | 				continue; | ||
| 
											1 year ago
										 | 			assert(xs != v); | ||
|  | 			assert(points[xs] != points[v]); | ||
|  | 			assert(v != pnum - 1); | ||
| 
											1 year ago
										 | 			// assert(pnum==2833);
 | ||
| 
											1 year ago
										 | 			assert(pre[2 * (pnum - 1)] == 0); | ||
|  | 			assert(pre[2 * (pnum - 1) + 1] == 0); | ||
|  | 
 | ||
|  | 			double cst = distan(points[xs], points[v], inOut, mode); | ||
|  | 
 | ||
|  | 			bool updatePreBranchPoint = false; | ||
|  | 			bool updateNextBranchPoint = false; | ||
|  | 			double tempPos1 = 0, tempPos2 = 0; | ||
| 
											1 year ago
										 | 
 | ||
|  | 				// 特殊处理分支点
 | ||
| 
											1 year ago
										 | 			if (points[xs].type == 1 || points[xs].type == 2) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				int bid = points[xs].ref; | ||
| 
											1 year ago
										 | 				if (inOut == 0) | ||
|  | 				{ | ||
|  | 					BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 					cst = (pb->Dis) / 2; | ||
|  | 				} | ||
| 
											1 year ago
										 | 				else | ||
|  | 				{ | ||
|  | 					BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 					cst = pb->computeWeight(points[v], mode, 0); | ||
|  | 					updatePreBranchPoint = true; | ||
|  | 					tempPos1 = pb->t; | ||
|  | 				} | ||
|  | 			} | ||
| 
											1 year ago
										 | 			if (points[v].type == 1 || points[v].type == 2) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				int bid = points[v].ref; | ||
| 
											1 year ago
										 | 				BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
|  | 				if (mode == 1) | ||
|  | 				{ | ||
| 
											1 year ago
										 | 
 | ||
|  | 					cst = (pb->Dis) / 2; | ||
|  | 				} | ||
| 
											1 year ago
										 | 				else | ||
|  | 				{ | ||
| 
											1 year ago
										 | 					cst = pb->computeWeight(points[xs], inOut, 1); | ||
|  | 					updateNextBranchPoint = true; | ||
|  | 					tempPos2 = pb->t; | ||
|  | 				} | ||
|  | 			} | ||
|  | 			cst += dis[xs * 2 + inOut].dis; | ||
|  | 
 | ||
| 
											1 year ago
										 | 			if (dis[2 * v + mode] < Node(2 * v + mode, 0, cst)) | ||
|  | 			{ | ||
|  | 				if (updatePreBranchPoint) | ||
|  | 				{ | ||
| 
											1 year ago
										 | 					this->preBranchPointPos[2 * v + mode] = tempPos1; | ||
|  | 				} | ||
| 
											1 year ago
										 | 				if (updateNextBranchPoint) | ||
|  | 				{ | ||
| 
											1 year ago
										 | 					int bid = points[v].ref; | ||
| 
											1 year ago
										 | 					BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 					pb->recordPos(0); | ||
|  | 				} | ||
|  | 
 | ||
|  | 				dis[2 * v + mode] = Node(2 * v + mode, 0, cst); | ||
|  | 				assert(v != pnum - 1); | ||
|  | 				pre[2 * v + mode] = xs * 2 + inOut; | ||
|  | 				pq.push(dis[2 * v + mode]); | ||
|  | 			} | ||
|  | 		} | ||
|  | 	} | ||
|  | 	int top = 0; | ||
|  | 	int tag = T * 2; | ||
| 
											1 year ago
										 | 		while (pre[tag]) // pre[tag] 值为0导致无结果,
 | ||
| 
											1 year ago
										 | 	{ | ||
| 
											1 year ago
										 | 		st[++top] = tag; | ||
|  | 		tag = pre[tag]; | ||
| 
											1 year ago
										 | 		if (testflag) | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			cout << "nodeid  " << tag << "  "; | ||
|  | 			if (tag < (pnum - 1) * 2) | ||
|  | 				cout << basicChannel.clipType(tag / 2) << endl; | ||
| 
											1 year ago
										 | 			else | ||
|  | 				cout << -1 << endl; | ||
| 
											1 year ago
										 | 		} | ||
|  | 	} | ||
| 
											1 year ago
										 | 	if (top) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		st[++top] = S * 2; | ||
|  | 	} | ||
|  | 	vector<double> prePos; | ||
| 
											1 year ago
										 | 	for (int i = top; i > 0; i--) | ||
|  | 	{ | ||
| 
											1 year ago
										 | 		int id = st[i]; | ||
| 
											1 year ago
										 | 		if (top > 2) | ||
|  | 		{ | ||
|  | 			if (id / 2 != S && id / 2 != T) | ||
|  | 			{ | ||
|  | 				if (i == top - 1) | ||
|  | 					nearClip[points[S]] = make_pair(id / 2, id % 2); | ||
|  | 				if (i == 2) | ||
|  | 					nearClip[points[T]] = make_pair(id / 2, id % 2); | ||
| 
											1 year ago
										 | 			} | ||
|  | 		} | ||
| 
											1 year ago
										 | 		// if(i!=top&&i!=1)pclipSet->addwire(id,dia);
 | ||
| 
											1 year ago
										 | 		path.points.push_back(points[id / 2]); | ||
| 
											1 year ago
										 | 		if (i != top && i != 1 && id / 2 < pnum) | ||
|  | 			path.inOut.push_back(id % 2); | ||
|  | 		else | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			path.inOut.push_back(-1 - id % 2); | ||
|  | 		} | ||
|  | 		prePos.push_back(preBranchPointPos[id]); | ||
|  | 	} | ||
| 
											1 year ago
										 | 	for (int i = 0; i < path.points.size(); i++) | ||
|  | 	{ | ||
|  | 		P &p = path.points[i]; | ||
|  | 		if (p.type == 1 || p.type == 2) | ||
|  | 		{ | ||
| 
											1 year ago
										 | 			int mode = -1 - path.inOut[i]; | ||
|  | 			int bid = p.ref; | ||
| 
											1 year ago
										 | 			BranchPoint *pb = branchPointSet.getBranchPointPointer(bid); | ||
| 
											1 year ago
										 | 			pb->mode = mode; | ||
| 
											1 year ago
										 | 			if (mode == 1) | ||
|  | 			{ | ||
| 
											1 year ago
										 | 				pb->t = prePos[i + 1]; | ||
|  | 				pb->recordPos(1); | ||
|  | 			} | ||
|  | 		} | ||
|  | 	} | ||
|  | } |