I'm working on a GA. My problem is as follows. I have a fitness function which takes a couple of values:
A - value which is huge, but less important for example 999999. (weight of importance 30% of the final result)
B - value couple times smaller but more important for example 50. (weight of importance 70% of final result)
I assume that both of these values strive to infinity. How to build a fitness function where I have something like:
long calculateFitness(A, weightOfA, B, weightOfB);
and the result will be any long number which will put B variable as much more important.
You need an upper bound and lower bound for each objective value. If it is not possible to estimate the upper bound (lower bound) you could consider the highest (lowest) values at your current iteration.
Let the upper bound for objective A and B be respectively ubA and ubB, and lower bounds for objective A and B be lbA and lbB. Here I assume that lbA and lbB are equal to 0, and ubA and ubB are respectively 999999 and 50.
Now assume that you have a valueA = 642465 and a valueB = 47. You could do:
let lbA = 0;
let ubA = 999999;
let valueA = 642465
let lbB = 0;
let ubB = 50
let valueB = 47
let remappedA = remap(valueA, lbA, ubA, 0, 1);
let remappedB = remap(valueB, lbB, ubB, 0, 1);
let weightedValue = getWeightedValue(0.3, remappedA, 0.7, remappedB);
console.log(valueA + ' remapped to ' + remappedA);
console.log(valueB + ' remapped to ' + remappedB);
console.log("Weighted objective value: " + weightedValue);
function remap(n, start1, stop1, start2, stop2) {
return ((n - start1)/(stop1 - start1)) * (stop2 - start2) + start2;
}
function getWeightedValue(weightA, valueA, weightB, valueB){
return weightA * valueA + weightB * valueB;
}
Your output value should be 0.8507396927396926