Coverage for examples/CustomMarketPlugin/run_example.py: 95%

22 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2026-06-17 09:09 +0000

1import logging 

2from agentlib_flexquant.generate_flex_agents import FlexAgentGenerator 

3from agentlib.utils.multi_agent_system import LocalMASAgency 

4 

5logging.basicConfig(level=logging.WARN) 

6until = 3600 * 24 

7 

8ENV_CONFIG = {"rt": False, "factor": 0.002, "t_sample": 1} 

9sim_config = "mpc_and_sim/fmu_config.json" 

10mpc_config = "mpc_and_sim/simple_building.json" 

11predictor_config = "predictor/predictor_config.json" 

12flex_config = "flex_configs/flexibility_agent_config.json" 

13 

14def run_example(until=until): 

15 """ Run the SimpleBuilding MAS example with a custom flexibility plugin. 

16 

17 The custom plugin is implemented in agentlib_plugin, loaded via the 

18 flexibility_agent_config, and configured in market.json. 

19 

20 See the README for a detailed step-by-step guide. As this example is based on the SimpleBuilding 

21 example, further details can be found inside its example folder.  

22 """ 

23 

24 generator = FlexAgentGenerator( 

25 flex_config=flex_config, mpc_agent_config=mpc_config 

26 ) 

27 

28 config_list = generator.generate_flex_agents() 

29 sim_config_new = generator.adapt_sim_results_path(sim_config, save_name_suffix="_temp") 

30 

31 agent_configs = [sim_config_new, predictor_config] 

32 agent_configs.extend(config_list) 

33 

34 mas = LocalMASAgency( 

35 agent_configs=agent_configs, env=ENV_CONFIG, variable_logging=False 

36 ) 

37 mas.run(until=until) 

38 results = mas.get_results(cleanup=False) 

39 return results 

40 

41 

42if __name__ == "__main__": 

43 # Here the simulation is run once,  

44 # generated files are stored in --> the current working directory 

45 # For an example with multiple runs, see: examples\SimpleBuilding\main_multi_run.py 

46 # For plotting of results generated from this main file,  

47 # see: examples\SimpleBuilding\plot_results_single.py 

48 run_example(until)