# Genetic Algorithms: Converge to best solution for one, few or many environments?

Let's say we take someone's garden (A) as the environment. We want a robot to pick up a series of eggs that chickens have laid in the garden, while covering as little ground as possible (those heavy rover tracks damage the turf, you know). So we evolve a solution whereby the genes representing the robot's behaviour (i.e. we are not just evolving some chain of path states/positions) work great in that garden.

All freshly laid eggs in (A) are collected in record time. Our algorithm has learned some tricks about navigating gardens; like driving a car for the first time. But there is more.

If I now put the same robot in a different garden (B), it may or may not do OK. It depends, I suppose, on how similar (B) is to (A) in certain key factors, i.e., will any of the tricks learned in (A) apply here? The likelihood is it will need new tricks, so I'm going to have evolve it further in (B) if I want anything like an optimal solution. Yet if I don't, at every iteration, continue to test it in (A) too, then I may be losing fitness for (A) in every new generation, yes?

So if I want a algorithm that performs well under a wide variety of circumstances, I am going to have to test it in all of those N circumstances, for all of the M candidates; will I thus need to run MxN tests on each generation? What about circumstances I didn't cover?

• I don't think genetic algorithms are suited to your situation, at all. You should never stop adapting to changing circumstances, and you'd have to have a fleet of robots that try different strategies simultaneously. With only a single robot which you want to ship with a fixed programming, I think a rule-based approach is more promising. That said, if you can scan the whole garden, the single robot can internally simulate many behaviours with many virtual copies of itself, and decide on what to do before leaving. – Raphael Aug 12 '16 at 9:10
• @Raphael OK, thank you. The robot / garden was an abstract example, very distantly related to what I am in fact trying to achieve. The actual situation does involve simulation, not physical circumstances, meaning I would need to run several / many simulations in parallel to determine fitness for a given gene set. If you would like to put your comment into an answer, I will be glad to accept. – Engineer Aug 12 '16 at 9:39
• I'm not an expert and my comment reflects my opinion only. Hence I don't think it should become an answer. – Raphael Aug 12 '16 at 9:40

Unless you define "wide variety" very precisely and prove that your algorithm is able to abstract over all varieties in the way you want, then yes, you'll have to test it every time. I think for most interesting problems you won't be able to produce such a proof.

For a related entertaining read, check Neural Network Follies. The author describes a project where a neural network was trained to spot tanks in images. Instead the network learned how to tell whether it's sunny or not.

• Ah, yes, the dangers of overfitting. – Raphael Aug 12 '16 at 9:43
• Reminds me of Pentagon Wars! :D – Engineer Aug 12 '16 at 9:46

To answer this question, we can just look at the real world. Because you are talking about genetic algorithms let's look at the evolution.

A giraffe is trained in Garden A(African Savannah) for thousand of years and now almost optimal(but still slowly evolving). You are now taking it to Garden B(North Pole) and expecting it to survive just because it knows to survive in a low food supply area. If you have to much time, the giraffe population will adapt to North Pole but it will leave it's abilities that is suited for Africa. For Example, it will become white to hide itself inside ice , have more hair etc. When you put it back to Garden A, it's fitness will absolutely fall.

The only species I know that can live through different environments without to long adaptation is human. You can put an African baby in north pole and it will learn how to survive when he is 20 years old. For Giraffe that adaptation will take probably thousand of years.

Back to your question, you can train your robot in different environment until it's fitness is optimal for one environment but as soon as you move to the next environment, the previous adaptation will fall and it will leave you in a vicious cycle where you only train your robot but can not maximize it's effectiveness.

• I'm pretty sure that an African baby will die quickly when you put it somewhere close to the north pole. Probably faster than a Giraffe in the same spot. – adrianN Aug 12 '16 at 13:36
• What i meant was, an eskimo teach him the tricks he should learn to survive in North pole in 20 years. The baby being african does not prevent him learning eskimo knowledge. – atayenel Aug 12 '16 at 13:50