def generate_and_run_mutation(sut, initial_state, environment, initial_mission, number_of_missions): mission_generator = MutationBasedMissionGenerator( sut, initial, environment, initial_mission, action_generators=[ CircleBasedGotoGenerator((-35.3632607, 149.1652351), 2.0) ]) resource_limits = ResourceLimits(number_of_missions * 5, 1000, number_of_missions) mission_generator.generate_and_run(100, resource_limits, with_coverage=True) print("DONE") with open("example/missions-mutation.json", "w") as f: mission_descriptions = list( map(Mission.to_json, mission_generator.history)) print(str(mission_descriptions)) json.dump(mission_descriptions, f) f.write("\n") mission_descriptions = list( map(Mission.to_json, mission_generator.most_fit_missions)) print(str(mission_descriptions)) json.dump(mission_descriptions, f)
def generate_and_run(sut, initial, environment, number_of_missions): mission_generator = RandomMissionGenerator(sut, initial, environment) resource_limits = ResourceLimits(number_of_missions, 1000) mission_generator.generate_and_run(100, resource_limits) #mission_generator.prepare(100, resource_limits) #for i in range(number_of_missions): # m = mission_generator.generate_mission() # print("Mission {}: {}".format(i, m.to_json())) # res = sandbox.run(m) print("DONE")
def generate(num_missions: int, max_num_commands: int, seed: int, output_file: str, speedup: int) -> None: random.seed(seed) config = build_config(speedup) mission_generator = RandomMissionGenerator( sut, initial, environment, config, max_num_commands=max_num_commands) resource_limits = ResourceLimits(num_missions) missions = mission_generator.generate(None, resource_limits) with open(output_file, "w") as f: mission_descriptions = list(map(Mission.to_dict, missions)) json.dump(mission_descriptions, f, indent=2)
def generate(sut, initial, environment, config, number_of_missions, max_num_commands=3): mission_generator = RandomMissionGenerator( sut, initial, environment, config, max_num_commands=max_num_commands ) #action_generators=[CircleBasedGotoGenerator((-35.3632607, 149.1652351), 2.0)]) resource_limits = ResourceLimits(number_of_missions, 1000) missions = mission_generator.generate(100, resource_limits) print("### {}".format(missions)) with open("example/missions.json", "w") as f: mission_descriptions = list(map(Mission.to_dict, missions)) print(str(mission_descriptions)) json.dump(mission_descriptions, f)
def generate_and_run_with_fl(sut, initial, environment, number_of_missions): mission_generator = RandomMissionGenerator( sut, initial, environment, max_num_commands=3, action_generators=[ CircleBasedGotoGenerator((-35.3632607, 149.1652351), 2.0) ]) resource_limits = ResourceLimits(number_of_missions, 1000) report = mission_generator.generate_and_run(100, resource_limits, with_coverage=True) print("DONE") print(report) print(mission_generator.coverage) print(mission_generator.report_fault_localization()) with open("fl.json", "w") as f: f.write(str(mission_generator.report_fault_localization()))
def test_random(): config = ArduConfig( speedup=1, time_per_metre_travelled=5.0, constant_timeout_offset=1.0, min_parachute_alt=10.0) environment = Environment({}) initial = CopterState( home_latitude=-35.3632607, home_longitude=149.1652351, latitude=-35.3632607, longitude=149.1652351, altitude=0.0, armed=False, armable=True, mode="GUIDED", ekf_ok=True, yaw=0.0, roll=0.0, pitch=0.0, # roll_channel=0.0, # throttle_channel=0.0, heading=0.0, groundspeed=0.0, airspeed=0.0, vx=0.0, vy=0.0, vz=0.0, time_offset=0.0) sut = ArduCopter max_num_commands = 5 number_of_missions = 10 mission_generator = RandomMissionGenerator(sut, initial, environment, config, max_num_commands=max_num_commands) resource_limits = ResourceLimits(number_of_missions, 1000) missions = mission_generator.generate(100, resource_limits) assert len(missions) == number_of_missions assert all(len(m.commands) <= max_num_commands for m in missions)