Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization Tips #10

Open
flo-wolf opened this issue Oct 24, 2020 · 1 comment
Open

Optimization Tips #10

flo-wolf opened this issue Oct 24, 2020 · 1 comment

Comments

@flo-wolf
Copy link

flo-wolf commented Oct 24, 2020

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:

  • ControllerMap in Optimizer.cs keeps growing each Generation, since no Key ever gets removed, only added.
  • For each UnitController one Coroutiner instance is created, which can be streamlined by only having one MonoBehaviour instance that handles all Coroutines, greatly decreasing Instantiation calls on each generation start.
  • I would also suggest to use MEC instead of Unity Coroutines, MEC's are around 10x faster.
  • Lastly object pooling is advisable, so that the cars don't actually get destroyed and reinstantiated with every new generation, but only reset, which would pretty much elimiate Instantiation calls during evolving.

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
Copy link
Author

flo-wolf commented Nov 7, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant