I would like to design an application that can allocate resources according to rules. I believe simulated annealing would work, but I am not too familiar with it and I was wondering if there were alternative algorithms that might be suitable.
For example if I had a grid, and I could color each cell in the grid, I would like to design an algorithm that would find an optimum or close-to-optimum solution for a rule set like the following:
- 1000x1000 grid
- Must place 500 red cells, 500 blue cells, and 1000 green cells
- A red cell must be touching another red cell
- A blue cell must not be touching another blue cell
- A green cell may only be placed along the edge
- Arrangements can be scored based on the mean distance of the colored cells from the upper-left hand corner
Would simulated annealing be appropriate for this problem? I need an algorithm which can compute a solution reliably quickly (seconds to minutes).
Simulated annealing will get close to the optimal solution pretty fast. However, implementing simulated annealing correctly (which isn't that much code) can be very challenging. Many people (including myself in the past) implement it wrong, think they did it right and presume that the algorithm just isn't that good.
Alternatives algorithms are tabu search, genetic algorithms, simplex, ...
Here's how your constraints would like in Drools Planner (java, open source, ASL):
Now the fun part is: once you have you score rules, you can throw several algorithms (tabu search, simulated annealing, ...) on it (see
Benchmarker
support) and use the best one in production. More information in the reference manual.