本文整理汇总了C++中graph::numConflicts方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::numConflicts方法的具体用法?C++ graph::numConflicts怎么用?C++ graph::numConflicts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::numConflicts方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: threeOptSteepestDecent
//method takes a graph and finds the best local optimum using 3-opt neighbors
//returns number of coflicts
int threeOptSteepestDecent(graph &g, bool repeat, int numColors) {
double startTime = (double) (clock() / CLOCKS_PER_SEC);
graph prevBest;
while ( (double)(clock() / CLOCKS_PER_SEC) - startTime < 600) {
do {
if (repeat) {
g.randomize(numColors);
}
prevBest = g;
g = prevBest.threeOptNeighbor(600 + startTime);
if ( (double)(clock() / CLOCKS_PER_SEC) - startTime > 600) {
break;
}
}
while (prevBest.numConflicts() > g.numConflicts());
if (!repeat) {
break;
}
}
return g.numConflicts();
}
示例2: 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;
}
示例3: 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();
}