If you want the best solution, you need to evaluate all permutations.
Often, a good enough solution is sufficient.
If you can define a "good enough" criterion, you can define a break condition to stop searching.
E.g. (pseudo code):
iteration = MaxIterations;
best = none;
while (iteration-- > 0)
{
curr = GetNextPermutation();
best = Min(best, curr)
if (AcceptedLimit(curr)) break;
}
DoSomething(best);
You have to design (not implement) first the
GetNextPermutation()
function, the
Min()
function, and the
AcceptedLimit()
functions.
Once you have an idea on these, you may talk about implementing these.
Cheers
Andi