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