public Ranking(SolutionSet solutionSet) {
solutionSet_ = solutionSet;
// dominateMe[i] contains the number of solutions dominating i
int[] dominateMe = new int[solutionSet_.size()];
// iDominate[k] contains the list of solutions dominated by k
List<Integer>[] iDominate = new List[solutionSet_.size()];
// front[i] contains the list of individuals belonging to the front i
List<Integer>[] front = new List[solutionSet_.size() + 1];
// flagDominate is an auxiliar encodings.variable
int flagDominate;
// Initialize the fronts
for (int i = 0; i < front.length; i++)
front[i] = new LinkedList<Integer>();
// -> Fast non dominated sorting algorithm
// Contribution of Guillaume Jacquenot
for (int p = 0; p < solutionSet_.size(); p++) {
// Initialize the list of individuals that i dominate and the number
// of individuals that dominate me
iDominate[p] = new LinkedList<Integer>();
dominateMe[p] = 0;
}
for (int p = 0; p < (solutionSet_.size() - 1); p++) {
// For all q individuals , calculate if p dominates q or vice versa
for (int q = p + 1; q < solutionSet_.size(); q++) {
flagDominate = constraint_.compare(solutionSet.get(p), solutionSet.get(q));
if (flagDominate == 0) {
flagDominate = dominance_.compare(solutionSet.get(p), solutionSet.get(q));
}
if (flagDominate == -1) {
iDominate[p].add(q);
dominateMe[q]++;
} elseif (flagDominate == 1) {
iDominate[q].add(p);
dominateMe[p]++;
}
}
// If nobody dominates p, p belongs to the first front
}
for (int p = 0; p < solutionSet_.size(); p++) {
if (dominateMe[p] == 0) {
front[0].add(p);
solutionSet.get(p).setRank(0);
}
}
// Obtain the rest of fronts
int i = 0;
Iterator<Integer> it1, it2; // Iterators
while (front[i].size() != 0) {
i++;
it1 = front[i - 1].iterator();
while (it1.hasNext()) {
it2 = iDominate[it1.next()].iterator();
while (it2.hasNext()) {
int index = it2.next();
dominateMe[index]--;
if (dominateMe[index] == 0) {
front[i].add(index);
solutionSet_.get(index).setRank(i);
}
}
}
}
// <-
ranking_ = new SolutionSet[i];
// 0,1,2,....,i-1 are front, then i fronts
for (int j = 0; j < i; j++) {
ranking_[j] = new SolutionSet(front[j].size());
it1 = front[j].iterator();
while (it1.hasNext()) {
ranking_[j].add(solutionSet.get(it1.next()));
}
}
} // Ranking
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)