Coding smart solutions for off-grid farming
Published: May 17, 2026
Feed is the single largest expense in poultry and swine production. To maximize profitability, farmers need to formulate custom diets that hit precise nutritional targets at the lowest possible cost. Today, I am sharing the logic behind the feed formulation optimizer I built for the Uni-Farm app.
An animal's nutritional requirements change dramatically as it grows. A broiler chick needs high protein for muscle development, while a finisher needs more energy for weight gain. To handle this, I hardcoded specific industry-standard baselines into the app's state controller:
A pure mathematical algorithm will always choose the cheapest ingredient to hit a target. However, in animal science, you cannot feed a pig 100% of a cheap byproduct without causing severe digestive issues. To solve this, I wrote a syncOptimizerLimits() function that actively checks the database for maximum inclusion limits based on the specific animal and growth phase before running the math.
Even the best algorithm can't know exactly what is sitting in a farmer's barn on any given Tuesday. That is why the most critical feature I built is the exportToManual() function. Once the algorithm finds the most cost-effective recipe, the user can export those results into a dynamic DOM list. This allows the farmer to manually adjust the ingredient weights to match their actual physical inventory while still seeing the resulting protein and energy outputs in real-time.
By blending algorithmic precision with practical farm management, this tool is designed to save significant money on feed costs without sacrificing herd health.