The error handling with limit_active_flow_count is nice , because it reads
10:51:57-ERROR-Constructing component 'one_tractor_battery_constraint_build' from data=None failed:
indicating that no data was generated. Below i have a very simple model where only one of the two batteries is allowed to charge the load on the bev bus. My guess is that something is wrong with the format of the flows, which I assumed to be as it is mentioned in the documentation:
flows (list of flows) â flows (have to be NonConvex) in the format [(in, out)]
def saturating_storage_example():
# create an energy system
idx = pd.date_range("1/1/2023", periods=100, freq="H")
es = solph.EnergySystem(timeindex=idx, infer_last_interval=False)
# power bus
bel = solph.Bus(label="bel")
bev = solph.Bus(label ='bev')
es.add(bel,bev)
es.add(
solph.components.Source(
label="source_el",
outputs={bel: solph.Flow(nominal_value=1, fix=1)},
)
)
es.add(
solph.components.Sink(
label="sink_el",
inputs={
bev: solph.Flow(
nominal_value=1,
variable_costs=1,
)
},
)
)
# Electric Storage
inflow_capacity = 0.5
full_charging_limit = 0.4
storage_capacity = 10
battery = solph.components.GenericStorage(
label="battery_1",
nominal_storage_capacity=storage_capacity,
inputs={bel: solph.Flow(nominal_value=inflow_capacity)},
outputs={bev: solph.Flow(variable_costs=2)},
initial_storage_level=0,
balanced=False,
loss_rate=0.0001,
)
es.add(battery)
battery = solph.components.GenericStorage(
label="battery_2",
nominal_storage_capacity=storage_capacity,
inputs={bel: solph.Flow(nominal_value=inflow_capacity)},
outputs={bev: solph.Flow(variable_costs=2)},
initial_storage_level=0,
balanced=False,
loss_rate=0.0001,
)
es.add(battery)
# create an optimization problem and solve it
model = solph.Model(es)
battery1 = es.groups['battery_1']
battery2 = es.groups['battery_2']
# only one of the tractor batteries may be actively discharging at a time
solph.constraints.limit_active_flow_count(
model=model, constraint_name = 'one_tractor_battery', flows = [('battery_1','bev'),('battery_2','bev')], lower_limit=0, upper_limit=1
)