diff --git a/engine/configProcessor.py b/engine/configProcessor.py index 3a99ae3..bf87437 100644 --- a/engine/configProcessor.py +++ b/engine/configProcessor.py @@ -2,14 +2,12 @@ import pandas as pd from functools import partial, reduce def state_identity(k): - def identity(step, sL, s, _input): - return (k, s[k]) - return identity + return lambda step, sL, s, _input: (k, s[k]) +def b_identity(step, sL, s): + return 0 def behavior_identity(k): - def identity(step, sL, s): - return 0 - return identity + return b_identity def key_filter(mechanisms, keyname): return [ v[keyname] for k, v in mechanisms.items() ] @@ -27,10 +25,24 @@ def create_matrix_field(mechanisms, key): identity = behavior_identity df = pd.DataFrame(key_filter(mechanisms, key)) col_list = apply_identity_funcs(identity, df, list(df.columns)) - return reduce((lambda x, y: pd.concat([x, y], axis=1)), col_list) + if len(col_list) != 0: + return reduce((lambda x, y: pd.concat([x, y], axis=1)), col_list) + else: + return pd.DataFrame({'empty' : []}) + def generate_config(mechanisms, env_poc): - bdf = create_matrix_field(mechanisms,'behaviors') - sdf = create_matrix_field(mechanisms,'states') - zipped_list = list(zip(sdf.values.tolist(), bdf.values.tolist())) + def no_behavior_handler(bdf, sdf): + if bdf.empty == False: + sdf_values, bdf_values = sdf.values.tolist(), bdf.values.tolist() + else: + sdf_values = sdf.values.tolist() + bdf_values = [[b_identity] * len(sdf_values)] + return sdf_values, bdf_values + + bdf = create_matrix_field(mechanisms, 'behaviors') + sdf = create_matrix_field(mechanisms, 'states') + sdf_values, bdf_values = no_behavior_handler(bdf, sdf) + zipped_list = list(zip(sdf_values, bdf_values)) + return list(map(lambda x: (x[0] + env_poc, x[1]), zipped_list)) \ No newline at end of file diff --git a/engine/mechanismExecutor.py b/engine/mechanismExecutor.py index e5b2d8f..7231b57 100644 --- a/engine/mechanismExecutor.py +++ b/engine/mechanismExecutor.py @@ -45,7 +45,11 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step): def block_gen(states_list, configs, env_processes, t_step): m_step = 0 + print("states_list") + print(states_list) states_list_copy = deepcopy(states_list) + print("states_list_copy") + print(states_list_copy) genesis_states = states_list_copy[-1] genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step states_list = [genesis_states] @@ -54,7 +58,7 @@ def block_gen(states_list, configs, env_processes, t_step): for config in configs: s_conf, b_conf = config[0], config[1] states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step) - print(b_conf) + # print(b_conf) m_step += 1 t_step += 1 diff --git a/ui/config.py b/ui/config.py index 34754af..19690ea 100644 --- a/ui/config.py +++ b/ui/config.py @@ -105,34 +105,34 @@ env_processes = { mechanisms = { "m1": { "behaviors": { - "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, + # "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, "b2": b2m1 }, "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value - "s1": s1m1, - "s2": s2m1 + # "s1": s1m1, + # "s2": s2m1 } }, - "m2": { - "behaviors": { - "b1": b1m2, - "b2": b2m2 - }, - "states": { - "s1": s1m2, - "s2": s2m2 - } - }, - "m3": { - "behaviors": { - "b1": b1m3, - "b2": b2m3 #toggle for error - }, - "states": { - "s1": s1m3, - "s2": s2m3 - } - } + # "m2": { + # "behaviors": { + # "b1": b1m2, + # "b2": b2m2 + # }, + # "states": { + # "s1": s1m2, + # "s2": s2m2 + # } + # }, + # "m3": { + # "behaviors": { + # "b1": b1m3, + # "b2": b2m3 #toggle for error + # }, + # "states": { + # "s1": s1m3, + # "s2": s2m3 + # } + # } } sim_config = {