0 1 2 3 4
5 6 7 8 9
A B C D E
06C, 2B9, 48C etc.. are valid vectors, while 05A, 123, 17B etc are all to be discarded.
Ok, I'm having a hard time in resolving this problem. I have a feeling it might be relatively easy if I write a recursive function, but I'd like to stick to iterative code if possible.
I hope what I said makes sense, if you need a description of the original problem just ask. Any hint will be very appreciated :)
Ah, m and n can get quite big, but I doubt they will ever get past 150.
Edit:
Ordering is not important, so 2B9 = 29B = B92. So maybe calling it a subset rather than vector is more appropriate ^^
ga initial population
Hello everyone, I'm trying to generate the initial population for a genetic algorithm, but having certain constraints. I've been able to transform the problem into a more general form, like this:
given an mxn matrix M, and given s = min(m,n), I need to calculate all the m*n vectors of values in M and of length s such that no more than one value in M is taken more than once from the same columns and rows.
For example, if M is like
[ King_DuckZ out-- ]
Take the ranges 0..M and 0..N. Shuffle them both. Then generate a list of pairs, one from the first range and one from the second range, until you have 's' pairs. These pairs are your row,column coordinates within the matrix, allowing you to select the required value from it.
Interestingly enough, what you are looking for seems to be similar to a steiner triple system from combinatorial design. There is an algorithm that can be used to generate the solution set (a set of triples) along with a way to determine exactly how many triples you'll have. I'll need to look it up to get the details, but that seems to be what you want to look for. Also, the standard generating technique uses a idempotent latin square.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement