Created
April 8, 2019 03:59
-
-
Save radzionc/29e9a7739f1ba1c95b467cc5ed2400ea to your computer and use it in GitHub Desktop.
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": "code", | |
"execution_count": 44, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_total_cost(costs, solution):\n", | |
" total_cost = 0\n", | |
" for i, row in enumerate(costs):\n", | |
" for j, cost in enumerate(row):\n", | |
" total_cost += cost * solution[i][j]\n", | |
" return total_cost" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 45, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[[30. 0. 0. 0.]\n", | |
" [ 0. 0. 30. 40.]\n", | |
" [10. 30. 10. 0.]]\n", | |
"total cost: 680.0\n" | |
] | |
} | |
], | |
"source": [ | |
"costs = [\n", | |
" [ 2, 2, 2, 1],\n", | |
" [10, 8, 5, 4],\n", | |
" [ 7, 6, 6, 8]\n", | |
"]\n", | |
"supply = [30, 70, 50]\n", | |
"demand = [40, 30, 40, 40]\n", | |
"solution = transportation_simplex_method(supply, demand, costs)\n", | |
"print(solution)\n", | |
"print('total cost: ', get_total_cost(costs, solution))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment