I am experimenting with the Multi-objective Optimization Problem (MOP) using Jenetics. A toy problem I created is to select two subsets from a given set, maximizing their total sum, given each subset has a limit. However I want to ensure that the two subsets are mutually exclusive. How can I set this constraint when creating Genotype of the two Chromosomes?
The set I'm using for my toy problem is:
private static final ISeq<Integer> SET = ISeq.of( IntStream.rangeClosed( 1, 10 )
.boxed()
.collect( Collectors.toList() ) );
The signature of my problem is:
Problem<List<ISeq<Integer>>, BitGene, Vec<int[]>>
And the codec is:
@Override public Codec<List<ISeq<Integer>>, BitGene> codec() {
Objects.requireNonNull( SET );
final Genotype<BitGene> g =
Genotype.of( BitChromosome.of( SET.length() ), BitChromosome.of( SET.length() ) );
return Codec.of(
g,
gc -> gc.stream().map( z -> z.as( BitChromosome.class ).ones().mapToObj( SET )
.collect( ISeq.toISeq() ) ).collect( Collectors.toList() )
);
}
I have assigned the first subset with a limit of 9 and the second subset with a limit of 4.
I expect an initial population of two chromosomes with mutually exclusive genes such that Phenotype's in the end will yield individuals that do not have items duplicated from the SET
.
An example output I'm currently getting is:
[[4,5], [4]]
But I expect both individuals to have mutually exclusive items. How can this be achieved with Jenetics?