set_paras.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import sys, os, shutil
  2. model_name = sys.argv[1]
  3. mut_flags = sys.argv[2]
  4. pri_queue_size = sys.argv[3]
  5. init_pop_size = sys.argv[4]
  6. if_sampling = sys.argv[5]
  7. loop = sys.argv[6]
  8. fit = ['all', 'err', 'div']
  9. fitness_func = fit[(int)(sys.argv[7]) - 1]
  10. fitness = sys.argv[7]
  11. print("[" + os.path.basename(__file__) + ", Line " + str(sys._getframe().f_lineno) + ", " + sys._getframe().f_code.co_name + "] " + "model_name: " + model_name + ", mut_flags: " + mut_flags + ", pri_queue_size: " + pri_queue_size +
  12. ", init_pop_size: " + init_pop_size + ", if_sampling: " + if_sampling + ", loop: " + loop + ", fitness_func: " + fitness_func)
  13. if os.path.exists('./error_count.csv'): # clear ./error_count.csv
  14. os.remove('./error_count.csv')
  15. shutil.copy('./error_count_null.csv', './error_count.csv')
  16. if os.path.exists('./r_list.csv'): # clear ./r_list.csv
  17. os.remove('./r_list.csv')
  18. shutil.copy('./r_list_null.csv', './r_list.csv')
  19. if os.path.exists('./sample_num_vgg.csv'): # clear ./sample_num_vgg.csv
  20. os.remove('./sample_num_vgg.csv')
  21. shutil.copy('./sample_num_vgg_null.csv', './sample_num_vgg.csv')
  22. path = '/home/vangogh/software/FuzzScene/code/scenario_runner-0.9.13/_out/'
  23. shutil.rmtree(path + 'center') # 清空out
  24. os.mkdir(path + 'center')
  25. if os.path.exists(path + 'label_test.csv'): # 清空label_test.csv
  26. os.remove(path + 'label_test.csv')
  27. shutil.copy(path + 'label_test_null.csv', path + 'label_test.csv')
  28. f = open("./generate_carla.py", "r+")
  29. new = []
  30. for line in f:
  31. new.append(line)
  32. f.close()
  33. new[16] = 'model_name = "' + model_name + '"\n'
  34. f = open("./generate_carla.py", "w+")
  35. # f.seek(0)
  36. for n in new:
  37. f.write(n)
  38. f.close()
  39. f1 = open("./sampling.py", "r+")
  40. new1 = []
  41. for line in f1:
  42. new1.append(line)
  43. f1.close
  44. new1[5] = 'model_name = "' + model_name + '"\n'
  45. f1 = open("./sampling.py", "w+")
  46. # f1.seek(0)
  47. for n in new1:
  48. f1.write(n)
  49. f1.close()
  50. f2 = open("./fuzz_ga.py", "r+")
  51. new2 = []
  52. for line in f2:
  53. new2.append(line)
  54. f2.close
  55. new2[6] = 'domain_flags = ' + mut_flags + '\n'
  56. new2[8] = 'pri_queue_size = ' + pri_queue_size + '\n'
  57. new2[9] = 'pop_size = ' + init_pop_size + '\n'
  58. new2[14] = 'if_sampling = ' + if_sampling + '\n'
  59. if fitness == "1" and if_sampling == "True":
  60. new2[15] = 'is_err_collection = 1' + '\n'
  61. else:
  62. new2[15] = 'is_err_collection = 0' + '\n'
  63. new2[40] = 'N = ' + loop + '\n'
  64. f2 = open("./fuzz_ga.py", "w+")
  65. # f2.seek(0)
  66. for n in new2:
  67. f2.write(n)
  68. f2.close()
  69. if fitness == "1":
  70. fitness = "r.f[0] += r.f[1] + (r.f[2] - min_val) / minus"
  71. if fitness == "2":
  72. fitness = "r.f[0] += 0"
  73. elif fitness == "3":
  74. fitness = "r.f[0] = r.f[1] + (r.f[2] - min_val) / minus"
  75. f3 = open("./ga.py", "r+")
  76. new3 = []
  77. for line in f3:
  78. new3.append(line)
  79. f3.close
  80. # 修改def calculate_pop_fitness(self, R)的最后一行,下标为修改位置上一行的行号,因为数组从0开始
  81. new3[315] = "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + fitness + '\n'
  82. f3 = open("./ga.py", "w+")
  83. # f3.seek(0)
  84. for n in new3:
  85. f3.write(n)
  86. f3.close()
  87. f4 = open("./rename.py", "r+") # 重命名
  88. new4 = []
  89. for line in f4:
  90. new4.append(line)
  91. f4.close
  92. new4[3] = 'model_name="' + model_name + '"\n'
  93. new4[4] = 'if_sampling="' + if_sampling + '"\n'
  94. new4[5] = 'fitness_func="' + fitness_func + '"\n'
  95. f4 = open("./rename.py", "w+")
  96. # f4.seek(0)
  97. for n in new4:
  98. f4.write(n)
  99. f4.close()