James,
Very nice approach!
-A.
>Michael von Aichberger <[EMAIL PROTECTED]> wrote:
>
>> Imagine you had a given length. Like:
>>
>> length = 315
>>
>> And you needed to cover that length with smaller pieces. You had a set of
>> pieces of a given length, like for instance:
>>
>> piecesL = [13, 27, 35, 48, 90, 111, ...]
>>
>>
>> Now the algorithm I am looking for should chose any number of the pieces in
>> piecesL and add them up the the given length. The pieces can be used several
>> times. If the full length cannot be achieved because of the given values,
>> the one solution should be found that comes closest.
>>
>> So I need a solution in the style of
>>
>> solutionL = [13, 13, 13, 27, 90, 90, ...]
>
>
>Hi Michael,
>
>Here are a couple of solutions to the particular problem that you give:
>
>[27, 27, 27, 27, 27, 90, 90]
>[27, 27, 27, 48, 48, 48, 90]
>
>
>Your problem lends itself nicely to a genetic algorihtm, where a number of
>near solutions are created then combined to produce even nearer solutions.
>Below you will find my full genetic algorithm. Here is the output from my
>message window for my tests, where the solution should add up to 16 and the
>list of lengths are the first nine prime numbers:
>
>genePool = script("Genetics").new()
>put genePool.mFindSolution(16, [2, 3, 5, 7, 11, 13, 17, 19, 23])
>-- [[2, 2, 2, 5, 5], [2, 7, 7], [3, 13], [2, 3, 3, 3, 5]]
>-- [[3, 13], [3, 3, 3, 7], [2, 7, 7]]
>-- [[3, 13], [2, 7, 7], [5, 11], [2, 3, 11]]
>-- [[3, 13], [2, 3, 11]]
>
>Note that running the algorithm four times gave four different sets of
>correct answers. Genetic algorithms do not guarantee a correct answer.
>What they do provide is a shortcut to an answer that is close enough.
>
>My script is very arbitrary in places, and there are many ways in which it
>could be optimized. You may want to include other criteria for fitness,
>such as how many numbers need to be summed together.
>
>Have fun,
>
>James
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/lingo-l.cgi To post messages to the list, email
[EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]). Lingo-L is for
learning and helping with programming Lingo. Thanks!]