def test_parameters(self): # initialize Params p = ParameterServer() # TODO: this has to be the ParameterServer # set new parameter self.assertTrue(p["LetsTest"]["hierarchy", "bla", True]) # check whether right value is recovered tester = p["Car"]["Length", "Car Length", 6] tester2 = p["Car"]["Length", "Car Length", 8] self.assertEqual(tester, 6) self.assertEqual( tester2, 6) # value should not change, since key already exists in dict # check whether access without description and default value is possible self.assertEqual(p["Car"]["Length"], 6) # check whether setting values works p["Age"] = 24 self.assertEqual(p["Age"], 24) p["Localization"]["Number of Particles"] = 2000 self.assertEqual(p["Localization"]["Number of Particles"], 2000) # C++ Test in /modules/commons/Params/params_test.h # write in parameters in C++ and check whether they can be accessed in python afterwards #ParamsTest(p) #self.assertEqual(p["param_cpp"], 16.5) # add child in python child = p.AddChild("ch") self.assertTrue(child["ChildTest"]["hierarchy", "bla", True]) # write parameters to json file p.Save("written_a_param_test.json")
def test_write_params_agent(self): params = ParameterServer() behavior = BehaviorConstantVelocity(params) execution = ExecutionModelInterpolate(params) dynamic = SingleTrackModel(params) shape = Polygon2d([1.25, 1, 0], [ Point2d(0, 0), Point2d(0, 2), Point2d(4, 2), Point2d(4, 0), Point2d(0, 0) ]) init_state = np.zeros(4) agent = Agent(init_state, behavior, dynamic, execution, shape, params.AddChild("agent")) params.Save("written_agents_param_test.json")
def test_configurable_scenario_generation_default_params(self): params = ParameterServer() scenario_generation = ConfigurableScenarioGeneration(num_scenarios=2, params=params) scenario_generation.dump_scenario_list("test.scenario") scenario_loader = ScenarioGeneration() scenario_loader.load_scenario_list("test.scenario") self.assertEqual(len(scenario_loader._scenario_list), 2) self.assertEqual( len(scenario_loader._scenario_list[0]._agent_list), len(scenario_generation._scenario_list[0]._agent_list)) scenario = scenario_loader.get_scenario(idx=0) params.Save("default_params.json")
def test_configurable_scenario_generation_sample_behavior_types(self): sink_source_dict = [{ "SourceSink": [[5111.626, 5006.8305], [5110.789, 5193.1725]], "Description": "left_lane", "ConfigAgentStatesGeometries": { "Type": "UniformVehicleDistribution", "LanePositions": [0] }, "ConfigBehaviorModels": { "Type": "FixedBehaviorType", "ModelType": "BehaviorIDMClassic", "ModelParams": { "BehaviorIDMClassic::MaxVelocity": 60.0 } }, "ConfigExecutionModels": { "Type": "FixedExecutionType" }, "ConfigDynamicModels": { "Type": "FixedDynamicType" }, "ConfigGoalDefinitions": { "Type": "FixedGoalTypes" }, "ConfigControlledAgents": { "Type": "NoneControlled" }, "AgentParams": {} }, { "SourceSink": [[5111.626, 5006.8305], [5110.789, 5193.1725]], "Description": "right_lane", "ConfigAgentStatesGeometries": { "Type": "UniformVehicleDistribution", "LanePositions": [1] }, "ConfigBehaviorModels": { "Type": "SampleBehaviorType" }, "ConfigExecutionModels": { "Type": "FixedExecutionType" }, "ConfigDynamicModels": { "Type": "FixedDynamicType" }, "ConfigGoalDefinitions": { "Type": "FixedGoalTypes" }, "ConfigControlledAgents": { "Type": "RandomSingleAgent" }, "AgentParams": {} }] params = ParameterServer() params["Scenario"]["Generation"]["ConfigurableScenarioGeneration"][ "SinksSources"] = sink_source_dict scenario_generation = ConfigurableScenarioGeneration(num_scenarios=2, params=params) scenario_generation.dump_scenario_list("test.scenario") params.Save("default_params_behavior_type_sampling.json")