Skip to content

Commit 1d1296d

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ccef627 commit 1d1296d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

knapsack/knapsack_branch_and_bound.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ def calculate_bound(node: Node, capacity: int, items: list[Item]) -> float:
4747

4848
if index < len(items):
4949
profit_bound += (
50-
(capacity - total_weight)
51-
* items[index].value
52-
/ items[index].weight
50+
(capacity - total_weight) * items[index].value / items[index].weight
5351
)
5452

5553
return profit_bound
@@ -98,9 +96,7 @@ def knapsack_branch_and_bound(
9896

9997
include_node.bound = calculate_bound(include_node, capacity, items)
10098
if include_node.bound > max_profit:
101-
heapq.heappush(
102-
priority_queue, (-include_node.bound, include_node)
103-
)
99+
heapq.heappush(priority_queue, (-include_node.bound, include_node))
104100

105101
# Exclude next item
106102
exclude_node = Node(
@@ -112,8 +108,6 @@ def knapsack_branch_and_bound(
112108

113109
exclude_node.bound = calculate_bound(exclude_node, capacity, items)
114110
if exclude_node.bound > max_profit:
115-
heapq.heappush(
116-
priority_queue, (-exclude_node.bound, exclude_node)
117-
)
111+
heapq.heappush(priority_queue, (-exclude_node.bound, exclude_node))
118112

119113
return max_profit

0 commit comments

Comments
 (0)