It is definitely possible to solve this with OptaPlanner, but in my opinion, this wouldn't really be optimal: OptaPlanner tries to solve NP-hard problems using various heuristics - essentially, it purges the search space in one way or the other. It is very improbable that it actually finds the absolute global maximum (or minimum) - although it does probably get quite close.
As far as I can tell, this problem isn't NP-hard and therefore could be solved in polynomial time O(n^k)
where k
is constant.
There are also pseudo-polynomial algorithms, which might also be the case here - the complexity is then dependent on the weight and input size. For example O(w*n^k)
where w
is the biggest weight.
In this case, you would probably be better off going with a dynamic programming solution, as described in the wiki article you linked to. Also, don't forget to introduce some sort of randomization into the weights, or you will always deterministically pick the same set of "best" activities for a given day and a given group of tourists.
Some math to sum it all up:
- 10K activities isn't large at all. Everything you need per activity is: the start time, end time and weight.
- If all these were 32bit integers and you made a Java object, the needed memory is (approximately)
3*4B + 8B (object overhead) = 20B/object
, which is 200 000B
in total, i.e. ~195kB
.
- If you implemented the suggested
O(n^3)
dynamic programming algorithm, the running time with 10K activities would be approximately 10 000^3 / 10^9 (1GHz processor) = 1000 seconds ~ 17 minutes
. This is a very crude estimate. Also, the O(n log n)
algorithm would plow through data of this size (using the same estimation) in 132 ns
.