eaopt icon indicating copy to clipboard operation
eaopt copied to clipboard

Feature/implement genome marshaling

Open matthewmcneely opened this issue 6 years ago • 5 comments
trafficstars

@MaxHalford ~~This is my first pass at adding Population marshaling to the repo. There are some issues with serializing the GA object, namely issues with interfaces (Model, Migrator, etc) that definitely could be solved, but beyond the immediate goal which I think is being able to restart a Minimize run from where a GA's population has left off.~~ See below, the entire GA is now marshaled.

~~In this branch, when creating a GA one can add an io.Reader and/or io.Writer. If a Reader is present, then the Populations will be regenerated from the marshaled data. Likewise, if a Writer (and a Context) is present, then GA will attempt to marshal the populations on exit.~~

JSON encodings are supported. See the Vector implementation in setup_test.go for what's required to marshal concrete objects that implement Genome.

Have a look, if you're cool with the direction it's going I'll update the documentation and remove the Work in Progress status of this PR.

matthewmcneely avatar Oct 18 '19 21:10 matthewmcneely

Pull Request Test Coverage Report for Build 299

  • 100 of 119 (84.03%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.02%) to 97.769%

Changes Missing Coverage Covered Lines Changed/Added Lines %
population.go 37 46 80.43%
ga.go 63 73 86.3%
<!-- Total: 100 119
Totals Coverage Status
Change from base Build 293: -1.02%
Covered Lines: 1709
Relevant Lines: 1748

💛 - Coveralls

coveralls avatar Oct 18 '19 21:10 coveralls

Hey there. I like the idea and the work you've visibly put into this. The only I'm not comfortable with is that the writing occurs when the GA stops. Instinctively I would have implemented a Save(w io.Writer) method which can be called whenever I like. What you've done is fine, but it feels a bit too "magic". Moreover I'm not sure a lot of users will quickly understand how the context field works. It's definitely useful and in the right direction though :).

MaxHalford avatar Oct 21 '19 07:10 MaxHalford

I agree. The thread that monitors the Context is probably a bit too "automagic". There is the GA::Marshal method which can be called at anytime. I'll remove the Context monitoring and leave it to the implementer to decide when to write the Populations.

matthewmcneely avatar Oct 21 '19 14:10 matthewmcneely

@MaxHalford Ready for review again. One issue to be aware of that I discovered during testing is that sometimes, a population can exist (and be marshaled) in which no individual has better fitness than the hof. And because I'm not marshaling the hof, that work gets lost. Probably not a big deal, just wanted to point it out.

Let me know if you're good and I'll update the documentation in this branch so that it can all be merged at once.

matthewmcneely avatar Oct 24 '19 13:10 matthewmcneely

@MaxHalford After spending more time with my marshaling branch, I made some changes to this PR.

  • add support for storage of the entire GA (minus config parts). I found that NOT having the HAF individuals(s) stored is not ideal when populations evolve away from the fittest. It's nice to have the HAF reinstated. Also, the GA's duration and generations count are maintained.
  • I dropped support for GOB encoding. It added a lot of complication to the codebase and the representation in JSON is probably good enough.
  • I removed the need to set an io.Reader in the GA config. Now one can simply perform idiomatic JSON marshaling operations, like so:
// encode a GA into a byte array
b, _:= json.Marshal(ga)

// decode from a byte array representing a GA
ga, _ := config.NewGA()
ga.GenomeJSONUnmarshaling = myGenomeUnMarshaler
err = ga.UnmarshalJSON(b)

matthewmcneely avatar Nov 26 '19 02:11 matthewmcneely

Hey @matthewmcneely! I'm not really maintaining eaopt anymore, but if you're using it, I'd be glad to merge PRs if that helps. Do you need any review/feedback?

MaxHalford avatar Feb 26 '23 21:02 MaxHalford

Hey @MaxHalford, Sorry I didn't realize that modifying my fork would trigger a notification to you.

Feel free to ignore, I'm working exclusively in my fork now. I'll delete the PR so you're not notified going forward.

matthewmcneely avatar Feb 27 '23 21:02 matthewmcneely