realtwin.func_lib.BehaviorCali
- class realtwin.func_lib.BehaviorCali(scenario_config: dict = None, behavior_config: dict = None, verbose: bool = True)[source]
Behavior Optimization class for SUMO calibration
- Parameters:
scenario_config (dict) – the configuration for the scenario.
behavior_config (dict) – the configuration for the behavior.
verbose (bool) – whether to print the log. Defaults to True.
Notes
- We use the mealpy library for optimization. mealpy is a Python library for optimization algorithms.
The init_solution parameter is used to provide initial solutions for the population. None by default.
Behavior includes: min_gap(meters), acceleration(m/s^2), deceleration(m/s^2), sigma, tau, and emergencyDecel.
See also
Problem_dict: https://mealpy.readthedocs.io/en/latest/pages/general/simple_guide.html termination_dict: https://mealpy.readthedocs.io/en/latest/pages/general/advance_guide.html#stopping-condition-termination
Examples
>>> from realtwin import BehaviorOpt >>> prob_dict = {"obj_func": partial(fitness_func, scenario_config=scenario_config, error_func="rmse"), "bounds": FloatVar(lb=[1.0, 2.5, 4, 0.0, 0.25, 5.0], ub=[3.0, 3.0, 5.3, 1.0, 1.25, 9.3],), "minmax": "max", # maximize or minimize "log_to": "console", "save_population": True} >>> init_solution = [2.5, 2.6, 4.5, 0.5, 1.0, 9.0] >>> term_dict = {"max_epoch": 500, "max_fe": 10000, "max_time": 3600, "max_early_stop": 20} >>> opt = BehaviorOpt(problem_dict=prob_dict, init_solution=init_solution, term_dict=term_dict) >>> g_best, model_opt = opt.run_GA(epoch=1000, pop_size=30, pc=0.95, pm=0.1, sel_model="BaseGA")
Save result figures to output_dir >>> opt.run_vis(output_dir=”output_dir”, model=model_opt) >>> print(g_best.solution) >>> print(g_best.target.fitness)
Methods
__init__([scenario_config, behavior_config, ...])run_GA(**kwargs)Run Genetic Algorithm (GA) for behavior optimization.
run_SA(**kwargs)Run Simulated Annealing (SA) for behavior optimization.
run_TS(**kwargs)Run Tabu Search (TS) for behavior optimization.
run_vis(output_dir, model)Save the results of the optimization.