Ejemplo n.º 1
0
// Performs a planarity test on a biconnected component
// of G. numbering contains an st-numbering of the component.
void FastPlanarSubgraph::planarize(
	const Graph &G,
	NodeArray<int> &numbering,
	List<edge> &delEdges)
{
	node v;

	NodeArray<SListPure<PlanarLeafKey<whaInfo*>* > > inLeaves(G);
	NodeArray<SListPure<PlanarLeafKey<whaInfo*>* > > outLeaves(G);
	Array<node> table(G.numberOfNodes()+1);

	forall_nodes(v,G)
	{
		edge e;
		forall_adj_edges(e,v)
		{
			if (numbering[e->opposite(v)] > numbering[v])
				// sideeffect: ignores selfloops
			{
				PlanarLeafKey<whaInfo*>* L = OGDF_NEW PlanarLeafKey<whaInfo*>(e);
				inLeaves[v].pushFront(L);
			}
		}
		table[numbering[v]] = v;
	}
Ejemplo n.º 2
0
// Performs a planarity test on a biconnected component
// of G. numbering contains an st-numbering of the component.
bool CconnectClusterPlanar::doTest(
	Graph &G,
	NodeArray<int> &numbering,
	cluster &cl,
	node superSink,
	EdgeArray<edge> &edgeTable)
{
	bool cPlanar = true;

	NodeArray<SListPure<PlanarLeafKey<IndInfo*>* > > inLeaves(G);
	NodeArray<SListPure<PlanarLeafKey<IndInfo*>* > > outLeaves(G);
	Array<node> table(G.numberOfNodes()+1);

	for(node v : G.nodes)
	{
		for (adjEntry adj : v->adjEntries) {
			if (numbering[adj->twinNode()] > numbering[v])
				//sideeffect: loops are ignored
			{
				PlanarLeafKey<IndInfo*>* L = OGDF_NEW PlanarLeafKey<IndInfo*>(adj->theEdge());
				inLeaves[v].pushFront(L);
			}
		}
		table[numbering[v]] = v;
	}

	for(node v : G.nodes)
	{
		for (PlanarLeafKey<IndInfo*>* L : inLeaves[v])
		{
			outLeaves[L->userStructKey()->opposite(v)].pushFront(L);
		}
	}

	PlanarPQTree* T = new PlanarPQTree();

	T->Initialize(inLeaves[table[1]]);
	for (int i = 2; i < G.numberOfNodes(); i++)
	{
		if (T->Reduction(outLeaves[table[i]]))
		{
			T->ReplaceRoot(inLeaves[table[i]]);
			T->emptyAllPertinentNodes();

		}
		else
		{
			cPlanar = false;
			break;
		}
	}
	if (cPlanar && cl && superSink)
	{
		// Keep the PQTree to construct a wheelgraph
		// Replace the edge stored in the keys of T
		// by the original edges.
		// Necessary, since the edges currently in T
		// correspond to a graph that mirrors a biconnected
		// component and thus is deallocated

		int n = G.numberOfNodes();

		for (PlanarLeafKey<IndInfo*>* info : outLeaves[table[n]])
		{
			PQLeafKey<edge,IndInfo*,bool>* key = (PQLeafKey<edge,IndInfo*,bool>*) info;
			key->m_userStructKey = edgeTable[key->m_userStructKey];
		}

		m_clusterPQTree[cl] = T;

	}
	else //if (cPlanar)
		delete T;

	// Cleanup
	for(node v : G.nodes)
	{
		if (v != superSink || !cPlanar)
		{
			while (!outLeaves[v].empty())
			{
				PlanarLeafKey<IndInfo*>* L = outLeaves[v].popFrontRet();
				delete L;
			}
		}
	}

	return cPlanar;
}