Skip to content

Commit

Permalink
[Fix] don't treat cost matrix values as an integer
Browse files Browse the repository at this point in the history
When we enter float value inside cost matrix, "print_matrix" function
treats those values as integer, and only prints integral part of the
values.

For example, if cost matrix is:
matrix = [[5.1, 9.6, 1.7],
          [10.2, 3.5, 2.8],
          [8.3, 7.4, 4.9]]

Then output is as follows:
Lowest cost through this matrix:
[   5,    9,    1]
[  10,    3,    2]
[   8,    7,    4]
(0, 0) -> 5.1
(1, 1) -> 3.5
(2, 2) -> 4.9
total cost: 13.5

We can see printed cost matrix isn't same as original cost matrix. And
it's not always the case, cost matrix would have all values in integral
form, cost of the assignment could be a float value.

Resolves: bmc#34
  • Loading branch information
Vipul Kumar committed Aug 13, 2020
1 parent 5badef0 commit 0aa3574
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions munkres.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def make_cost_matrix(

def print_matrix(matrix: Matrix, msg: Optional[str] = None) -> None:
"""
Convenience function: Displays the contents of a matrix of integers.
Convenience function: Displays the contents of a matrix.
**Parameters**
Expand Down Expand Up @@ -513,8 +513,8 @@ def print_matrix(matrix: Matrix, msg: Optional[str] = None) -> None:
sep = '['
for val in row:
if val is DISALLOWED:
formatted = ((format + 's') % DISALLOWED_PRINTVAL)
else: formatted = ((format + 'd') % val)
val = DISALLOWED_PRINTVAL
formatted = ((format + 's') % val)
sys.stdout.write(sep + formatted)
sep = ', '
sys.stdout.write(']\n')
Expand Down

0 comments on commit 0aa3574

Please sign in to comment.