I want to limit the share of flow from a transformer to a bus by certain factor which is mentioned by share_in_bus. I tried to incorporate equate_variables function from solph.constraints. However, the function gives me ValueError, I think it could not distinguish between Investmenflow and the actual flow. How can I change my code so that it know which flow to take into consideration?
Any hints would be much appreciated,
Regards,
Dev
def add_flow_limits(projectname, om, bus_i, tech_i, H):
project = projectname
input_dir = f'input\\input_table_{project}.xlsx'
input_fl = pd.read_excel(input_dir, sheet_name='flow_limits', header=12)
for i, fl in input_fl.iterrows():
if not fl['include']:
continue
from_transformer = tech_i[fl['from_transformer']]
to_bus = bus_i[fl['to_bus']]
flow_from_transformer = sum(om.flow[i, o, t] for (i, o) in om.FLOWS if i == from_transformer
for t in om.TIMESTEPS)
total_flow_to_bus = sum(
om.flow[i, o, t] for (i, o) in om.FLOWS if o == to_bus for t in om.TIMESTEPS
)
if fl['comparison'] == 'equal':
constraints.equate_variables(
om,
flow_from_transformer,
total_flow_to_bus,
factor1=fl['share_in_bus'],
name='flow_limit_equal',
)
elif fl['comparison'] == 'greater_than':
constraints.equate_variables(
om,
flow_from_transformer,
total_flow_to_bus,
factor1=fl['share_in_bus'],
name='flow_limit_greater',
)
om.flow_limit_greater.lower = 0
elif fl['comparison'] == 'smaller_than':
constraints.equate_variables(
om,
flow_from_transformer,
total_flow_to_bus,
factor1=fl['share_in_bus'],
name='flow_limit_smaller',
)
om.flow_limit_smaller.upper = 0
return om