Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

Commit cd3b5c2

Browse files
committed
Refactor minor details
1 parent 6e5e4db commit cd3b5c2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

knapsack_problem/heuristic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,20 @@ def solveInstance(knapsack: Knapsack, index, heuristics):
3232
'''
3333
Solve the generated or loaded instance by the specified heuristics.
3434
'''
35-
print(f' {index}° instance:\n {knapsack.total_items} items\n {knapsack.capacity} of capacity')
35+
print(f'\n {index}° instance:\n {knapsack.total_items} items\n {knapsack.capacity} of capacity')
3636
for h in heuristics:
3737
print('\tSolving instance... ', end='')
3838
start = time()
39-
# heuristics take 0 seconds to run:
39+
# heuristics take almost 0 seconds to run:
4040
items = pickItems(knapsack, h)
41-
# the measured time is actually just the sum of the values:
41+
#? the measured time is actually just the sum of the values:
4242
value = sum(i.value for i in items)
4343
end = time()
4444
print('done\r', end='')
4545
print(' \r', end='')
4646
print(f'\tTotal value by heuristic {h}: {value}')
4747

4848
measured_time = end - start
49+
# only print time when it took 100 milliseconds or more
4950
if measured_time >= 0.1:
5051
print(f'\t Measured time: {measured_time:.3g} seconds')

0 commit comments

Comments
 (0)