Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pigLoveRabbit520 opened this issue Feb 24, 2024 · 1 comment
Open

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

pigLoveRabbit520 opened this issue Feb 24, 2024 · 1 comment

Comments

@pigLoveRabbit520
Copy link

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;
}
@zyx999
Copy link

zyx999 commented Feb 24, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants