"Best fit" to avoid reuse of object instances in a collection
- by Simon
Imagine I have a collection of object instances which represent activities for a user to undertake. Dependent on user attributes, I have to randomly select instances to present activities to the user.
For some users, I need to present more activities to them than there are available activities in which case, I want to use the following algorithm.
If all available activities have already been presented to the user, then re-select a "used" activity, selecting the earliest presented activity ordered by frequency of use. In other words, try to reduce repetition and where repetition is unavoidable, use the instances which have been repeated less often and were presented furthest back in time.
Before I go on to code that algorithm, I wondered if there is some existing pattern I can re-use?
[EDIT] "Furthest back in time" is not relevant as I will pass the algorithm an ordered collection of used instances where the first entry is the first presented.