Coverage for examples/OneRoom_SimpleMPC/main_one_room_flex.py: 92%
25 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-10-20 14:09 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-10-20 14:09 +0000
1import logging
2from agentlib_flexquant.generate_flex_agents import FlexAgentGenerator
3from agentlib.utils.multi_agent_system import LocalMASAgency
4from agentlib_flexquant.utils.interactive import Dashboard, CustomBound
5from plot_results import plot_results
7# Set the log-level
8logging.basicConfig(level=logging.WARN)
9until = 21600
11ENV_CONFIG = {"rt": False, "factor": 0.01, "t_sample": 60}
14def run_example(until=until, with_plots=False):
15 """ Example with market usage
17 Change flex_power_feedback_method in MarketSpecifications to deal with systems with
18 fast or slow inertia.
19 See difference in results: when using collocation, power during flex event does not
20 fully follow offer. When using constant it does. Reason is the fast inertia of the
21 system.
23 """
25 results = []
26 mpc_config = "mpc_and_sim/simple_model.json"
27 sim_config = "mpc_and_sim/simple_sim.json"
28 predictor_config = "predictor/predictor_config.json"
29 flex_config = "flex_configs/flexibility_agent_config.json"
30 agent_configs = [sim_config, predictor_config]
32 config_list = FlexAgentGenerator(
33 flex_config=flex_config, mpc_agent_config=mpc_config
34 ).generate_flex_agents()
35 agent_configs.extend(config_list)
37 mas = LocalMASAgency(
38 agent_configs=agent_configs, env=ENV_CONFIG, variable_logging=False
39 )
41 mas.run(until=until)
42 results = mas.get_results(cleanup=False)
44 if with_plots:
45 Dashboard(
46 flex_config="flex_configs/flexibility_agent_config.json",
47 simulator_agent_config="mpc_and_sim/simple_sim.json",
48 results=results
49 ).show(
50 custom_bounds=CustomBound(
51 for_variable="T",
52 lb_name="T_lower",
53 ub_name="T_upper"
54 )
55 )
56 # plot_results(results_data=results) # Alternative plotscript using matplotlib,
57 return results
60if __name__ == "__main__":
61 run_example(until, with_plots=True)