Skip to content
Permalink
main
Switch branches/tags

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?
Go to file
 
 
Cannot retrieve contributors at this time
{
"cells": [
{
"cell_type": "markdown",
"id": "5937b132",
"metadata": {},
"source": [
"# Tools making optimisation problem"
]
},
{
"cell_type": "markdown",
"id": "cbca808d",
"metadata": {},
"source": [
"AAA is a company that produces tools T1, T2 and T3. These are are made from steel, and the process involves molding the tools and then assembling them.\n",
"\n",
"The following table summarises the requirements and constraints:\n",
"\n",
"| | T1 | T2 | T3 | Availability |\n",
"|--------------------------|--------|--------|--------|--------------|\n",
"| Steel (kg) | 1 | 0.7 | 0.6 | 10,000 |\n",
"| Molding machine (hr) | 1 | 1 | 1 | 20,000 |\n",
"| Assembly machine (hr) | 0.3 | 0.5 | 0.4 | 9,000 |\n",
"| Demand limit (tools/day) | 15,000 | 16,000 | 12,000 | |\n",
"| Profit (£/1000 units) | 130 | 100 | 120 | |\n",
"\n",
"AAA would like to plan for the daily production of tools to maximise its profit.\n",
"In particular, we have the following questions:\n",
"\n",
"- How many of each type of the tools should AAA plan to produce per day?\n",
"- What is the expected total profit from this plan?\n",
"- Which resources are expected to be most critical in this plan?"
]
},
{
"cell_type": "markdown",
"id": "5f8a3431",
"metadata": {},
"source": [
"### Marking scheme\n",
"\n",
"|Item|Mark|\n",
"|:----|---:|\n",
"|**Mathematical formulation**:||\n",
"|Decision variables|/1|\n",
"|Profit formula|/1|\n",
"|Constraints|/2|\n",
"|Demand limits|/2|\n",
"|Non-negativity constraints|/1|\n",
"|**Solution**:||\n",
"|PuLP solution|/4|\n",
"|**Answers to AAA's questions**:||\n",
"|How many of each type of the tools should AAA plan to produce per day?|/3|\n",
"|What is the expected total profit from this plan?|/3|\n",
"|Which resources are expected to be most critical in this plan?|/3|\n",
"|||\n",
"|**Total**: |/20|\n"
]
},
{
"cell_type": "markdown",
"id": "0366a3fc",
"metadata": {},
"source": [
"## Mathematical formulation"
]
},
{
"cell_type": "markdown",
"id": "06aeba09",
"metadata": {},
"source": [
"Decision variables:\n",
"\n",
"|Variable name| Description |\n",
"|-------------|------|\n",
"|$X_{T1}$|day production of tool T1|\n",
"|$X_{T2}$|day production of tool T2|\n",
"|$X_{T3}$|day production of tool T3|"
]
},
{
"cell_type": "markdown",
"id": "56ab5cbe",
"metadata": {},
"source": [
"\n",
"Profit formula (to be optimised):\n",
"$$\n",
"Profit(Z) = 0.13X_{T1} + 0.1X_{T2} + 0.12X_{T3}\n",
"$$\n",
"*side note: all profit values (130,100,120) are divided by 1000 to get profit per unit*"
]
},
{
"cell_type": "markdown",
"id": "9b2ca564",
"metadata": {},
"source": [
"Constraints:\n",
"\n",
"$$\n",
"\\begin{alignat*}{4}\n",
" &X_{T1} + 0.7X_{T2} + 0.6X_{T3} &\\leq 10000 \\\\\n",
" &X_{T1} + X_{T2} + X_{T3} &\\leq 20000 \\\\\n",
" &0.3X_{T1} + 0.5X_{T2} + 0.4X_{T3} &\\leq 9000 \\\\\n",
"\\end{alignat*}\n",
"$$\n",
"\n",
"Demand limits:\n",
"\n",
"$$\n",
"\\begin{alignat*}{2}\n",
" &X_{T1} &\\leq 15000 \\\\\n",
" &X_{T2} &\\leq 16000 \\\\\n",
" &X_{T3} &\\leq 12000 \\\\\n",
"\\end{alignat*}\n",
"$$\n",
"\n",
"Non-negativity constraints:\n",
"\n",
"$$\n",
"X_{T1},X_{T2},X_{T3} \\geq 0\n",
"$$"
]
},
{
"cell_type": "markdown",
"id": "94561b9d",
"metadata": {},
"source": [
"## Solution"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4beff1b7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting pulp\n",
" Using cached PuLP-2.6.0-py3-none-any.whl (14.2 MB)\n",
"Installing collected packages: pulp\n",
"Successfully installed pulp-2.6.0\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install pulp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "1a5ec9b7",
"metadata": {
"ExecuteTime": {
"end_time": "2022-10-25T11:37:42.147735Z",
"start_time": "2022-10-25T11:37:42.007094Z"
}
},
"outputs": [],
"source": [
"import pulp"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "575493b6",
"metadata": {},
"outputs": [],
"source": [
"# Create a LP problem class with the objective being to maximise\n",
"prob = pulp.LpProblem(\"tools_cost\", pulp.LpMaximize)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "be39b471",
"metadata": {},
"outputs": [],
"source": [
"# The three tools named with a low bound of 0 (Non-negativity constraint), and their value being integer, as half a tool is not possible.\n",
"t1 = pulp.LpVariable(\"T1\", lowBound = 0, cat = 'Integer')\n",
"t2 = pulp.LpVariable(\"T2\", lowBound = 0, cat = 'Integer')\n",
"t3 = pulp.LpVariable(\"T3\", lowBound = 0, cat = 'Integer')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "a03a2752",
"metadata": {},
"outputs": [],
"source": [
"# Adding the profit formula:\n",
"prob += 0.13*t1 + 0.1*t2 + 0.12*t3, \"total_profit_of_tools\""
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "fcbde100",
"metadata": {},
"outputs": [],
"source": [
"# Adding the three constaints to the different resources\n",
"prob += t1 + 0.7*t2 + 0.6*t3 <= 10000, \"Steel\"\n",
"prob += t1 + t2 + t3 <= 20000, \"Molding\"\n",
"prob += 0.3*t1 + 0.5*t2 + 0.4*t3 <= 9000, \"Assembly\""
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "59b6e2d6",
"metadata": {},
"outputs": [],
"source": [
"# Adding the three demand limits for the tools\n",
"prob += t1 <= 15000, \"Limit_of_tools_1\"\n",
"prob += t2 <= 16000, \"Limit_of_tools_2\"\n",
"prob += t3 <= 12000, \"Limit_of_tools_3\""
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "937b3308",
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tools_cost:\n",
"MAXIMIZE\n",
"0.13*T1 + 0.1*T2 + 0.12*T3 + 0.0\n",
"SUBJECT TO\n",
"Steel: T1 + 0.7 T2 + 0.6 T3 <= 10000\n",
"\n",
"Molding: T1 + T2 + T3 <= 20000\n",
"\n",
"Assembly: 0.3 T1 + 0.5 T2 + 0.4 T3 <= 9000\n",
"\n",
"Limit_of_tools_1: T1 <= 15000\n",
"\n",
"Limit_of_tools_2: T2 <= 16000\n",
"\n",
"Limit_of_tools_3: T3 <= 12000\n",
"\n",
"VARIABLES\n",
"0 <= T1 Integer\n",
"0 <= T2 Integer\n",
"0 <= T3 Integer\n",
"\n"
]
}
],
"source": [
"print(prob)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "43f0ce9d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob.solve()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "37fe9208",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"T1 = 0.0\n",
"T2 = 4000.0\n",
"T3 = 12000.0\n"
]
}
],
"source": [
"for v in prob.variables():\n",
" print(\"{} = {}\".format(v.name, v.varValue))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "6d7456d9",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total profit over a day's worth of units: £1840.0\n"
]
}
],
"source": [
"print(\"Total profit over a day's worth of units: £{}\".format(pulp.value(prob.objective)))"
]
},
{
"cell_type": "markdown",
"id": "524021a2",
"metadata": {},
"source": [
"# Conclusion\n",
"\n",
"Answer 1: \n",
"\n",
"Number of tools to make each day:\n",
"\n",
"|tools| Amount |\n",
"|-------------|------|\n",
"| T1 | 0.0 units |\n",
"| T2 | 4000 units |\n",
"| T3 | 12000 units |\n",
"\n",
"Answer 2:\n",
"\n",
"Total profit per day: £1,840\n",
"\n",
"Answer 3:\n",
"\n",
"When putting the value back into the constraints:\n",
"* Steel: $0+0.7(4000)+0.6(12000) = 10000 == 10000$.\n",
"* Molding: $0+4000+12000 = 16000 < 20000$. \n",
"* Assembly: $0+0.5(4000)+0.4(12000) = 6800 < 9000$. \n",
"\n",
"When compared with the other constraints which had additional resources, Steel is the only one where it's limit has reached and therefore made it critical to the problem. Less or more steel added to the problem would directly influence the total cost and the tools"
]
},
{
"cell_type": "markdown",
"id": "57a444ba",
"metadata": {},
"source": [
"# List of references\n",
"\n",
"https://medium.com/swlh/solving-linear-programming-problems-lpps-using-pulp-and-python-5bf41ce96687 - for advice on PuLP and designing it for a linear problem"
]
}
],
"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.9.12"
},
"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
}