Open maluramichael opened 7 years ago
same here!
const Task = require('genetic').Task;
const options = {
getRandomSolution : getRandomSolution,
popSize : 500,
stopCriteria : stopCriteria,
fitness : fitness,
minimize : true,
mutateProbability : 0.1,
mutate : mutate,
crossoverProbability : 0.3,
crossover : crossover
}
const util = require('util');
function crossover(parent1, parent2, callback) {
var child = {}
if (Math.random()>0.5) {
child.a = parent1.a
}
else {
child.a = parent2.a
}
if (Math.random()>0.5) {
child.b = parent1.b
}
else {
child.b = parent2.b
}
if (Math.random()>0.5) {
child.c = parent1.c
}
else {
child.c = parent2.c
}
callback(child)
}
function mutate(solution, callback) {
if (Math.random()<0.3) {
solution.a = Math.random()
}
if (Math.random()<0.3) {
solution.b = Math.random()
}
if (Math.random()<0.3) {
solution.c = Math.random()
}
callback(solution)
}
function getRandomSolution(callback) {
var solution = { a: Math.random(), b: Math.random(), c: Math.random() };
callback(solution)
}
function stopCriteria() {
return (this.generation == 1000)
}
function fitness(solution, callback) {
callback(Math.abs(Math.pow(solution.a,2)+solution.b+solution.c - 10))
}
console.log('=== TEST BEGINS === ')
var
t = new Task(options)
t.on('error', function (error) { console.log('ERROR - ', error) })
t.run(function (stats) {
console.log('results', stats);
})
Same here. Did you find a solution/workaround?
I think there is a problem with the negative scores, and / or when we set "minimize" to true, which is like having negative scores.
same here, I am having the error 2/3 runs, some configurations of crossover won't run at all
Someone got this problem before? I cannot run more than 100 generations.