Coverage for examples/SimpleBuilding/main_single_run.py: 95%
22 statements
« prev ^ index » next coverage.py v7.4.4, created at 2026-03-26 09:43 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2026-03-26 09:43 +0000
1import logging
2from agentlib_flexquant.generate_flex_agents import FlexAgentGenerator
3from agentlib.utils.multi_agent_system import LocalMASAgency
5logging.basicConfig(level=logging.WARN)
6until = 3600 * 24
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"
14def run_example(until=until):
15 """Runs MAS simulation with specified flex event duration.
17 mpc_config:
18 Sets inputs, outputs, states, and parameters for the MPC agent.
19 It points to the path of the MPC problem definition file (simple_building.py) and defines the MPC parameters.
20 sim_config:
21 Sets inputs, outputs, and states for the simulation agent.
22 It points to the path of the FMU file and defines the simulation parameters.
23 predictor_config:
24 Sets parameters for the predictor agent and points to the path of the predictor formulation file (predictor.py).
25 flex_config:
26 Sets various options for the flexibility quantification framework:
27 - characteristic times for the indicator module (e.g. market time, preparation time, flex event duration)
28 - options for the cost calculation
29 - whether to use a constant electricity price or to input a time series sent by the predictor agent
30 - whether to use a constant feed-in tariff or to input a time series sent by the predictor agent
31 - if no feed-in is required (e.g. for a house without electricity generation), use a constant feed-in tariff with value 0
32 - option to correct the cost for stored energy at the end of the prediction horizon
33 - option to include a market config (points to a market config file)
34 - options for the flexibility agent generator:
35 - power variable of the baseline agent
36 - cost functions of PF-MPC and NF-MPC agents, including custom parameters and variables for the shadow MPCs
37 - general options such as results paths
39 """
41 generator = FlexAgentGenerator(
42 flex_config=flex_config, mpc_agent_config=mpc_config
43 )
45 config_list = generator.generate_flex_agents()
46 sim_config_new = generator.adapt_sim_results_path(sim_config, save_name_suffix="_temp")
48 agent_configs = [sim_config_new, predictor_config]
49 agent_configs.extend(config_list)
51 mas = LocalMASAgency(
52 agent_configs=agent_configs, env=ENV_CONFIG, variable_logging=False
53 )
54 mas.run(until=until)
55 results = mas.get_results(cleanup=False)
56 return results
59if __name__ == "__main__":
60 # Here the simulation is run once,
61 # generated files are stored in --> the current working directory
62 # For an example with multiple runs, see: examples\SimpleBuilding\main_multi_run.py
63 # For plotting of results generated from this main file,
64 # see: examples\SimpleBuilding\plot_results_single.py
65 run_example(until)