fitness function with more than one parameters
See original GitHub issueDoes Jenetics even support fitness function with multiple parameters??
I have the following fitness function
public static double func(double a, double b, double c) {
// f(a, b, c) = 3 * cos(a)^4 + 4 * cos(b)^3 + 2 sin(c)^2 * cos(c)^2 + 5
return 3 * Math.pow(Math.cos(a), 4) + 4 * Math.pow(Math.cos(b), 3) +
2 * Math.pow(Math.sin(c), 2) * Math.pow(Math.cos(c), 2) + 5;
}
Is the following use of Codec.of correct???
final Codec<Double, DoubleGene> PARAM = Codecs.ofScalar(DoubleRange.of(1, Math.PI));
final Codec<Double, DoubleGene> CODEC = Codec.of(
ISeq.of(PARAM, PARAM, PARAM),
params -> {
final double param1 = (double) params[0];
final double param2 = (double) params[1];
final double param3 = (double) params[2];
return 0.0;
}
);
final Engine<DoubleGene, Double> engine = Engine
.builder(JeneticsDemo6::func, CODEC)
.populationSize(500)
.optimize(Optimize.MAXIMUM)
.offspringSelector(new StochasticUniversalSelector<>())
.alterers(new Mutator<>(0.03), new MeanAlterer<>(0.5))
.build();
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Passing multiple parameters to the fitness function
I'm trying to pass one more argument to my fitness function: def eval_fitness(individual, mode):. When I call "toolbox.evaluate(individual, mode)" it works, ...
Read more >How to define a Fitness Function in a Genetic Algorithm?
Given a set of 5 genes, which can hold one of the binary values 0 and 1, we have to come up with...
Read more >Coding and minimizing a fitness function using the Genetic ...
This is a demonstration of how to create and minimize a fitness function using the Genetic Algorithm in the Genetic Algorithm and Direct...
Read more >returning additional values from a fitness function for genetic ...
Is there a simple way to return additional values from a fitness function (in addition to the objective value) when using an optimisation...
Read more >Should all the variables in a fitness function be the same in ...
Let's say my fitness function will be cost(a) + cost(b) + cost(c) + cost(d), where the unit for cost(a) and cost(b) is in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @zollen, your fitness function can’t have more than one parameter. If you need three double values, you have to wrap it into an array. There are predefined factory methods for doing this:
The example above will do the trick.
You have two possibilities in this situation. 1) you can only create valid values, the simpler one, or 2) you can use the
Constraintinterface.Ad 1)
Ad 2)
I would prefer the first version, since it doesn’t create invalid values. In version 2) you have to add the
Constraintto the engine builder.