lordjesus / UnityNEAT

Port of SharpNEAT to Unity 4.x and 5.x
125 stars 38 forks source link

Optimization Tips #10

Open flo-wolf opened 3 years ago

flo-wolf commented 3 years ago

I am currently using your repo in Unity 2020.2, and it actually works, which is a good thing!

Though I have stumbled upon a few optimization issues:

Also, as stated in another issue, SimpleExperiement.cs, SimpleEvaluator.cs and Optimzer.cs are too tightly intertwined into the SharpNeat code. It is also quite confusing, since for instance there are two paralel main loops for each generation, one in SimpleEvaluator.cs which creates and deletes the cars, and one in NeatEvolutionAlgorithm.cs, controlling the evolution. Kind of confusing, and prone to race conditions - especially inside UnityParallelListEvaluator.cs in line 82, where we have to hope that the Coroutine that we call there finishes first to add the fitness to the dictionary, since we require the filled dictionary to process the fitness in our main loop. Both coroutines have the same wait time. If the coroutine inside SimpleEvaluator finishes second, then all fitness will be equal to 0. To me it makes little sense why there are so many loops in parallel.

Finally, it's probably best to upgrade to the sharpneat-refactor version of sharpneat, which is far more optimized and... well... refactored. Though at the moment (October 2020) it doesn't support CPPN's yet, which is a nice feature to have. As soon as CPPN's are supported it's worth the upgrade.

flo-wolf commented 3 years ago

I did a full refactor of this repository, solving the issues listed above. It can be found here.