1- import expirements_csv
2- # add the comparisons test from both heuristic files + add a function that will plot the graphs.
3- # TBD
1+ """
42
3+ The Paper -
4+ Approximability of the Firefighter Problem Computing Cuts over Time
5+
6+ Paper Link -
7+ https://www.math.uwaterloo.ca/~cswamy/papers/firefighter-journ.pdf
8+
9+ Authors -
10+ Elliot Anshelevich
11+ Deeparnab Chakrabarty
12+ Ameya Hate
13+ Chaitanya Swamy
14+
15+ Developers -
16+ Yuval Bubnovsky
17+ Almog David
18+ Shaked Levi
19+
20+ """
21+
22+ import experiments_csv
23+ from experiments_csv import *
24+ import logging
25+ logger = logging .getLogger (__name__ )
26+
27+
28+ from networkz .algorithms .approximation .firefighter_problem .Utils import *
29+ from networkz .algorithms .approximation .firefighter_problem .Firefighter_Problem import *
30+ from networkz .algorithms .approximation .tests .test_firefighter_problem .test_non_spreading_dirlaynet_minbudget import generate_layered_network
31+ from matplotlib import pyplot as plt
32+
33+ def setup_global_logger (level : int = logging .DEBUG ):
34+ log_format = "|| %(asctime)s || %(levelname)s || %(message)s"
35+ date_format = '%H:%M:%S'
36+ formatter = logging .Formatter (log_format , datefmt = date_format )
37+ handler = logging .StreamHandler ()
38+ handler .setFormatter (formatter )
39+
40+ root_logger = logging .getLogger ()
41+ root_logger .setLevel (level )
42+ root_logger .addHandler (handler )
43+
44+ G_dirlay_random = generate_layered_network ()
45+
46+ def runner_no_spreading (algorithm ):
47+ graph = G_dirlay_random .copy ()
48+ source = 0
49+ targets = [2 ,4 ,6 ,7 ,8 ,9 ,20 ,15 ]
50+
51+ if algorithm == heuristic_minbudget :
52+ return {"Budget" : (algorithm (Graph = graph ,source = source ,targets = targets ,spreading = False ))}
53+
54+ else :
55+ return {"Budget" : (algorithm (Graph = graph ,source = source ,targets = targets ))}
56+
57+
58+ def runner_spreading (algorithm ):
59+ graph = G_dirlay_random .copy ()
60+ source = 0
61+ targets = [2 ,4 ,6 ,7 ,8 ,9 ,20 ,15 ]
62+
63+ if algorithm == heuristic_minbudget :
64+ return {"Budget" : (algorithm (Graph = graph ,source = source ,targets = targets ,spreading = True ))}
65+
66+ if algorithm == heuristic_maxsave :
67+ return {"Budget" : (algorithm (Graph = graph ,budget = 1 , source = source ,targets = targets ,spreading = True ))}
68+
69+ if algorithm == spreading_maxsave :
70+ return {"Budget" : (algorithm (Graph = graph ,budget = 1 , source = source ,targets = targets ))}
71+
72+ else :
73+ return {"Budget" : (algorithm (Graph = graph ,source = source ,targets = targets ))}
74+
75+
76+ if __name__ == "__main__" :
77+ setup_global_logger (level = logging .DEBUG )
78+
79+
80+ G_dirlay_random = generate_layered_network () #random graph generator for dirlay testings/ can also fit other algorithms but dirlay
81+
82+ ex1 = experiments_csv .Experiment ("./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/" , "non_spreading.csv" , backup_folder = None )
83+ ex1 .clear_previous_results () # to clear previous experminets..
84+
85+ input_ranges = {
86+ "algorithm" :[non_spreading_dirlaynet_minbudget ,non_spreading_minbudget ,heuristic_minbudget ],
87+ }
88+ ex1 .run_with_time_limit (runner_no_spreading ,input_ranges , time_limit = 0.9 )
89+
90+ """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """"""
91+
92+ ex2 = experiments_csv .Experiment ("./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/" , "spreading.csv" , backup_folder = None )
93+ ex2 .clear_previous_results () # to clear previous experminets..
94+
95+ input_ranges = {
96+ "algorithm" :[spreading_minbudget ,spreading_maxsave ,heuristic_minbudget ,heuristic_maxsave ],
97+ }
98+ ex2 .run_with_time_limit (runner_spreading ,input_ranges , time_limit = 0.9 )
99+
100+
101+ #Plotting:
102+
103+ single_plot_results ("./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/non_spreading.csv" ,
104+ filter = {},
105+ x_field = "algorithm" ,
106+ y_field = "runtime" ,
107+ z_field = "Budget" ,
108+ save_to_file = "./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/non_spreading.png" )
109+
110+ print ("\n DataFrame-NonSpread: \n " , ex1 .dataFrame )
111+
112+
113+ single_plot_results ("./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/spreading.csv" ,
114+ filter = {},
115+ x_field = "algorithm" ,
116+ y_field = "runtime" ,
117+ z_field = "Budget" ,
118+ save_to_file = "./networkz/algorithms/approximation/tests/test_firefighter_problem/comparisons/spreading.png" )
119+
120+ print ("\n DataFrame-Spreading: \n " , ex2 .dataFrame )
0 commit comments