-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a99941
commit f7ded2e
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "b01c2277", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Status: 1\n", | ||
"Total Cost: $36950.0\n", | ||
"Amount of coal shipped from Mine 1 to Plant 1: 33.0 tons\n", | ||
"Amount of coal shipped from Mine 1 to Plant 2: 64.0 tons\n", | ||
"Amount of coal shipped from Mine 1 to Plant 3: 36.0 tons\n", | ||
"Amount of coal shipped from Mine 1 to Plant 4: 72.0 tons\n", | ||
"Amount of coal shipped from Mine 2 to Plant 1: 55.0 tons\n", | ||
"Amount of coal shipped from Mine 2 to Plant 2: 0.0 tons\n", | ||
"Amount of coal shipped from Mine 2 to Plant 3: 0.0 tons\n", | ||
"Amount of coal shipped from Mine 2 to Plant 4: 0.0 tons\n", | ||
"Amount of coal shipped from Mine 3 to Plant 1: 22.0 tons\n", | ||
"Amount of coal shipped from Mine 3 to Plant 2: 96.0 tons\n", | ||
"Amount of coal shipped from Mine 3 to Plant 3: 54.0 tons\n", | ||
"Amount of coal shipped from Mine 3 to Plant 4: 108.0 tons\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from pulp import LpProblem, LpVariable, lpSum, LpMinimize\n", | ||
"\n", | ||
"# Create a linear programming problem\n", | ||
"model = LpProblem(\"Coal_Shipping_Problem\", LpMinimize)\n", | ||
"\n", | ||
"# Decision variables\n", | ||
"mines = [1, 2, 3]\n", | ||
"plants = [1, 2, 3, 4]\n", | ||
"\n", | ||
"# Amount of coal to be shipped from each mine to each plant\n", | ||
"x = LpVariable.dicts(\"coal_shipped\", ((i, j) for i in mines for j in plants), lowBound=0, cat='Integer')\n", | ||
"\n", | ||
"# Objective function: Minimize total cost\n", | ||
"model += lpSum(62 * x[i, j] for i in mines for j in plants) + \\\n", | ||
" lpSum(7 * x[i, j] for i in mines for j in plants if j == 1) + \\\n", | ||
" lpSum(9 * x[i, j] for i in mines for j in plants if j == 2) + \\\n", | ||
" lpSum(14 * x[i, j] for i in mines for j in plants if j == 3)\n", | ||
"\n", | ||
"# Constraints\n", | ||
"# Mine capacity constraints\n", | ||
"mine_capacity = {1: 220, 2: 190, 3: 280}\n", | ||
"for i in mines:\n", | ||
" model += lpSum(x[i, j] for j in plants) <= mine_capacity[i]\n", | ||
"\n", | ||
"# Plant demand constraints\n", | ||
"plant_demand = {1: 110, 2: 160, 3: 90, 4: 180}\n", | ||
"for j in plants:\n", | ||
" model += lpSum(x[i, j] for i in mines) >= plant_demand[j]\n", | ||
"\n", | ||
"# Ash and sulfur content constraints\n", | ||
"for j in plants:\n", | ||
" model += 0.09 * x[1, j] + 0.05 * x[2, j] + 0.04 * x[3, j] <= 0.06 * lpSum(x[i, j] for i in mines)\n", | ||
" model += 0.06 * x[1, j] + 0.04 * x[2, j] + 0.03 * x[3, j] <= 0.05 * lpSum(x[i, j] for i in mines)\n", | ||
"\n", | ||
"# Solve the problem\n", | ||
"model.solve()\n", | ||
"\n", | ||
"# Print the results\n", | ||
"print(f\"Status: {model.status}\")\n", | ||
"print(f\"Total Cost: ${model.objective.value()}\")\n", | ||
"\n", | ||
"for i in mines:\n", | ||
" for j in plants:\n", | ||
" print(f\"Amount of coal shipped from Mine {i} to Plant {j}: {x[i, j].value()} tons\")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c6b0eaee", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"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.7" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |