I developed a software implementation of Ant Colony Optimization to solve the Traveling Salesman Problem, but due to ACO's stochastic nature, each execution of the ACO algorithm produces a different near optimal solution every time. Is there a way to make ACO more deterministic? I understand that it will never be 100% deterministic but I need it to be able to run multiple times on the same problem space and at least come up with a similar solution most of the time. I've tried tweaking α, β, ρ and number of iterations but I'm just shooting in the dark at this point.
As Michael already stated as a comment: use a seeded pseudo random number generator (PRNG) and reuse the same all over your implementation.
In Java, do something like this:
Random workingRandom = new Random(0L);
// Never use Math.random(), always use workingRandom.next*() instead
There are a couple of other things you might need to disable (especially in multi-threaded implementations) to have 100% reproducibility, some of which I discuss in my implementation's docs section 4.4.3.4. REPRODUCIBLE (such as replacing HashMap
by LinkedHashMap
when needed).