Heating controller with neural thermal model written in Python
Jacek Kowalski
2018-06-24 425bf71fc0b24b547006686d83404c54b983de0b
commit | author | age
425bf7 1 #!/usr/bin/python3
JK 2
3 import collections
4 import functools
5
6 from lib.ArgParser import get_config, get_model_from_config
7 from lib.Controller import simulate, BruteForceController, CostController, ReplayController, ThermostatController
8 from lib.Cost import NegativeCost, NegativeCostExtendedRange
9 from lib.Env import CentralHeatingHistoryEnv
10
11 # ARGS
12 config = get_config(uses_future=True)
13
14 # MODEL
15 model = get_model_from_config(config)
16
17 # PLOT
18 config['plot_fields'] = ['time', 'temp_in_calc', 'temp_out', 'temperature', 'mode_calc']
19 config['future_values'] += config['model_future_values']
20
21 # MAIN
22 plot = collections.OrderedDict()
23
24 for controller_type, controller in (
25     ('controler', BruteForceController(model=model, cost_calculator_class=NegativeCost, config=config)),
26     ('thermostat', ThermostatController(19.6, 20.4))
27 ):
28     env = CentralHeatingHistoryEnv()
29     env.model = model
30     env.config = config
31     env.cost_class = NegativeCostExtendedRange
32     env.reset()
33     
34     simulate(env, controller, render=False)
35     
36     plot['time'] = env.window.plot['time']
37     plot['temp_out'] = env.window.plot['temp_out']
38     plot['temp_in_' + controller_type] = env.window.plot['temp_in_calc']
39     plot['mode_' + controller_type] = env.window.plot['mode_calc']
40
41 print(plot.keys())
42 env.window.plot = plot
43
44 env.render()