Thanks for the hints. I does seem like a type of napsack problem or a change problem however there are smoe specifics that make it a little more complex, maybe. Also I did some fiddling with the script to try to see what strategy I owould use as a human and try to determine if I could use that as a basis from which to develop code. The weights do (sort of) have two attributes, weight and precision. Precision could probably be equated with value but I really can not wrap my head around this one :) The weight examples I gave were not representative of the true problem. The weights do run from smallest to largest and the values are 5 or 6 decimal places. A strategy I used fairly well to do it by hand is very simple but ... As in the example I found online of the coin change problem you can add the largest number of the largest number of weights and add that to the total as long as the total does not exceed the target value. Continue with lesser weights and finally add the number of the smallest weights. The smallest weight is quite small and there are a lot of intermediates so it might make sense to just keep it as simple as possible and not worry about the perfect solution. Once the weights are chosen by this method, it is never possible to substitute more larger weights for smaller ones, of course but as in the coin change problem it might be possible to get closer with more smaller weights if the remainder is then satisfied with fewer even smaller coins. I can very easily code the simplistic solution and fiddle around to see how much improvement might be possible. I might even get an idea as to how to test for a better solution once the simple method is used. I have not used much math in many years and could not follow most of the online examples. There was a python example for the syntax is so different from Perl or any language I have used that it would take me forever to figure out. I will search for Perl coin change problem and similar topics once my satellite internet connection improves after 2:00 AM but if anyone has links for examples of the coin change or napsack problems written in Perl that would be very much appreciated.

In reply to Re^2: optimization problem (Knapsack) by spencoid
in thread optimization problem by spencoid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.