You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to be able to implement a switch activity that combines multiple enum parameters for the selection of other activities.
For example, rather than creating a first switch activity switch_act_1 controlled by switch_param_1 that points to switch_act_2a and switch_act_2b both of which are controlled by parameter switch_param_2, it could be possible to create a single multi_switch_act controlled by the combination of switch_param_1 and switch_param_2.
Here is an example :
multi_switch_act = newMultiSwitchAct(MYDB, "MultiSwitchAct", [switchParam1, switchParam2], {
("switchParam1_val1", switchParam2_val1) : act1 # act1 is selected if both switchParam1 = switchParam1_val1 and switchParam2 = switchParam2_val1
("switchParam1_val2", switchParam2_val2) : (act2, 0.4) # act2 is selected if both switchParam1 = switchParam1_val2 and switchParam2 = switchParam2_val2
("switchParam1_val1", switchParam2_val2) : (act3, b + 6) # act3 is selected if both switchParam1 = switchParam1_val1 and switchParam2 = switchParam2_val2
}
This could be done by modifying the newSwitchAct() method as follows:
def newMultiSwitchAct(dbname, name, paramDefList: Union[List[ParamDef], ParamDef], acts_dict: Union[Dict[str, ActivityOrActivityAmount], Dict[Tuple[str], ActivityOrActivityAmount]]):
exch = defaultdict(lambda: 0)
unit = None
for key, act in acts_dict.items():
amount = 1
if isinstance(act, (list, tuple)):
act, amount = act
if isinstance(paramDefList, list): # <-- this is new
exch[act] += amount * reduce(lambda x, y: x*y, [paramDef.symbol(key[i]) for i, paramDef in enumerate(paramDefList)])
else: # <-- regular switch activity
exch[act] += amount * paramDefList.symbol(key)
unit = act["unit"]
res = newActivity(dbname, name, unit=unit, exchanges=exch)
return res
This should work for any number of enum parameters (not only two).
The text was updated successfully, but these errors were encountered:
It would be nice to be able to implement a switch activity that combines multiple enum parameters for the selection of other activities.
For example, rather than creating a first switch activity
switch_act_1
controlled byswitch_param_1
that points toswitch_act_2a
andswitch_act_2b
both of which are controlled by parameterswitch_param_2
, it could be possible to create a singlemulti_switch_act
controlled by the combination ofswitch_param_1
andswitch_param_2
.Here is an example :
This could be done by modifying the
newSwitchAct()
method as follows:This should work for any number of enum parameters (not only two).
The text was updated successfully, but these errors were encountered: