当前位置: 首页>>代码示例>>C++>>正文


C++ MultilevelGraph::postMerge方法代码示例

本文整理汇总了C++中MultilevelGraph::postMerge方法的典型用法代码示例。如果您正苦于以下问题:C++ MultilevelGraph::postMerge方法的具体用法?C++ MultilevelGraph::postMerge怎么用?C++ MultilevelGraph::postMerge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MultilevelGraph的用法示例。


在下文中一共展示了MultilevelGraph::postMerge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: buildOneLevel

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;
}
开发者ID:marvin2k,项目名称:ogdf,代码行数:58,代码来源:RandomMerger.cpp

示例2: buildOneLevel

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;
}
开发者ID:marvin2k,项目名称:ogdf,代码行数:89,代码来源:MatchingMerger.cpp


注:本文中的MultilevelGraph::postMerge方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。