This project demonstrates how to optimize the feed mix for dairy cows using Linear Programming. The goal is to minimize the cost of the feed while ensuring that the nutritional requirements for the cows are met. The project uses real-world nutrient data fetched from the USDA FoodData Central API, and the optimization is done using the PuLP
library in Python.
- Data Source: Nutrient data for feed ingredients is fetched from the USDA FoodData Central API.
- Feed Ingredients: Corn silage, soybean meal, barley, and hay.
- Nutrient Requirements: Optimization ensures that the feed meets the minimum requirements for protein, fat, fiber, and energy.
- Cost Minimization: The linear programming model is set to minimize the total cost of the feed mix.
- Visualizations: Includes pie charts and bar charts to visually represent the optimized feed mix and the nutritional contributions of each ingredient.
The project consists of the following key components:
- API Integration: Fetches real-time nutrient data for each feed ingredient.
- Linear Programming Model: Optimizes the feed mix using
PuLP
to meet nutritional requirements at the lowest cost. - Data Handling: Cleans and processes the fetched data, replacing missing values with mean values.
- Visualizations: Provides insights into the optimized feed mix and nutritional contributions with clear, easy-to-understand charts.
- Pie Chart: Displays the proportions of each ingredient in the optimized feed mix.
- Bar Chart: Shows how each feed ingredient contributes to the total amounts of protein, fat, fiber, and energy.
- Python 3.x
- Jupyter Notebook (optional but recommended)
Make sure to install the necessary Python libraries before running the project. You can install them by running the following command:
pip install requests pandas pulp matplotlib
-
Clone the Repository:
git clone https://github.com/yourusername/feed-optimization.git
-
Navigate to the Project Directory:
cd feed-optimization
-
Run the Jupyter Notebook: Open the
feed_optimization.ipynb
file in Jupyter Notebook or JupyterLab. -
Run the Python Script: If you prefer to run the script in a terminal or Python environment, execute the notebook cells sequentially to fetch the data, optimize the feed, and display the visualizations.
We use the USDA FoodData Central API to fetch the nutritional information for four common feed ingredients: corn silage, soybean meal, barley, and hay. The nutrient data includes the protein, fat, fiber, and energy content of each feed ingredient.
After fetching the data, we handle missing values by replacing any zeros with the mean value for that nutrient across all feed ingredients.
We set up a linear programming model using PuLP
to minimize the cost of the feed while meeting the cows' nutritional requirements for protein, fat, fiber, and energy. Bounds are set to ensure a balanced feed mix, with upper and lower limits for each ingredient.
Once the model is solved, we generate visualizations to showcase the optimized feed mix and how each ingredient contributes to the cows' total nutritional intake.
Here’s an example of the optimized feed mix and its visual representation:
- Feed Mix:
- Corn silage: 30%
- Soybean meal: 5%
- Barley: 5%
- Hay: 60%
- Total Cost: $14.00 per kg
- More Feed Ingredients: Incorporating additional feed ingredients into the optimization model.
- Dynamic Nutritional Requirements: Adding a feature to dynamically change the nutritional requirements based on different cow types or stages of lactation.
- Interactive Dashboard: Implementing an interactive dashboard using a tool like
Dash
orStreamlit
for better user interaction with the optimization results.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to submit issues or pull requests if you want to contribute to improving this feed optimization project.
For any inquiries or further information, feel free to contact me at:
- Email: jebin.jervis2@mail.dcu.ie
- LinkedIn: https://www.linkedin.com/in/jebin-larosh-jervis-a52938123/
- GitHub: https://github.com/Jebin1999
- Special thanks to the USDA FoodData Central for providing the nutrient data used in this project.