Change interface between problem and algorithm
|Reported by:||abeham||Owned by:||swagner|
The more problems and the more algorithms we add to HeuristicLab the larger the collection of operators becomes that is shared between them. Additionally the problem stores all these operators while they are actually only needed in the algorithm. So to say the Problem is an operator-provider and the algorithm is an operator-consumer.
Currently the main interface (apart from a few parameters) between these two entities is the Operators property that returns a list of operators.
I would suggest a different approach in that the provider creates and parameterizes the operators, but then forgets about them. To sync them it offers a method as a service for the algorithm and a notification of when a sync is necessary.
- Remove storing the operators in the problem and keep only the evaluator and solution creator.
- Change the Operators property to discover and wire the operators with each call to its get accessor.
- Create a RewireOperators event that the problem fires whenever it would need to rewire the operators collection
- Use the OperatorsChanged event such that the problem fires whenever there would be a change to the discovery of operators.
- Have the algorithm call the problem's new RewireOperators(IList<IOperator>) method upon receiving the event giving it the list of operators that the algorithm is currently holding.
- Have the algorithm call the problem's Operators property to get a fresh list of operators whenever the problem fires the OperatorsChanged event.
That way the operators need to be stored on the algorithm side and the algorithm can throw out anything it does not need and thus saves memory and disk space.
We could even go one step further and not discover the operators in the problem, but in the algorithm (since the algorithm knows which operators it needs: e.g. all ICrossover operators) and then hand them to the problem for wiring service. Only the analyzers would need to be obtained from the problem. On the other hand, the problem would need to indicate or weed out all operators that do not fit.