Skip to content

Commit

Permalink
rename max-flow to min-cut
Browse files Browse the repository at this point in the history
  • Loading branch information
erelsgl committed Jul 9, 2024
1 parent 2ef6676 commit adf9974
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import networkx.algorithms.connectivity as algo
import math
import logging
from networkz.algorithms.approximation.firefighter_problem.max_flow_with_node_capacity import max_flow_with_node_capacity
from networkz.algorithms.approximation.firefighter_problem.max_flow_with_node_capacity import min_cut_with_node_capacity
from networkz.algorithms.approximation.firefighter_problem.Utils import *

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -275,7 +275,7 @@ def non_spreading_dirlaynet_minbudget(Graph:nx.DiGraph, src:int, targets:list)->
layers = adjust_nodes_capacity(Graph, src)
G = create_st_graph(Graph, targets)
#display_graph(G)
G_reduction_min_cut = max_flow_with_node_capacity(G, source=src, target='t')
G_reduction_min_cut = min_cut_with_node_capacity(G, source=src, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

logger = logging.getLogger(__name__)

def max_flow_with_node_capacity(graph: nx.DiGraph, source: int = None, target: int = None) -> set:
def min_cut_with_node_capacity(graph: nx.DiGraph, source: int = None, target: int = None) -> set:
"""
Computes a maximum flow in the given graph, where each node has a capacity
Computes a minimum cut in the given graph, where each node has a capacity
Parameters:
----------
Expand Down Expand Up @@ -70,7 +70,8 @@ def max_flow_with_node_capacity(graph: nx.DiGraph, source: int = None, target: i
>>> G.add_edge(2, 3)
>>> G.add_edge(1, 4)
>>> s_t_G = create_st_graph(G, [2,4])
>>> min_cut_nodes = max_flow_with_node_capacity(s_t_G, 0, 4)
>>> min_cut_nodes = min_cut_with_node_capacity
(s_t_G, 0, 4)
>>> sorted(min_cut_nodes)
['2_out', '4_out']
"""
Expand Down Expand Up @@ -105,7 +106,6 @@ def max_flow_with_node_capacity(graph: nx.DiGraph, source: int = None, target: i
min_cut_nodes = algo.minimum_st_node_cut(H, f'{source}_out', 't_in')

logger.info(f"Minimum Cut is: {min_cut_nodes}")

return min_cut_nodes

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from networkz.algorithms.approximation.firefighter_problem.Utils import adjust_nodes_capacity
from networkz.algorithms.approximation.firefighter_problem.Utils import create_st_graph
from networkz.algorithms.approximation.firefighter_problem.Utils import parse_json_to_networkx
from networkz.algorithms.approximation.firefighter_problem.max_flow_with_node_capacity import max_flow_with_node_capacity
from networkz.algorithms.approximation.firefighter_problem.max_flow_with_node_capacity import min_cut_with_node_capacity
from networkz.algorithms.approximation.firefighter_problem.Utils import calculate_vaccine_matrix
from networkz.algorithms.approximation.firefighter_problem.Utils import min_cut_N_groups
from networkz.algorithms.approximation.firefighter_problem.Utils import matrix_to_integers_values
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_source_is_target(graph_key, source, targets):
layers_1 = adjust_nodes_capacity(graph_1, 0) # src is 0
targets_1 = [1, 2, 3] # saving 1,2,3
G1 = create_st_graph(graph_1, targets_1)
reduction_G1_min_cut = max_flow_with_node_capacity(G1, 0)
reduction_G1_min_cut = min_cut_with_node_capacity(G1, 0)
N_1_groups = min_cut_N_groups(reduction_G1_min_cut,layers_1)
matrix_1 = calculate_vaccine_matrix(layers_1, N_1_groups)
integer_matrix_1 = matrix_to_integers_values(matrix_1)
Expand All @@ -89,7 +89,7 @@ def test_source_is_target(graph_key, source, targets):
layers_2 = adjust_nodes_capacity(graph_2, 0) # src is 0
targets_2 = [2, 4] # saving 2,4
G2 = create_st_graph(graph_2, targets_2)
reduction_G2_min_cut = max_flow_with_node_capacity(G2, 0)
reduction_G2_min_cut = min_cut_with_node_capacity(G2, 0)
N_2_groups = min_cut_N_groups(reduction_G2_min_cut, layers_2)
matrix_2 = calculate_vaccine_matrix(layers_2, N_2_groups)
integer_matrix_2 = matrix_to_integers_values(matrix_2)
Expand All @@ -101,7 +101,7 @@ def test_source_is_target(graph_key, source, targets):
layers_3 = adjust_nodes_capacity(graph_3, 0) # src is 0
targets_3 = [1, 5, 7] # saving 1,5,7
G3 = create_st_graph(graph_3, targets_3)
reduction_G3_min_cut = max_flow_with_node_capacity(G3, 0)
reduction_G3_min_cut = min_cut_with_node_capacity(G3, 0)
N_3_groups = min_cut_N_groups(reduction_G3_min_cut, layers_3)
matrix_3 = calculate_vaccine_matrix(layers_3, N_3_groups)
integer_matrix_3 = matrix_to_integers_values(matrix_3)
Expand All @@ -113,7 +113,7 @@ def test_source_is_target(graph_key, source, targets):
layers_4 = adjust_nodes_capacity(graph_4, 0) # src is 0
targets_4 = [4, 5, 6, 8] # saving 4,5,6,8
G4 = create_st_graph(graph_4, targets_4)
reduction_G4_min_cut = max_flow_with_node_capacity(G4, 0)
reduction_G4_min_cut = min_cut_with_node_capacity(G4, 0)
N_4_groups = min_cut_N_groups(reduction_G4_min_cut, layers_4)
matrix_4 = calculate_vaccine_matrix(layers_4, N_4_groups)
integer_matrix_4 = matrix_to_integers_values(matrix_4)
Expand Down

0 comments on commit adf9974

Please sign in to comment.