Genetic Algorithms: Automatic DIY Soylent


Inspired by comments on the MakeSoylent thread, I went ahead and implemented an example of how an automatic recipe generator might work by using a Genetic algorithm. Right now, it’s only using 5 ingredients and 4 nutrients, but it can easily be expanded.

Look a the nutrient completeness, then click the ‘play’ button and see how the recipe evolves over time. It’s not perfect, but a start!

The code is open source and available on my GitHub page here:

Looking forward to seeing how this evolves :smile:

Http:// - Soylent Recipe web app

Wow brilliant.
Not much code either, kind of surprising.
I’m still going to try my method, but this looks like it’s working really well.
Can’t wait to see it at-scale.


I would think about implementing something telling the simulation how precisely you will be able to measure said ingredient. It would be very difficult to measure everything to 3 decimal places every day.


Yea, this is more a proof of concept than anything else. Something usable will take some more work…


Yea I realize that I just need to put some ideas down :slight_smile:

Also the final version should include Micronutriant Ratios and instead of having a set amount for each nutrient, have a minimum and recommended and a maximum.


I discovered something interesting the other day. Something like this would ,be awesome. You could possibly take the flavor profiles of all the ingredients, but design your own flavor profile, and then set it as one of the target fitness criteria. You could pick your flavor, and then the GA would generate the formula. Texture would also be a good criteria.

However, something like this would also be awesome for creating tasty “real meal” courses that comprise complete nutrition. Food doesn’t have to be soylent, just portion allocations would work. Bucketing meals by creating discrete populations with individual fitness metrics could also be a valuable feature. You could then divide a set of ingredients into appropriate meals throughout the day (dinner and dessert,) so that in conjunction with your Soylent intake, you’re able to track your real food intake.

Awesome work, @nickp!


Along the same lines as ianproth, I would suggest an acceptable range (e.g., calories > 1995 and < 2000 kcal; phosphorus would be > 0.7 and < 4.0 grams).


…Dude, at that point: make it yourself lol.
Could just be me but that’s a bit much to ask of someone.


Since before Soylent, I’ve envisioned a system that could ambiently, or with extremely minimal effort, assess an individual’s current needs (e.g., , Soylent gave me hope than not only would we be able to ambiently assess, but we could use that assessment to create up-to-the-minute custom prescriptions. I think something like your Soylent GA in combination with and some type of data recording device (e.g., to keep track of things like recently prescribed soylent meals, recent assessments, preferences) would provide the dynamic formulations.

In other words, I could wake up and take a leak. My in-house diagnostic toilet would send my phone my pre-breakfast assessment while I make my way to the kitchen. Once in the kitchen my in-house soylent machine would ask if I want a latte, berry, or other flavored soylent, and based on my option and pre-breakfast assessment it would prepare my up-to-the-minute customized soylent formula and send that formula to my phone. This would repeat over the course of the day, with each subsequent meal taking into account not just recent assessments, but also all the previous meals of the day.

Over the course of days, months, and years, my personal formula would evolve to match not just my obvious needs (e.g., sodium within DRI) but also my personalized needs (e.g., my assessments consistently show that I maintain higher than average sodium levels, so my personal formulas move into the lower quartile of the DRI).

In theory, other assessment sources (e.g. dna, blood pressure cuffs, blood draws) or prescription sources could be factored into the dynamic soylent formula. For example, after a traumatic accident a surgeon could prescribe a lower caloric level along with pain killer. (Albeit the latter would make it more difficult to use public Soylent machines. Even then something like a powdered version of the prescription could be blister-packed and used in soylent machines.)

The Dial-a-Drug Machine

I’m working on an app, but I like sharing my ideas. I have a generic genetic algorithm simmering now, and I’m just tooling around with ideas. :smile:

Right now it’s sharing brainspace with some other things I work on, as I want to be able to reuse it, but I have a ghost of a notion of a food / AI fusion.


The more I see other peoples GitHubs, the more my lack of programming opportunities depresses me lol.
The irony is I have so little time after finishing my schoolwork for programming classes that I can’t actually find time to program anything worthwhile. Fuck school.


That’s awesome! Seems like the hard part is done. It would be usable - albeit basic - if you could just tie it in to the USDA food database and the makesoylent database to choose recipe items. It would certainly make adapting existing recipes to test inclusion of new ingredients much easier. Just pop new ingredient in and set it off…

The example ingredients you chose are particularly cruel, I felt very sorry for the poor little algorithm not being able to balance carbs and protein!


Interesting! Can’t wait to see full listing someday.


I used to hang out on the Halfbakery. It is not in any way a list of actual items (Although being 15 years old, some of them have been baked, just by coincidence), it’s a site for ‘half baked’ ideas and commentary thereon.

Aside from that, I like the idea otherwise.


Thank you.

The prominent smart toilet since about 2005 is from Toto.



I had been working on a similar algorithm. Before I worked on a random based one, but a few days ago I implement a short of genetic algorithm. You can see it on (and the random version on They are only experiments (to improve then the main project,, but just with a little work, they could work better.

PS: if you are going to check this, please use Chrome.


Thanks Nick, I’m finding the results very interesting.

I’ve added:

  • Max/Min ranges for each nutrient
  • Rounds to whole values
  • All nutrients
  • Weighting of the importance that each nutrient falls within the max/min

Code on github here.
Github hosted demo here.


Wow that’s awesome work @2potatoes!

I think this algorithm could be incorporated back into the diy site as a kind of ‘auto correct’. For example, if your nutrient profile differs to the one the author of a recipe was using, you could select your own profile and ‘auto correct’ the recipe to fit it.

This would also be useful if you want to experiment with different ingredients, for example ‘what happens if I add a banana?’. Just add in the banana and auto correct the recipe to see how it fits.

I’m not sure if you saw this but you can get JSON representation of recipes and nutrient profiles by simply adding /json to the end of a recipe url, eg

You can also override the nutrient profile like this:

Would be great if we can get it working with recipes from the site as a starting point. At that point it would be fairly simple to add the code back into the site.


I’ve added some ideas for converting diy json data to genetic-compatible data to the current revision. In my version I won’t be able to grab the data directly because of cross-site scripting limitations–but @nickp should be able to get that code working pretty quickly if he wants to.

Meanwhile, anyone interested can copy a diy recipe’s json file into my genetic soylent copy hosted on github. The source code remains available on github.

New stuff:

  • Paste in JSON from
  • A basic UI for max/min for each nutrient as well as the importance



I just pushed jsonp support if you want to include that too: