Skip to content

Commit

Permalink
Fixed a bug with dirlay budget calcculation twice
Browse files Browse the repository at this point in the history
  • Loading branch information
20shaked20 committed Aug 25, 2024
1 parent f7d1260 commit 18b29d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""

import networkx as nx
import numpy as np
import networkx.algorithms.connectivity as algo
import math
import logging
Expand Down Expand Up @@ -347,8 +348,8 @@ def non_spreading_dirlaynet_minbudget(Graph:nx.DiGraph, source:int, targets:list
G_reduction_min_cut = min_cut_with_node_capacity(G, source=source, target='t')
N_groups = min_cut_N_groups(G_reduction_min_cut,layers)
vacc_matrix = calculate_vaccine_matrix(layers, N_groups)
integer_matrix = matrix_to_integers_values(vacc_matrix)
min_budget = min_budget_calculation(vacc_matrix)
integer_matrix = matrix_to_integers_values(np.array(vacc_matrix))
min_budget = min_budget_calculation(integer_matrix)
strategy = dirlay_vaccination_strategy(integer_matrix, N_groups)

logger.info(f"Returning minimum budget: {min_budget} and the vaccination strategy: {strategy}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Status(Enum):
'directly vaccinated': 'green',
'default' : "#00FFD0"
}
logger = logging.getLogger(__name__)
logger = logging.getLogger('firefighter_problem_main')

# ============================ Validation Functions ============================

Expand Down Expand Up @@ -632,7 +632,7 @@ def matrix_to_integers_values(matrix: np.matrix) -> np.matrix:
the original matrix as closely as possible.
"""

logger.info ("Converting the matrix to integer values..")
logger.info("Converting the matrix to integer values..")

#get the row sums and column sums
row_sums = np.sum(matrix, axis=1)
Expand Down Expand Up @@ -663,7 +663,7 @@ def matrix_to_integers_values(matrix: np.matrix) -> np.matrix:
rounded_matrix[idx, j] += diff
current_col_sums = np.sum(rounded_matrix, axis=0)

logger.info("Integer matrix as follows -", rounded_matrix)
logger.info(f"Integer matrix as follows:{rounded_matrix}")

return rounded_matrix

Expand All @@ -687,8 +687,7 @@ def min_budget_calculation(matrix: list) -> int:
>>> min_budget_calculation(matrix)
2
"""
integral_matrix = matrix_to_integers_values(np.array(matrix))
rows_sum = np.sum(integral_matrix, axis=1) # we get column sum as we want to -> on time step i, vaccinate Mij nodes from layer j , for all i ≤ j ≤ .
rows_sum = np.sum(matrix, axis=1) # we get row sum as we want to -> on time step i, vaccinate Mij nodes from layer j , for all i ≤ j ≤ .
min_budget = int(np.max(rows_sum))
logger.info(f"Min budget needed to save the target nodes: {min_budget}")
return min_budget
Expand Down

0 comments on commit 18b29d7

Please sign in to comment.