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


C++ graph::setColor方法代码示例

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


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

示例1: exhaustiveColoring

//method finds coloring of graph to minimize conflicts
//returns number of conflicts
int exhaustiveColoring(graph &g, int numColors, int t) {
	//vector to hold answer with least conflicts seen so far
	//initially ever node is color 1
	vector<int> bestAnswer(g.numNodes(), 1);
	//vector to hold answer currently being tested
	//also set to all color 1
	vector<int> currentAnswer = bestAnswer;
	//int to hold number of conflicts in bestAnswer
	//initialized to max number of cnflicts for given graph
	int conflicts = g.numEdges();
	//initilize starting time
	double startTime = (double) (clock() / CLOCKS_PER_SEC);

	//while time elapsed is within given time
	while ( (double)(clock() / CLOCKS_PER_SEC) - startTime < t) {
		//change graph to have coloration of currentAnswer
		for (int i = 0; i < currentAnswer.size(); i++) {
			g.setColor(i, currentAnswer[i]);
		}
		//if current graph is asgood as or better than best graph
		//set best graph to current graph
		if (g.numConflicts() <= conflicts) {
			conflicts = g.numConflicts();
			bestAnswer = currentAnswer;
		}
		//break if all permutations of colors have been tested
		//algorithm is done
		if (!increment(currentAnswer, numColors)) {
			break;
		}
	}
	//set coloration of graph to best rsult
	for (int i = 0; i < bestAnswer.size(); i++) {
		g.setColor(i, bestAnswer[i]);
	}
	return conflicts;
}
开发者ID:willderivera,项目名称:special-topics,代码行数:39,代码来源:graphColor.cpp

示例2: naturalGreedyColoring

//unmodified natural greedy algortihm
//
int naturalGreedyColoring(graph &g, int numColors, int t) {
	//vector to hold answer with least conflicts seen so far
	//initially ever node is color 0
	//can be usd in testing
	//vector<int> answer(g.numNodes(), 0);

	//iterate over all nodes
	for (int n = 0; n < g.numNodes(); n++) {
		//can be used in testing
		//answer[n] = g.getfirstAvailColor(n, numColors);
		
		//pick color with fewest conflicts and assign to node
		g.setColor(n,  g.getfirstAvailColor(n, numColors));
	}
	return g.numConflicts();
}
开发者ID:willderivera,项目名称:special-topics,代码行数:18,代码来源:graphColor.cpp


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