Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

计算适应度的函数是不是有点问题? #4

Open
@rabbitLove520

Description

function calAdaptability(chromosomeMatrix) {
 adaptability = [];
 // 计算每条染色体的任务长度
 for (var chromosomeIndex=0; chromosomeIndex<chromosomeNum; chromosomeIndex++) {
 var maxLength = Number.MIN_VALUE;
 for (var nodeIndex=0; nodeIndex<nodeNum; nodeIndex++) {
 var sumLength = 0;
 for (var taskIndex=0; taskIndex<taskNum; taskIndex++) {
 if (chromosomeMatrix[chromosomeIndex][taskIndex] == nodeIndex) {
 sumLength += timeMatrix[taskIndex][nodeIndex];
 }
 }
 if (sumLength > maxLength) {
 maxLength = sumLength;
 }
 }
 // 适应度 = 1/任务长度
 adaptability.push(1/maxLength);
 }
}

我看了代码,chromosomeMatrix[chromosomeIndex][taskIndex]存的就是节点索引吧,外面的for (var nodeIndex=0; nodeIndex<nodeNum; nodeIndex++) { 这个循环没必要吧,直接这样就可以吧

var maxLength = Number.MIN_VALUE;
var sumLength = 0;
for (var taskIndex=0; taskIndex<taskNum; taskIndex++) {
 var nodeIndex = chromosomeMatrix[chromosomeIndex][taskIndex]
 sumLength += timeMatrix[taskIndex][nodeIndex];
}
if (sumLength > maxLength) {
 maxLength = sumLength;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /