-
|
Hallo :) ich möchte einen Code schreiben in dem 2 BHKWs in bestimmten Zeitfenstern (täglich zwischen 18 und 24 Uhr) mit einer konstanten Leistung fahren, sodass, die Anlage nicht gesteuert werden muss. Alle anderen Nebenbedingungen sollen bleiben. Das eine BHKW kann also in diesem Zeitraum zwischen 375 und 537 kW Fahren, aber konstant, das andere kann entweder ganz aus sein oder zwischen 560 und 800 kW fahren, aber ebenfalls in diesem Zeitraum konstant. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
@UHLIHELE Bitte als Codebeispiel immer möglichst minimalistische Beispiele nutzen, die sich nur auf das eine THema fokussieren ( Siehe minimal_example.py Anbei eine Möglichkeit eine eigene constraint dafür zu schreiben. Linopy basicsimport linopy
import pandas as pd
import numpy as np
# Create model
model = linopy.Model()
# Create hourly time index for 3 days
time_index = pd.date_range('2024-01-01', periods=72, freq='h', name='time')
# Add variable with rising bounds
var = model.add_variables(
lower=0,
upper=np.linspace(0, 100, len(time_index)),
coords=(time_index,),
name='power'
)
## -------------------------------------------------------------------------------------------------------------------#
# Evening equality constraints (18:00-23:59 equal within each day)
hour = var.coords['time'].dt.hour
evening_mask = (hour >= 18) & (hour < 24)
evening_times = var.coords['time'].sel(time=evening_mask)
for day, times in evening_times.groupby('time.date'):
group = var.sel(time=times)
model.add_constraints(
group == group.isel(time=0),
name=f'evening_equality_{day}'
)
## --------------------------------------------------------------------------------------------------------------------#
# Objective: maximize total power
model.add_objective(-var.sum())
# Solve
model.solve()
# Results
print(var.solution.to_pandas())
try:
import plotly.express as px
px.bar(var.solution.to_pandas()).show()
except ImportError:
print('Plotting not possible')With flixoptimport numpy as np
import pandas as pd
import flixopt as fx
flow_system = fx.FlowSystem(pd.date_range('2020-01-01', periods=72, freq='h'))
flow_system.add_elements(
fx.Bus('Heat'),
fx.Bus('Gas'),
fx.Effect('Costs', '€', 'Cost', is_standard=True, is_objective=True),
fx.linear_converters.Boiler(
'Boiler',
thermal_efficiency=0.5,
thermal_flow=fx.Flow(label='Heat', bus='Heat', size=50),
fuel_flow=fx.Flow(label='Gas', bus='Gas'),
),
fx.Sink(
'Sink',
inputs=[fx.Flow(label='Demand', bus='Heat', size=1, fixed_relative_profile=np.linspace(0, 50, len(flow_system.timesteps)))],
),
fx.Source(
'Source',
outputs=[fx.Flow(label='Gas', bus='Gas', size=1000, effects_per_flow_hour=0.04)],
),
)
calculation = fx.FullCalculation('Simulation1', flow_system).do_modeling()
## --Insert custom constraints after .modeling()-------------------------------------------------------------------------------------#
# Evening equality constraints (18:00-23:59 equal within each day)
var = calculation.model['Boiler(Heat)|flow_rate']
hour = var.coords['time'].dt.hour
evening_mask = (hour >= 18) & (hour < 24)
evening_times = var.coords['time'].sel(time=evening_mask)
for day, times in evening_times.groupby('time.date'):
group = var.sel(time=times)
calculation.model.add_constraints(
group == group.isel(time=0),
name=f'evening_equality_{day}'
)
## --------------------------------------------------------------------------------------------------------------------#
calculation.solve(fx.solvers.HighsSolver(0.01, 60))
calculation.results['Heat'].plot_node_balance() |
Beta Was this translation helpful? Give feedback.
@UHLIHELE Bitte als Codebeispiel immer möglichst minimalistische Beispiele nutzen, die sich nur auf das eine THema fokussieren ( Siehe minimal_example.py
Anbei eine Möglichkeit eine eigene constraint dafür zu schreiben.
Linopy basics