[Tutor] Encoding and Decoding
Kent Johnson
kent37 at tds.net
Tue Jan 2 19:52:50 CET 2007
Carlos wrote:
> The genetic algorithm that Im using (GA) generates solutions for a given
> problem, expressed in a list, this list is composed by integers. Every
> element in the list takes 8 integers, is a little messy but this is because
>
> List [0] = Tens X position
> List [1] = Units X position
> List [2] = Decimals X position
> List [3] = If < than 5 the number is negative, else is positive
>
> Then if the result is List = [6, 1, 2, 3] the X position equals -612.3.
> This is the same for the Y position. If there are 10 elements the list
> is going to be 80 integers long and if there are 100 elements, well you
> get a very long list...
>
> With this in mind my question would be, how can I keep track of this
> information? I mean how can I assign this List positions to each
> element? This is needed because this is going to be a long list and the
> GA needs to evaluate the position of each element with respect to the
> position of the other elements. So it needs to know that certain numbers
> are related to certain element and it needs to have access to the size,
> level, name and parent information... I hope that this is clear enough.
I will assume there is a good reason for storing the coordinates in this
form...
Do the numbers have to be all in a single list? I would start by
breaking it up into lists of four, so if you have 10 elements you would
have a list of 20 small lists. It might make sense to pair the x and y
lists so you have a list of 10 lists of 2 lists of 4 numbers, e.g.
[ [ [6, 1, 2, 3], [7, 2, 8, 4] ], ...]
Another thing to consider is whether you might want to make a class to
hold the coordinate values, then you could refer to x.tens, x.units,
x.decimal, x.sign by name.
If you need a single list for the GA to work, one alternative would be
to make converters between the nested representation and the flat one.
Alternately you could wrap the list in a class which provides helpful
accessors.
HTH
Kent
More information about the Tutor
mailing list