set_para.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import sys, os, shutil
  2. model_name = sys.argv[1]
  3. if_sampling = "False" if sys.argv[2] == "0" else "True"
  4. fit = ['all', 'err', 'div']
  5. fitness_func = fit[(int)(sys.argv[3]) - 1]
  6. fitness = sys.argv[3]
  7. print(model_name + "_" + if_sampling + "_" + fitness_func)
  8. if os.path.exists('./error_count.csv'): # clear ./error_count.csv
  9. os.remove('./error_count.csv')
  10. shutil.copy('./error_count_null.csv', './error_count.csv')
  11. if os.path.exists('./r_list.csv'): # clear ./r_list.csv
  12. os.remove('./r_list.csv')
  13. shutil.copy('./r_list_null.csv', './r_list.csv')
  14. f = open("./generate_carla.py", "r+")
  15. new = []
  16. for line in f:
  17. new.append(line)
  18. f.close()
  19. new[13] = 'model_name = "' + model_name + '"\n'
  20. f = open("./generate_carla.py", "w+")
  21. for n in new:
  22. f.write(n)
  23. f.close()
  24. f1 = open("./sampling.py", "r+")
  25. new1 = []
  26. for line in f1:
  27. new1.append(line)
  28. f1.close()
  29. new1[5] = 'model_name = "' + model_name + '"\n'
  30. f1 = open("./sampling.py", "w+")
  31. for n in new1:
  32. f1.write(n)
  33. f1.close()
  34. f2 = open("./fuzz_ga.py", "r+")
  35. new2 = []
  36. for line in f2:
  37. new2.append(line)
  38. f2.close()
  39. new2[12] = 'if_sampling = ' + if_sampling + '\n'
  40. if fitness == "1" and if_sampling == "True":
  41. new2[13] = 'is_err_collection = 1' + '\n'
  42. else:
  43. new2[13] = 'is_err_collection = 0' + '\n'
  44. f2 = open("./fuzz_ga.py", "w+")
  45. for n in new2:
  46. f2.write(n)
  47. f2.close()
  48. if fitness == "1":
  49. fitness = "r.f[0] += r.f[1] + (r.f[2] - min_val) / minus"
  50. if fitness == "2":
  51. fitness = "r.f[0] += 0"
  52. elif fitness == "3":
  53. fitness = "r.f[0] = r.f[1] + (r.f[2] - min_val) / minus"
  54. f3 = open("./ga.py", "r+")
  55. new3 = []
  56. for line in f3:
  57. new3.append(line)
  58. f3.close()
  59. new3[246] = "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20" + fitness + '\n'
  60. f3 = open("./ga.py", "w+")
  61. for n in new3:
  62. f3.write(n)
  63. f3.close()
  64. f4 = open("./rename.py", "r+")
  65. new4 = []
  66. for line in f4:
  67. new4.append(line)
  68. f4.close()
  69. new4[3] = 'model_name = "' + model_name + '"\n'
  70. new4[4] = 'if_sampling = "' + if_sampling + '"\n'
  71. new4[5] = 'fitness_func = "' + fitness_func + '"\n'
  72. f4 = open("./rename.py", "w+")
  73. for n in new4:
  74. f4.write(n)
  75. f4.close()
  76. path = '../scenario_runner-0.9.13/_out/'
  77. shutil.rmtree(path + 'center')
  78. os.mkdir(path + 'center')
  79. if os.path.exists(path + 'label_test.csv'):
  80. os.remove(path + 'label_test.csv')
  81. shutil.copy(path + 'label_test_null.csv', path + 'label_test.csv')