Ejemplo n.º 1
0
void RandomPlacer::placeOneLevel(MultilevelGraph &MLG)
{
	int level = MLG.getLevel();
	DPoint center(0.0, 0.0);
	double radius = 0.0;

	Graph &G = MLG.getGraph();
	double n = G.numberOfNodes();
	if (n > 0) {
		for(node v : G.nodes) {
			center = center + DPoint( MLG.x(v), MLG.y(v) );
		}
		center = DPoint(center.m_x / n, center.m_y / n);
		for(node v : G.nodes) {
			double r = sqrt( MLG.x(v) * MLG.x(v) + MLG.y(v) * MLG.y(v) );
			if (r > radius) radius = r;
		}
		radius *= m_circleSizeFactor;
	} else {
		radius = 10.0 * m_circleSizeFactor;
	}

	while (MLG.getLevel() == level && MLG.getLastMerge() != nullptr)
	{
		placeOneNode(MLG, center, radius);
	}
}
Ejemplo n.º 2
0
bool RandomMerger::buildOneLevel(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	int level = MLG.getLevel() + 1;
	int numNodes = G.numberOfNodes();

	if (numNodes <= 3) {
		return false;
	}

	int index = 0;
	Array<node> candidates(numNodes);
	for(node v : G.nodes) {
		candidates[index] = v;
		index++;
	}

	int candSize = candidates.size();
	while (candSize > numNodes / m_levelSizeFactor)
	{
		index = randomNumber(0, candSize-1);
		node mergeNode = candidates[index];
		candidates[index] = candidates[candSize-1];
		candSize--;
		node parent = nullptr;

		if (mergeNode->degree() > 0) {
			int index = randomNumber(0, mergeNode->degree()-1);
			int i = 0;
			for(adjEntry adj : mergeNode->adjEntries) {
				if (i == index) {
					parent = adj->twinNode();
					break;
				} else {
					i++;
				}
			}
		} else {
			do {
				index = randomNumber(0, candSize-1);
				parent = candidates[index];
			} while (parent == mergeNode);
			candidates[index] = candidates[candSize-1];
			candSize--;
		}

		NodeMerge * NM = new NodeMerge(level);
		bool ret = MLG.changeNode(NM, parent, MLG.radius(parent), mergeNode);
		OGDF_ASSERT( ret );
		MLG.moveEdgesToParent(NM, mergeNode, parent, true, m_adjustEdgeLengths);
		ret = MLG.postMerge(NM, mergeNode);
		if( !ret ) {
			delete NM;
		}
	}

	return true;
}
Ejemplo n.º 3
0
std::vector<node> SolarMerger::selectSuns(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	std::vector<node> suns;
	std::vector<node> candidates;

	node v;
	forall_nodes(v, G) {
		candidates.push_back(v);
	}
Ejemplo n.º 4
0
void RandomPlacer::placeOneLevel(MultilevelGraph &MLG)
{
	int level = MLG.getLevel();
	DPoint center(0.0, 0.0);
	double radius = 0.0;

	Graph &G = MLG.getGraph();
	double n = G.numberOfNodes();
	if (n > 0) {
		node v;
		forall_nodes(v, G) {
			center = center + DPoint( MLG.x(v), MLG.y(v) );
		}
Ejemplo n.º 5
0
void ModularMultilevelMixer::call(MultilevelGraph &MLG)
{
	const Graph &G = MLG.getGraph();

	m_errorCode = ercNone;
	clock_t time = clock();
	if ((m_multilevelBuilder.valid() == false || m_initialPlacement.valid() == false) && m_oneLevelLayoutModule.valid() == false) {
		OGDF_THROW(AlgorithmFailureException);
	}

	if (m_fixedEdgeLength > 0.0) {
		edge e;
		forall_edges(e,G) {
			MLG.weight(e, m_fixedEdgeLength);
		}
Ejemplo n.º 6
0
void IndependentSetMerger::buildAllLevels(MultilevelGraph &MLG)
{
	m_numLevels = 1;
	MLG.updateReverseIndizes();

	std::vector< std::vector<node> > levelNodes;
	Graph &G = MLG.getGraph();

	// calc MIS
	NodeArray<bool> nodeMarks(G, false);
	std::vector<node> IScandidates;
	node v;
	forall_nodes(v, G) {
		IScandidates.push_back(v);
	}
Ejemplo n.º 7
0
void CirclePlacer::placeOneLevel(MultilevelGraph &MLG)
{
	int level = MLG.getLevel();
	DPoint center(0.0, 0.0);
	float radius = 0.0;

	std::map<node, bool> oldNodes;
	Graph &G = MLG.getGraph();
	double n = G.numberOfNodes();
	if (n > 0) {
		node v;
		forall_nodes(v, G) {
			oldNodes[v] = true;
			center = center + DPoint( MLG.x(v), MLG.y(v) );
		}
Ejemplo n.º 8
0
bool RandomMerger::buildOneLevel(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	int level = MLG.getLevel() + 1;
	int numNodes = G.numberOfNodes();

	if (numNodes <= 3) {
		return false;
	}

	node v;
	int index = 0;
	Array<node> candidates(numNodes);
	forall_nodes(v, G) {
		candidates[index] = v;
		index++;
	}
Ejemplo n.º 9
0
bool MatchingMerger::buildOneLevel(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	int level = MLG.getLevel() + 1;
	
	int numNodes = G.numberOfNodes();

	if (level == 1 && m_selectByMass) {
		m_mass.init(G, 1);
	}

	if (numNodes <= 3) {
		return false;
	}

	NodeArray<bool> nodeMarks(G, false);
	std::vector<edge> matching;
	std::vector<node> candidates;

	node v;
	forall_nodes(v, G) {
		candidates.push_back(v);
	}
Ejemplo n.º 10
0
bool MatchingMerger::buildOneLevel(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	int level = MLG.getLevel() + 1;

	int numNodes = G.numberOfNodes();

	if (level == 1 && m_selectByMass) {
		m_mass.init(G, 1);
	}

	if (numNodes <= 3) {
		return false;
	}

	NodeArray<bool> nodeMarks(G, false);
	std::vector<edge> matching;
	std::vector<node> candidates;

	for(node v : G.nodes) {
		candidates.push_back(v);
	}

	while (!candidates.empty())
	{
		int rndIndex = randomNumber(0, (int)candidates.size()-1);
		node one = candidates[rndIndex];
		candidates[rndIndex] = candidates.back();
		candidates.pop_back();

		if (nodeMarks[one]) {
			continue;
		}
		nodeMarks[one] = true;

		std::vector<node> candNeighbors;
		std::vector<edge> candEdges;
		unsigned int minMass = numeric_limits<unsigned int>::max();
		for(adjEntry adj : one->adjEntries) {
			node cand = adj->twinNode();
			if (!nodeMarks[cand] && (!m_selectByMass || m_mass[cand] <= minMass))
			{
				if (m_selectByMass && m_mass[cand] < minMass) {
					minMass = m_mass[cand];
					candNeighbors.clear();
					candEdges.clear();
				}
				candNeighbors.push_back(cand);
				candEdges.push_back(adj->theEdge());
			}
		}
		if (candNeighbors.empty()) {
			continue;
		}
		int index = randomNumber(0, int(candNeighbors.size())-1);
		nodeMarks[candNeighbors[index]] = true;
		matching.push_back(candEdges[index]);
	}

	while (!matching.empty()) {
		edge matchingEdge = matching.back();
		matching.pop_back();

		node mergeNode;
		node parent;

		// choose high degree node as parent!
		mergeNode = matchingEdge->source();
		parent = matchingEdge->target();
		if (mergeNode->degree() > parent->degree()) {
			mergeNode = matchingEdge->target();
			parent = matchingEdge->source();
		}

		NodeMerge * NM = new NodeMerge(level);
		bool ret = MLG.changeNode(NM, parent, MLG.radius(parent), mergeNode);
		OGDF_ASSERT( ret );
		if (m_selectByMass) {
			m_mass[parent] = m_mass[parent] + m_mass[mergeNode];
		}
		MLG.moveEdgesToParent(NM, mergeNode, parent, true, m_adjustEdgeLengths);
		ret = MLG.postMerge(NM, mergeNode);
		if( !ret ) {
			delete NM;
		}
	}

	return true;
}
Ejemplo n.º 11
0
void FastMultipoleEmbedder::call(MultilevelGraph &MLG)
{
	Graph &G = MLG.getGraph();
	call(G, MLG.getXArray(), MLG.getYArray(), MLG.getWArray(), MLG.getRArray());
}