Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
7159CEM-Portfolio-2024/LP.ipynb
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
214 lines (214 sloc)
6.38 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "af0cba34-ce1c-4572-a2d1-e23425871b08", | |
"metadata": {}, | |
"source": [ | |
"# Part 1) A linear programming approach for optimizing features in ML models" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ef0baa69-7ce7-4800-afb5-9e06c8161c63", | |
"metadata": {}, | |
"source": [ | |
"Read the article [A linear programming approach for optimizing features in ML models](https://engineering.fb.com/2021/07/29/data-infrastructure/linear-programming/).\n", | |
"\n", | |
"Summarise it technically in about **400 words**, ensuring you capture the Mathematical formulation of how Linear Programming is used. (Do not discuss the code.)\n", | |
"\n", | |
"- Use LaTeX for the mathematical formulae, not images. You also need to expand on the formulae given in the article." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "98e54944-4ae1-4246-8762-c54afd201076", | |
"metadata": {}, | |
"source": [ | |
"## Article's summary\n", | |
"\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n", | |
"..................................................................................................\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "5937b132", | |
"metadata": {}, | |
"source": [ | |
"# Part 2) Farmer's Problem" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "cbca808d", | |
"metadata": {}, | |
"source": [ | |
"A farmer has 500 acres of land to allocate to wheat, corn, and sugar beets.\n", | |
"\n", | |
"The following table summarises the requirements and constraints:\n", | |
"\n", | |
"| | Unit | Wheat | Corn | Sugar Beets |\n", | |
"|--------------------------|---------|------:|-----:|:-----------:|\n", | |
"| Yield | T/acre | 2.5 | 3 | 20 |\n", | |
"| Demand (Need for feed) | T | 200 | 240 | |\n", | |
"| Planting cost | £/acre | 150 | 230 | 260 |\n", | |
"| Selling price | £/T | 170 | 150 | 36 if produce ≤ 6000 T |\n", | |
"| | £/T | | | 10 if produce > 6000 T |\n", | |
"| Backup (Purchase price) | £/T | 238 | 210 | |" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "0366a3fc", | |
"metadata": {}, | |
"source": [ | |
"## Mathematical formulation" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "06aeba09", | |
"metadata": {}, | |
"source": [ | |
"|Variable name| Description |\n", | |
"|:------------|:-----|\n", | |
"|$x_1$| Acres of land used for wheat |\n", | |
"|$x_2$| Acres of land used for corn |\n", | |
"|$x_3$| Acres of land used for sugar beets |\n", | |
"|$p_1$| Tons of crop wheat sold |\n", | |
"|$p_2$| Tons of crop corn sold |\n", | |
"|$p_3$| Tons of crop sugar beets sold at £36 |\n", | |
"|$p_4$| Tons of crop sugar beets sold at £10 |\n", | |
"|$y_1$| Tons of wheat purchased |\n", | |
"|$y_2$| Tons of corn purchased |" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "56ab5cbe", | |
"metadata": {}, | |
"source": [ | |
"\n", | |
"Profit formula:\n", | |
"\n", | |
"$$\n", | |
".........................\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9b2ca564", | |
"metadata": {}, | |
"source": [ | |
"Constraints:\n", | |
"\n", | |
"$$\n", | |
"\\begin{alignat*}{4}\n", | |
" ......................... &\\leq ...... \\\\\n", | |
" ......................... &\\leq ...... \\\\\n", | |
" ......................... \\\\\n", | |
" ......................... & \\geq 0\n", | |
"\\end{alignat*}\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "94561b9d", | |
"metadata": {}, | |
"source": [ | |
"## Solution using PuLP" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "1a5ec9b7", | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2022-10-25T11:37:42.147735Z", | |
"start_time": "2022-10-25T11:37:42.007094Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"from pulp import *" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "6a8a4305-6710-4a39-bf0c-3f032f9b3a07", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "4418a51c-715e-4ce1-bd3b-f7d53dd06159", | |
"metadata": {}, | |
"source": [ | |
"### Optimal solution\n", | |
"\n", | |
"|Category |Unit|Wheat|Corn|Sugar Beets|\n", | |
"|---------|----|-----|----|-----------|\n", | |
"|Area |Acre| | | |\n", | |
"|Yield |T | | | |\n", | |
"|Sales |T | | | |\n", | |
"|Purchase |T | | | |\n", | |
"\n", | |
"Total cost: ..............." | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.11.1" | |
}, | |
"toc": { | |
"base_numbering": 1, | |
"nav_menu": {}, | |
"number_sections": false, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"vscode": { | |
"interpreter": { | |
"hash": "6d1e45cadc3597bb8b6600530fbdf8c3eefe919a24ef54d9d32b318795b772e0" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |