Пример #1
0
def test_can_run_gym_interface_on_mixeduse_fan_fcu():
    env = make("MixedUseFanFCU-v0")
    episodes = 2
    n_steps_per_episode = 100
    for _ in range(episodes):
        observation = env.get_output()
        print(observation)
        for _ in range(n_steps_per_episode):
            action = env.sample_random_action()
            observation = env.step(action)
        print("Episode finished")
        env.reset()
    env.close()
Пример #2
0
def test_can_run_gym_interface_on_offices_thermostat():
    env = make("OfficesThermostat-v0")
    episodes = 2
    n_steps_per_episode = 100
    for _ in range(episodes):
        observation = env.get_output()
        print(observation)
        for _ in range(n_steps_per_episode):
            action = env.sample_random_action()
            observation = env.step(action)
        print("Episode finished")
        env.reset()
    env.close()
Пример #3
0
def test_can_run_gym_interface_on_seminarcenter_full():
    env = make("SeminarcenterFull-v0")
    episodes = 2
    n_steps_per_episode = 100
    for _ in range(episodes):
        observation = env.get_output()
        print(observation)
        for _ in range(n_steps_per_episode):
            action = env.sample_random_action()
            observation = env.step(action)
        print("Episode finished")
        env.reset()
    env.close()
Пример #4
0
def test_can_run_gym_interface_on_apartments2_grid():
    env = make("Apartments2Grid-v0")
    episodes = 2
    n_steps_per_episode = 100
    for _ in range(episodes):
        observation = env.get_output()
        print(observation)
        for _ in range(n_steps_per_episode):
            action = env.sample_random_action()
            observation = env.step(action)
        print("Episode finished")
        env.reset()
    env.close()
Пример #5
0
def run_model(model_name: str):
    env = energym.make(model_name)
    print(model_name)
    # Init data record
    N = round((env.stop_time - env.start_time) / env.step_size)
    outputs = env.get_outputs_names()
    record = pd.DataFrame(
        np.zeros((N, len(outputs) + 1)),
        index=np.arange(N) * env.step_size,
        columns=["u"] + outputs,
    )

    model_param(env, model_name)
    ctrl = control_param(model_name)

    # Get states
    out = env.get_variable_data(outputs)

    # Run feedback loop
    tic = time.time()
    for dt in record.index:
        # Get control law
        uval = [[
            controller(out[ctrl["sensor"][n]], ctrl["ref"][n], ctrl["kp"][n],
                       ctrl["bound"][n])
        ] for n in range(len(ctrl["inputs"]))]

        # DoStep
        out = env.step(dict(zip(ctrl["inputs"], uval)))

        # Save into DataFrame
        record.loc[dt, ctrl["inputs"]] = [val[0] for val in uval]
        record.loc[dt, outputs] = [out[key] for key in outputs]

    toc = time.time()
    print("Elapsed time: %.2f s" % (toc - tic))

    return record, env