Parcourir la source

Check only one occurence when restart

Jérôme BUISINE il y a 3 ans
Parent
commit
0d0f8eeaac
1 fichiers modifiés avec 15 ajouts et 2 suppressions
  1. 15 2
      find_best_attributes_surrogate.py

+ 15 - 2
find_best_attributes_surrogate.py

@@ -260,8 +260,21 @@ def main():
 
 
 
 
     line_info = p_output + ';' + p_data_file + ';' + str(bestSol.data) + ';' + str(list(bestSol.data).count(1)) + ';' + str(filters_counter) + ';' + str(bestSol.fitness)
     line_info = p_output + ';' + p_data_file + ';' + str(bestSol.data) + ';' + str(list(bestSol.data).count(1)) + ';' + str(filters_counter) + ';' + str(bestSol.fitness)
-    with open(filename_path, 'a') as f:
-        f.write(line_info + '\n')
+
+    # check if results are already saved...
+    already_saved = False
+    with open(filename_path, 'r') as f:
+        lines = f.readlines()
+
+        for line in lines:
+            output_name = line.split(';')[0]
+            
+            if p_output == output_name:
+                already_saved = True
+
+    if not already_saved:
+        with open(filename_path, 'a') as f:
+            f.write(line_info + '\n')
     
     
     print('Result saved into %s' % filename_path)
     print('Result saved into %s' % filename_path)