Linear soylent solver


I was inspired by all the comments in the genetic soylent thread about linear programming to make a linear soylent solver:

The installation and UI for this first version are rather awkward, but it does optimize soylent recipes quickly. It first tries to find the cheapest 100% complete recipe for the ingredients and profile provided; if there is no 100% complete recipe, it finds the least incomplete recipe, using a similar “deviation” calculation to 2potatoes’ genetic solver.


Minor update: It no longer shows the wrong amount for nutrients that are over the maximum.


any chance for a build with self contained python? Or at least standard Python3? I heard there was some upgrade rewrite program, so it should be a no brainer. Or is it?


I haven’t really looked into self contained Python much. I suspect the tricky bit would be lpsolve (the open source C library that is doing the heavy lifting here).

I’d probably have written it in Python 3 in the first place, except that there isn’t a Python 3 version of the lpsolve wrapper. I could look at converting the wrapper, I suppose. The upgrade tool (2to3) does simplify upgrading Python code, but the wrapper isn’t Python code. It’s an extension module written in C.

At this point this is more a proof of concept than anything, by which I mean that the code is pretty messy. If I end up making many more changes to it, then there’s probably a restructuring in its future, at which point I might just move to C++. That would make it simple to distribute a binary, and it would remove the need to deal with the wrapper.


@opethbass I took a stab at it using the pulp library to make it self contained.

I made a web version as well if anyone wants to play around with it.

still has a few rough edges but works all right. To use it just add /json to the end of a recipe url and copy the result into the load recipe popup.


@jstorry cool, thanks a lot.


I seem to be getting a JavaScript error when I load a URL. This isn’t a helpful error b/c of the minification of course but here it is:

Unexpected token h 

#8 :

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache/2.2.15 (Red Hat) Server at Port 80



Sorry @biab, I was fixing some bugs and making it a little more intuitive, or at least trying to :smile: should be working for now


sorry, I should have been a little more clear. Open the url in your browser and copy the resulting JSON data to the popup. A good starting point would be as it optimizes correctly. Should look something like this before you hit load once you’re done


I’m getting “infeasible” as a result. It won’t optimize.


Looks like it doesn’t like really small amounts.

On the flip side, this optimizes to $1.03 a day.

And this to 96 cents:

If I can figure out how to fix the small amounts issue (0.00882 grams and so forth) it should work out.

As a workaround, I can create custom nutrient profiles, removing the ones that cause NaN exceptions.


What recipe are you using? The way I have it now it can be hard to figure out what is causing the recipe to be infeasible, for me it’s typically the calories, or the niacin maximums are too low. If you want to use a different nutrient profile you can add ?nutrientProfile= to the end of the json url. For example you would use if you wanted to use Robs Recommended profile instead of the one in the recipe

I’m working to make the optimizing algorithm elastic based on this page so it will still return a result that makes a little more sense when the recipe is infeasible. I’m also planning on adding some more detail to make it easier to see how the nutrients are distributed amount the ingredients to give you an idea of what needs to be added or removed once you figure out the optimizing issue.


I’ll PM you the recipe, as it’s a WIP I don’t want to be public yet. I’m going to make a nutrient profile in json format customized to my targets. This is an awesome tool. Thanks, @Absotively and @jstorry !


My scale is only good to 2 or 3 decimal places… I was thinking of adding a drop down so you could select your batch size. So default to 1 day, then go up to a week or a month. Would that solve your problem? I can remove the rounding as well and go the full 8 or so decimal places, but it doesn’t really make sense to me as they take up space and aren’t very usable unless you are taking the data out of the app (I’ll add some export functionality for this later on maybe)


Changing the rounding to 6 decimal places would be sufficient for all the nutrients, added manually. I’d also like to see the ability to add arbitrary nutrients (let’s say you wanted to add lycopene, or so on.) Thanks for the help in figuring that out! I’ve since been able to adjust different recipes, and by setting a max on calories and so on, it’s been very useful.


Still have to think on how I want to address adding additional nutrients, but I’ve added the ability to turn off the rounding under the batch size drop down menu, as well you can now select some default batch sizes to calculate the amounts for larger batches.


Hi Absotively, it seems I cant connect to the web version of the script anymore. It was really great…any chance you can put it back up again? :slight_smile:

Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.


Are you talking about , not sure why it went down, but I restarted the app and it seems to be working again.


Yes, sorry, that was the one. Great that it is working again!