Heating controller with neural thermal model written in Python
Jacek Kowalski
2018-06-24 66a9fb40efe1311b34a3cee3f83f10c6990759af
commit | author | age
425bf7 1 #!/usr/bin/python3
JK 2
3 import collections
4 import functools
5 import time
6
7 from lib.ArgParser import get_config, get_model_from_config
8 from lib.Controller import simulate, ReplayController
9 from lib.Cost import DeviationCost, NegativeCost
10 from lib.Env import CentralHeatingHistoryEnv
11
12 # ARGS
13 config = get_config()
14
15 name_past_future = (
16     ('past', ('temp_in', 'temp_out', 'mode'), ()),
17 )
18
19 for name, past, future in name_past_future:
20     config['model_past_fields'] = past
21     config['model_future_fields'] = future
22
23     # MODEL
24     start_time = time.clock()
25     model = get_model_from_config(config)
26     end_time = time.clock()
27
28     # PLOT
29     config['plot_fields'] = ['time', 'temp_in', 'temp_in_calc']
30     config['past_fields'] = ['mode']
31     config['past_values'] = 1
32     config['future_values'] = 0
33
34     # ENV
35     env = CentralHeatingHistoryEnv()
36     env.cost_class = DeviationCost
37     env.model = model
38     env.config = config
39     env.reset()
40
41     # MAIN
42     controller = ReplayController()
43     simulate(env, controller, render=False)
44
45     model = config['model_type'].split('_')[-1]
46     if model == 'neural':
47         model = 'base'
48     print('RESULT {} {} {} {}'.format(model, env.cost.costs['diff'], env.cost.costs['sq_err'], end_time - start_time))