Showing posts from May, 2015

Transportation Problem (Vogel algorithm python)

Transportation Problem A typical transportation problem is shown in Fig. 9. It deals with sources where a supply of some commodity is available and destinations where the commodity is demanded. The classic statement of the transportation problem uses a matrix with the rows representing sources and columns representing destinations. The algorithms for solving the problem are based on this matrix representation. The costs of shipping from sources to destinations are indicated by the entries in the matrix. If shipment is impossible between a given source and destination, a large cost of M is entered. This discourages the solution from using such cells. Supplies and demands are shown along the margins of the matrix. As in the example, the classic transportation problem has total supply equal to total demand. Figure 9. Matrix model of a transportation problem. (
Vogel Algorithm as a solution (python)
class Vogel(): def __init__(…

cProfile python (benchmark)

Python includes a profiler called cProfile. It not only gives the total running time, but also times each function separately, and tells you how many times each function was called, making it easy to determine where you should make optimizations.

For example, you can invoke the cProfile when running a script with the following:

python -m cProfile  

the output of this script look like this below:

4550013 function calls in 4.187 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.002    0.002    4.187    4.187<module>)
      297    0.002    0.000    0.002    0.000
      297    0.003    0.000    0.003    0.000
      594    0.002    0.000    0.022    0.000
        1    0.006    0.006    0.008    0.008
        1    0.010    0.010    4.165    4.165