1+ import sys
12from operator import itemgetter
23from typing import List
34
4- from src .utils import print_adjacency_matrix_csv , adjacency_list_to_adjacency_matrix , \
5- generate_adjacency_list_without_cycles
5+ import matplotlib .pyplot as plt
6+
7+ from src .performance import get_n_exec_time
8+ from src .utils import generate_adjacency_list_without_cycles
69
710
811def main ():
9- # graph = [[1, 2], [2], [3], [4], []]
10- # graph = [[1, 2], [2], [3], [4, 5], [], [6], []]
11- # print(grundy(graph))
12+ if len (sys .argv ) != 4 :
13+ sys .exit ("Usage : <min_graph_size> <max_graph_size> <number_of_executions>" )
14+
15+ min_graph_size = int (sys .argv [1 ])
16+ max_graph_size = int (sys .argv [2 ]) + 1
17+ number_of_executions = int (sys .argv [3 ])
18+
19+ if min_graph_size < 1 or max_graph_size < min_graph_size or number_of_executions < 1 :
20+ sys .exit ("Invalid arguments." )
21+
22+ print ("{} executions" .format (number_of_executions ))
23+
24+ line1 = []
25+
26+ for i in range (min_graph_size , max_graph_size ):
27+ sys .stdout .write ('{0:.1f}% processed ({1} vertices) \r ' .format ((i + 1 ) / max_graph_size * 100 , i ))
28+ sys .stdout .flush ()
29+
30+ line1 .append (get_n_exec_time (grundy , number_of_executions , generate_adjacency_list_without_cycles (i )))
31+
32+ vertices_number = [* range (1 , max_graph_size )]
33+ plt .plot (vertices_number , line1 , label = 'Grundy' )
1234
13- for i in range (1 ):
14- print_adjacency_matrix_csv (adjacency_list_to_adjacency_matrix (generate_adjacency_list_without_cycles (8 )))
35+ plt .grid ()
1536
16- # print(adjacency_list_to_adjacency_matrix(generate_adjacency_list_without_cycles(5)))
37+ plt .ylabel ('Average exec time (in seconds)' )
38+ plt .xlabel ('Number of vertices' )
39+ plt .title ('Average exec time of grundy value algorithm ({} execs)' .format (number_of_executions ))
40+ plt .legend ()
41+ plt .show ()
1742
1843
1944def leveling (adjacency_list : List [List [int ]]) -> List [int ]:
@@ -31,7 +56,7 @@ def leveling(adjacency_list: List[List[int]]) -> List[int]:
3156 for k in range (len (adjacency_list [j ])):
3257
3358 if adjacency_list [j ][k ] == no_successor_vertices [i ]:
34- no_successor_vertices .append (j )
59+ no_successor_vertices .append (j ) # <-- bug here
3560
3661 if graph_leveling [j ] < (graph_leveling [no_successor_vertices [i ]] + 1 ):
3762 graph_leveling [j ] = graph_leveling [no_successor_vertices [i ]] + 1
0 commit comments