martin-fleck / momot

Marrying Search-based Optimization and Model Transformation Technology
http://martin-fleck.github.io/momot/
17 stars 6 forks source link

ProgressListener that returns current population? #7

Open sherzig opened 7 years ago

sherzig commented 7 years ago

Is there a way to return the current population using a progress listener? I've tried to do this by retrieving the approximation set through the executor and instrumenter accessible from the event. However, it's returned null / an empty list. Any clues?

Thanks

martin-fleck-at commented 7 years ago

Hi Sebastian,

Actually, my assumption would have been that it works with the progress listener. In fact, there is a class that already those that partially [1]. The problem seems to be that the Instrumenter.getLastAccumulator() [2] method from MOEA returns null. In the MOEA framework, an accumulator stores collected data from a single run of an algorithm. The instrumenter used in MOMoT collects these accumulators to gather the necessary data during the execution. Unfortunately, I do not have the time to debug into this right now. Maybe an update on a newer version of MOEA fixes this issue, but I did not check. Hopefully, I could point you in the right direction and sorry for not being able to provide a more positive answer.

[1] https://github.com/martin-fleck/momot/blob/master/plugins/at.ac.tuwien.big.moea/src/at/ac/tuwien/big/moea/experiment/executor/listener/CollectiveProgressListener.java [2] http://moeaframework.org/javadoc/org/moeaframework/Instrumenter.html

sherzig commented 7 years ago

No problem! Thanks for the pointers - I will have a closer look and submit a pull request if I find the solution.

sherzig commented 7 years ago

OK, I think I found the solution. First off, I've migrated MOMoT (mostly) to MOEA 2.12. As for the approximation set:

  1. SearchExperiment.java defines a method setAllCollectors(boolean). However, this function is never called (anywhere, from what I can tell).
  2. Collectors can be defined in the .momot file under experiment - however, there seems to be a bug in the grammar that requires both a "built-in" collector (e.g., approximationSet as a key) and a custom collector class (e.g., "new SimpleBestSolutionCollector()"). With these settings, the generated code enables the approximationSet collector and adds a custom collector:
experiment = {
    ...
    collectors = [ approximationSet new SimpleBestSolutionCollector() ]
    // Must appear as last entry, otherwise compilation error is thrown
}

As mentioned in the comment, this must also appear as the last line in the experiment section.

With the above, I can access the approximation set from the accumulator. It seems that by default only the NFE is collected.

BTW, I found a couple of other smaller bugs along the way - e.g., AccumulatorUtil.getLatestAlgorithm returns an object of type Solution, which should probably be an Algorithm instead.

I'll send you a pull request once I've completed testing.