2

I am trying to find best subset of set. Imagine that we need to find subset of objects. We have got some fitness function for this subset. So at the beginning we should make a population of subsets and then using GA we should try to find the best subset.

I would like to use Jenetics.io but I do not know how to use it in this case. Problem for me is that chromosomes are much different data structure than subset.

I would like to have a function( population, fitness function) which makes all needed job.

I tried to understand how Jenetics exactly works. Maybe I am wrong but I think there is no way to make it works the way I want.

Please give me advice , maybe there is option to use Jenetics in this case?

beatngu13
  • 7,201
  • 6
  • 37
  • 66
tomo_s
  • 35
  • 7

1 Answers1

1

There is a sub-set example in the Jenetics library. Essentially, it has the following form:

class SubsetExample
    implements Problem<ISeq<MyObject>, EnumGene<MyObject>, Double>
{
    // Define your basic set here.
    private final ISeq<MyObject> basicSet = ISeq.empty();
    private final int subSetSize = 5;

    @Override
    public Function<ISeq<MyObject>, Double> fitness() {
        return subSet -> {
            assert(subset.size() == subSetSize);
            double fitness = 0;
            for (MyObject obj : subSet) {
                // Do some fitness calculation
            }

            return fitness;
        };
    }

    @Override
    public Codec<ISeq<MyObject>, EnumGene<MyObject>> codec() {
        return codecs.ofSubSet(basicSet, subSetSize);
    }

    public static void main(final String[] args) {
        final SubsetExample problem = new SubsetExample()

        final Engine<EnumGene<MyObject>, Double> engine = Engine.builder(problem)
            .minimizing()
            .maximalPhenotypeAge(5)
            .alterers(
                new PartiallyMatchedCrossover<>(0.4),
                new Mutator<>(0.3))
            .build();

        final Phenotype<EnumGene<MyObject>, Double> result = engine.stream()
            .limit(limit.bySteadyFitness(55))
            .collect(EvolutionResult.toBestPhenotype());

        System.out.print(result);
    }
}
  • Thank you very much. I do not why but I have not seen this example. I will try to use it. – tomo_s Apr 04 '17 at 13:13
  • Is there an option to prepare my own population and then using Jenetics library mutate subsets from this population to find best ? I am trying to solve Nurse Scheduling problem with GA, and scheduler consists of the tuples [employee, start time, end time]. – tomo_s Apr 05 '17 at 12:24
  • Jenetics also allows the initialization with a start population (Engine.stream(genotypes). For the Nurse Scheduling Problem, your "population" is the basic set, where you want to choose a sub-set from, I think. – Franz Wilhelmstötter Apr 05 '17 at 13:51
  • After I analyzed this example I decided to use something very similar. In documentation I found codecs.ofSubSet(final ISeq extends T> basicSet). I did it because I do not know how big should be size of best subset. So everything look same but I have to use BitGene instead of EnumGene. Fitness function rates how subset fulfills requirements for the scheduler. Is there is something to do to make it works faster? What kind of selector is the best option? – tomo_s Apr 05 '17 at 14:32
  • I would add a SwapMutator for this kind of problems. Since usually most of the time is spent in the fitness function, its mostly on you to make it fast. – Franz Wilhelmstötter Apr 05 '17 at 16:11