Note that there are some explanatory texts on larger screens.

plurals
  1. POAlgorithm for sorting numbers summing to a total and respecting criterions in python
    text
    copied!<p>I am trying to do a feed optimisation calculation for animal feeding but I am a rookie in term of python coding.</p> <p>Actually what I try to achieve is compute the less expensive combination of n ingredients by groups of k or less that supply enough of A and B criterions.</p> <p>My problem is that when ingredients number start going up, python hangs in the calculations. So is there a way to have python use more memory or a better algorithm or already available package for those kind of computations. I searched the net for answer but maybe this particular problem has a mathematical name I am unaware of.</p> <p>What I am doing now:</p> <ol> <li>Create the ingredient matrix: each ingredient has a name and then P,A,B,C,D... where P is the price and A,B,C,... are the values for different nutritive elements</li> <li>Create the limit matrix: Each element has a minimum and maximum value of the total mix.</li> <li>Create the objective vector: What I want to obtain for now it is a A=X vector and B=Y vector but I would like to specify C,D, etc. in the future.</li> <li>I then compute all the possible combinations of ingredients summing to a total (usually 1000) and by group of k ingredients.</li> <li>Remove the combinations that do not fit the limit matrix to get the available combination matrix</li> <li>Multiply the ingredient matrix by the combination matrix to get the final composition matrix</li> <li>Remove all the values in the composition matrix that do not fit the objective vector for criterions A and B.</li> <li>Sort the resulting list by price and give the result.</li> </ol> <p>I am using Numpy for most of those operations.</p> <p>The approach (to my knowledge) cannot be a simple linear algebra problem because sometimes there will be no perfect solution which is why the numerical approach was taken in the first place. </p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload