#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier #include "BranchTree.h" BasicEdge basicEdge; void Edge::clear() { to = 0; dis = 0; wirenames.clear(); d.clear(); } BranchTree::BranchTree() { cnt = 0; bfs = 0; hashuan = 0; record = 0; // branchPointNum=0; dia = 0; // bundleid=0; pclipSet = &clipSet; } void BranchTree::init() { for (int i = 1; i <= cnt; i++) { edge[i].clear(); } nodeid.clear(); cnt = bfs = hashuan = record = 0; } void BranchTree::startRecord() { record = 1; } void BranchTree::endRecord() { record = 0; pathpoints.clear(); } int BranchTree::getid(P &p) { if (nodeid[p] == 0) { nodeid[p] = ++cnt; f[cnt] = cnt; sz[cnt] = 1; vis[cnt] = pre[cnt] = 0; endpoint[cnt] = 0; points[cnt] = p; } return nodeid[p]; } int BranchTree::getrt(int x) { if (x != f[x]) return f[x] = getrt(f[x]); return x; } void BranchTree::merge(int x, int y) { if (x != f[x]) x = getrt(x); if (y != f[y]) y = getrt(y); f[x] = y; sz[y] += sz[x]; } bool BranchTree::check(P &p) { int id = getid(p); for (int i = 0; i < pathpoints.size(); i++) { if (getrt(id) == getrt(pathpoints[i])) return false; } return true; } void BranchTree::addEdge(int x, int y, vector namelist) { if (record) pathpoints.push_back(x); for (int i = 0; i < edge[x].size(); i++) { if (edge[x][i].to == y) { Edge &e = edge[x][i]; e.d.push_back(dia); e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); } } for (int i = 0; i < edge[y].size(); i++) { if (edge[y][i].to == x) { Edge &e = edge[y][i]; e.d.push_back(dia); e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); return; } } Edge e; e.to = y; e.wirenames.insert(e.wirenames.begin(), namelist.begin(), namelist.end()); e.d.push_back(dia); edge[x].push_back(e); e.to = x; edge[y].push_back(e); merge(x, y); pclipSet->addwire(points[y], dia); } bool BranchTree::hasEdge(int x, int y) { for (int i = 0; i < edge[x].size(); i++) { if (edge[x][i].to == y) { return true; } } return false; } vector BranchTree::BFS(int u, int v) { // cout< path; queue q; q.push(u); vis[u] = bfs; pre[u] = 0; while (!q.empty()) { int x = q.front(); q.pop(); for (int i = 0; i < edge[x].size(); i++) { int y = edge[x][i].to; if (vis[y] == bfs) continue; pre[y] = x; vis[y] = bfs; q.push(y); } if (vis[v] == bfs) break; } int top = 0; int tag = v; while (pre[tag]) { // cout< 0; i--) { path.push_back(st[i]); } // cout< &path, vector namelist) { for (int i = 1; i < path.size(); i++) { // cout< pathid; pathid.push_back(0); for (int i = 0; i < path.points.size(); i++) { P p = path.points[i]; int id = getid(p); pathid.push_back(id); } map cross2; for (int i = 1; i <= path.points.size(); i++) { int id = pathid[i]; int rt = getrt(id); if (sz[rt] != 1) { cross2[rt] = i; } } for (int i = 1; i <= path.points.size(); i++) { int id = pathid[i]; int rt = getrt(id); if (cross2[rt] != 0) { int en = cross2[rt]; if (en != i) { vector tempPath = BFS(pathid[i], pathid[en]); newPath(tempPath, path.wirelist); Path path3; for (int j = 0; j < tempPath.size(); j++) { path3.points.push_back(points[tempPath[j]]); } path3.processDir(); path3.inOut[0] = path.inOut[i - 1]; path3.inOut[path3.size() - 1] = path.inOut[en - 1]; for (int j = 0; j < path3.size(); j++) { path2.points.push_back(path3.points[j]); path2.inOut.push_back(path3.inOut[j]); } // if(testhuan())cout<<"BFS"<