Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
9dd779a
docs: new section describing commitments
Flix6x Dec 4, 2025
13e9308
docs: rewrite the overview in commitments section
Flix6x Dec 4, 2025
1179198
docs: keep ems variables, but explain them as representing the site c…
Flix6x Dec 4, 2025
1b10360
docs: cross-reference the commitments section and the linear problem …
Flix6x Dec 4, 2025
0d25b25
Merge remote-tracking branch 'refs/remotes/origin/main' into docs/com…
Flix6x Dec 8, 2025
6f6e52b
fix: cross-references
Flix6x Dec 8, 2025
3599379
docs: add commitments section to index
Flix6x Dec 8, 2025
ce1533d
Merge remote-tracking branch 'refs/remotes/origin/main' into docs/com…
Flix6x Jan 23, 2026
84fbd5a
feat: add a util function for printing out commitments in a tabulated…
Ahmad-Wahid Jan 23, 2026
90177bf
refactor: move pretty printing method to class
Flix6x Jan 23, 2026
9f34676
feat: Commitment supports device groups
Flix6x Jan 23, 2026
43107c8
feat: start testing device grouping
Flix6x Jan 23, 2026
b90d7f0
dev: test multi-feed
Flix6x Jan 23, 2026
4179981
update the ids of devices to be integers
Ahmad-Wahid Jan 26, 2026
8b108ed
feat: function that group commitment quantities
Ahmad-Wahid Jan 26, 2026
485349e
add commitments for multi group
Ahmad-Wahid Jan 26, 2026
81bb9ec
fix: get unique list of devices for a frame column
Ahmad-Wahid Jan 27, 2026
334e4d3
fix: create util functions that extract devices for a list of values …
Ahmad-Wahid Jan 27, 2026
f738d9f
fix: create a series for a list of grouped devices
Ahmad-Wahid Jan 27, 2026
620c6dc
drop outdated comments
Ahmad-Wahid Jan 31, 2026
40eb747
use commitment costs and add asserts for electricity and gas
Ahmad-Wahid Jan 31, 2026
708d869
and an assert for commodity costs
Ahmad-Wahid Jan 31, 2026
ce307f8
add an extra assert on costs
Ahmad-Wahid Jan 31, 2026
5be555b
support commodity based EMS flow commitments and grouped devices
Ahmad-Wahid Feb 3, 2026
6f2d745
Add commodity field and support multi-device commitments
Ahmad-Wahid Feb 3, 2026
1d63893
test shared buffer and multi-comodity commitments
Ahmad-Wahid Feb 3, 2026
8c9b1b5
remove hard check for commodity to make backward compatible
Ahmad-Wahid Feb 3, 2026
a8f3b89
update the function to support backward compatibility
Ahmad-Wahid Feb 3, 2026
be09c4d
feat: add commodity field to the flexmodel and DBstorage-flex-model s…
Ahmad-Wahid Feb 10, 2026
07822eb
fix: use devices as index rather than time series
Flix6x Feb 10, 2026
92eabc7
fix: exclude gas-power devices from electricity commitments
Flix6x Feb 10, 2026
ee33fa2
Merge remote-tracking branch 'origin/main' into feat/switching-betwee…
Flix6x Feb 10, 2026
f9df705
Merge branch 'feat/switching-between-gas-and-electricity' into feat/m…
Flix6x Feb 10, 2026
325bfe8
feat: add gas-price field to the Flex-context schema
Ahmad-Wahid Feb 10, 2026
9261629
apply black
Ahmad-Wahid Feb 10, 2026
9dd5802
feat: add a test case for two flexible devices with commodity
Ahmad-Wahid Feb 10, 2026
b22c6d7
use expected datatypes
Ahmad-Wahid Feb 16, 2026
c88af5c
feat: split commitments per commodity
Ahmad-Wahid Feb 16, 2026
c2341f1
feat: split commitments per commodity
Ahmad-Wahid Feb 16, 2026
88d4be0
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid Feb 16, 2026
be05a19
Revert "use expected datatypes"
Ahmad-Wahid Feb 16, 2026
f4ffd8a
feat: add a test case for different commodities
Ahmad-Wahid Feb 16, 2026
c43d2ad
fix: do not produce gas
Flix6x Feb 20, 2026
0aa5b2b
feat: create a flow commitment for prefering to charge sooner devices
Ahmad-Wahid Feb 26, 2026
a48c6ba
add soc constraints for boiler
Ahmad-Wahid Feb 26, 2026
c58965f
add some assert statments
Ahmad-Wahid Feb 26, 2026
515f34a
update and add new assertions with clear explanation
Ahmad-Wahid Mar 4, 2026
4d77344
update the docstring
Ahmad-Wahid Mar 4, 2026
2becd02
refactor: move tiny-price-slope decleration out of the for loop
Ahmad-Wahid Mar 6, 2026
d9d4f94
Revert "refactor: move tiny-price-slope decleration out of the for loop"
Ahmad-Wahid Mar 6, 2026
2a22fae
refactor: move tiny-price-slope decleration out of the for loop
Ahmad-Wahid Mar 6, 2026
f38d6d8
fix: add data_key attr
Ahmad-Wahid Mar 6, 2026
007e514
add missing commodity description and it's field in ui flexmodel schema
Ahmad-Wahid Mar 6, 2026
0bff8bc
fix: add missing gas-price field in UI Flexcontext schema
Ahmad-Wahid Mar 6, 2026
82f807e
fix: wrong timezone; the test relied on the preference to charge soon…
Flix6x Mar 13, 2026
128550f
feat: move preference to charge sooner and discharge later into a Sto…
Flix6x Mar 13, 2026
130b9dd
fix: test case no longer relies on arbitrage opportunity coming from …
Flix6x Mar 13, 2026
1eab828
feat: check for optimal schedule
Flix6x Mar 13, 2026
b9bc4a9
feat: prefer a full storage earlier over later
Flix6x Mar 13, 2026
57df5c3
docs: update commitment name and inline comments
Flix6x Mar 13, 2026
ce71637
docs: touch up test explanation
Flix6x Mar 14, 2026
f6183df
fix: update test case given preference for a full battery
Flix6x Mar 14, 2026
ed471a8
delete: clean up comment
Flix6x Mar 14, 2026
7611fb9
feat: model the preference to curtail later within the same StockComm…
Flix6x Mar 14, 2026
bf16e63
fix: reduce tiny price slope
Flix6x Mar 14, 2026
06c30dc
docs: delete duplicate changelog entry
Flix6x Mar 16, 2026
0125e28
Merge remote-tracking branch 'origin/main' into feat/full-soc-preference
Flix6x Mar 18, 2026
d99089b
docs: fix broken link
Flix6x Mar 18, 2026
cf01f1d
Revert "fix: reduce tiny price slope"
Flix6x Mar 18, 2026
bdbdead
fix: soc unit conversion
Flix6x Mar 18, 2026
f987706
fix: adapt test to check for 1 hour of free energy at 15-min scheduli…
Flix6x Mar 18, 2026
7acbc99
Merge remote-tracking branch 'origin/feat/full-soc-preference' into f…
Flix6x Mar 19, 2026
12cf595
Merge remote-tracking branch 'origin/main' into feat/switching-betwee…
Flix6x Mar 19, 2026
c09371a
Merge branch 'feat/switching-between-gas-and-electricity' into feat/m…
Flix6x Mar 19, 2026
534179a
style: black
Flix6x Mar 19, 2026
19dc4dc
Merge remote-tracking branch 'origin/feat/switching-between-gas-and-e…
Ahmad-Wahid Mar 19, 2026
e4c43ea
fix: check curtailment preference per distinct device
Flix6x Mar 20, 2026
b3138c3
fix: set tight tolerance for HiGHS solver
Flix6x Mar 20, 2026
8eff839
refactor: merge if-blocks
Flix6x Mar 20, 2026
b0074d4
fix: update test_two_flexible_assets_with_commodity
Flix6x Mar 20, 2026
ae23ef6
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid Mar 20, 2026
05aed7e
fix: check curtailment preference per distinct device
Flix6x Mar 20, 2026
e55f638
fix: set tight tolerance for HiGHS solver
Flix6x Mar 20, 2026
764712f
refactor: merge if-blocks
Flix6x Mar 20, 2026
9070eae
fix: use iloc
Flix6x Mar 23, 2026
857e9c1
fix: diminish tiny price slope by number of planning steps
Flix6x Mar 23, 2026
54c9c36
refactor: always diminish tiny price slope by number of planning step…
Flix6x Mar 23, 2026
158c7a0
chore: increment StorageScheduler version
Flix6x Mar 23, 2026
3df2142
Merge remote-tracking branch 'origin/feat/full-soc-preference' into f…
Flix6x Mar 23, 2026
decf794
Merge remote-tracking branch 'origin/main' into feat/multi-commodity
Flix6x Mar 23, 2026
261ed3a
Merge branch 'feat/full-soc-preference' into feat/switching-between-g…
Flix6x Mar 23, 2026
a16ec74
Merge branch 'feat/switching-between-gas-and-electricity' into feat/m…
Flix6x Mar 23, 2026
021543c
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid Mar 23, 2026
66e9a8b
Merge remote-tracking branch 'origin/main' into feat/switching-betwee…
Flix6x Mar 23, 2026
eda0ec7
Merge branch 'feat/switching-between-gas-and-electricity' into feat/m…
Flix6x Mar 23, 2026
b092aa1
fix: use approximation to compare battery and heat pump costs
Ahmad-Wahid Mar 23, 2026
b20465e
update the assert statements with prefered to charge battery sooner t…
Ahmad-Wahid Mar 23, 2026
031a6e8
fix: update the expected ev and battery costs
Ahmad-Wahid Mar 24, 2026
de4981e
fix: add device id to get costs for the given device
Ahmad-Wahid Mar 24, 2026
1ec0b2c
Merge remote-tracking branch 'origin/main' into feat/switching-betwee…
Flix6x Apr 24, 2026
49df3a6
feat: rewrite test to not rely on multi-commodity
Flix6x Apr 24, 2026
a518437
feat: rewrite test to prove that only when both HPs share a single co…
Flix6x Apr 24, 2026
4258636
fix: do not coerce device_group into a time series
Flix6x Apr 24, 2026
b4f8b2b
docs: changelog entry
Flix6x Apr 24, 2026
6e3a5a4
docs: pretty_print is not specifically for FlowCommitments
Flix6x Apr 24, 2026
7eb1319
docs: add (back) inline dev notes
Flix6x Apr 24, 2026
a298dc7
feat: strengthen asserts
Flix6x Apr 24, 2026
7f15c13
feat: add check for exact electricity costs expected
Flix6x Apr 24, 2026
ffd0d86
fix: sum over electricity costs; and move to StockCommitment to model…
Flix6x Apr 24, 2026
a33790a
fix: replace vague assert with explicit asserts
Flix6x Apr 24, 2026
6b6a474
docs: lose confusing comment
Flix6x Apr 24, 2026
70e1af6
fix: backwards compatibility in case no device is specified;
Flix6x Apr 24, 2026
792d2df
fix: when device is present but device_group is absent, fall back to …
Flix6x Apr 25, 2026
a9174a5
dev: update expectations of how costs are shared between EV and battery
Flix6x Apr 26, 2026
864a98f
fix commodity-level commitments by grouping devices and aligning devi…
Ahmad-Wahid Apr 30, 2026
c885b04
update the test cases for net commodity consumption and production
Ahmad-Wahid Apr 30, 2026
55075d5
fix: merge conflicts
Ahmad-Wahid Apr 30, 2026
7deff15
Merge remote-tracking branch 'origin/main' into feat/switching-betwee…
Flix6x Jun 3, 2026
3e20ce0
Merge remote-tracking branch 'origin/feat/switching-between-gas-and-e…
Flix6x Jun 3, 2026
afba390
Merge remote-tracking branch 'origin/main' into feat/multi-commodity
Flix6x Jun 3, 2026
7e60e2d
fix: update the test cases according device level costs
Ahmad-Wahid Jun 4, 2026
6c82e1c
docs/scheduling: add COMMODITY and GAS_PRICE metadata field documenta…
Ahmad-Wahid Jun 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions documentation/features/scheduling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ And if the asset belongs to a larger system (a hierarchy of assets), the schedul
* - ``production-price``
- |PRODUCTION_PRICE.example|
- .. include:: ../_autodoc/PRODUCTION_PRICE.rst
* - ``gas-price``
- |GAS_PRICE.example|
- .. include:: ../_autodoc/GAS_PRICE.rst
* - ``site-power-capacity``
- |SITE_POWER_CAPACITY.example|
- .. include:: ../_autodoc/SITE_POWER_CAPACITY.rst
Expand Down Expand Up @@ -183,6 +186,9 @@ For more details on the possible formats for field values, see :ref:`variable_qu
* - Field
- Example value
- Description
* - ``commodity``
- |COMMODITY.example|
- .. include:: ../_autodoc/COMMODITY.rst
* - ``consumption``
- |CONSUMPTION.example|
- .. include:: ../_autodoc/CONSUMPTION.rst
Expand Down
32 changes: 31 additions & 1 deletion flexmeasures/data/models/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,27 @@ class Commitment:
quantity: pd.Series = 0
upwards_deviation_price: pd.Series = 0
downwards_deviation_price: pd.Series = 0
commodity: str | pd.Series | None = None

def __post_init__(self):
# device_group is a device→label lookup table, not a time series;
# exclude it from automatic time-series index coercion.
if (
isinstance(self, FlowCommitment)
and isinstance(self.commodity, pd.Series)
and self.device is not None
):
devices = extract_devices(self.device)
missing = set(devices) - set(self.commodity.index)
if missing:
raise ValueError(f"commodity mapping missing for devices: {missing}")

series_attributes = [
attr
for attr, _type in self.__annotations__.items()
if _type == "pd.Series" and hasattr(self, attr) and attr != "device_group"
if _type == "pd.Series"
and hasattr(self, attr)
and attr not in ("device_group", "commodity")
]
for series_attr in series_attributes:
val = getattr(self, series_attr)
Expand Down Expand Up @@ -389,6 +402,10 @@ def _init_device_group(self):
range(len(devices)), index=devices, name="device_group"
)
else:
if not isinstance(self.device_group, pd.Series):
self.device_group = pd.Series(
self.device_group, index=devices, name="device_group"
)
# Validate custom grouping
missing = set(devices) - set(self.device_group.index)
if missing:
Expand Down Expand Up @@ -450,6 +467,19 @@ def to_frame(self) -> pd.DataFrame:
np.nan
) # EMS-level: handled by ems_flow_commitment_equalities

# commodity
if getattr(self, "commodity", None) is None:
df["commodity"] = None
elif isinstance(self.commodity, pd.Series):
# commodity is a device→commodity mapping, like device_group
if self.device is None:
df["commodity"] = None
else:
df["commodity"] = map_device_to_group(self.device, self.commodity)
else:
# scalar commodity
df["commodity"] = self.commodity

return df


Expand Down
81 changes: 48 additions & 33 deletions flexmeasures/data/models/planning/linear_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ def device_scheduler( # noqa C901
df["group"] = group
commitments.append(df)

# commodity → set(device indices)
commodity_devices = {}

for df in commitments:
if "commodity" not in df.columns or "device" not in df.columns:
continue

for _, row in df[["commodity", "device"]].dropna().iterrows():
devices = row["device"]
if not isinstance(devices, (list, tuple, set)):
devices = [devices]

commodity_devices.setdefault(row["commodity"], set()).update(devices)

# Check if commitments have the same time window and resolution as the constraints
for commitment in commitments:
start_c = commitment.index.to_pydatetime()[0]
Expand Down Expand Up @@ -593,45 +607,30 @@ def device_stock_commitment_equalities(m, c, j, d):
)

def ems_flow_commitment_equalities(m, c, j):
"""Couple EMS flows (sum over devices) to each commitment.
"""Couple EMS flow commitments to device flows, optionally filtered by commodity."""

- Creates an inequality for one-sided commitments.
- Creates an equality for two-sided commitments and for groups of size 1.
"""
if (
"device" in commitments[c].columns
and not pd.isnull(commitments[c]["device"]).all()
) or m.commitment_quantity[c, j] == -infinity:
# Commitment c does not concern EMS
if commitments[c]["class"].iloc[0] != FlowCommitment:
return Constraint.Skip
if (
"class" in commitments[c].columns
and not (
commitments[c]["class"].apply(lambda cl: cl == FlowCommitment)
).all()
):
raise NotImplementedError(
"StockCommitment on an EMS level has not been implemented. Please file a GitHub ticket explaining your use case."
)

# Legacy behavior: no commodity → sum over all devices
if "commodity" not in commitments[c].columns:
devices = m.d
else:
commodity = commitments[c]["commodity"].iloc[0]
if pd.isna(commodity):
devices = m.d
else:
devices = commodity_devices.get(commodity, set())
if not devices:
return Constraint.Skip

return (
(
0
if len(commitments[c]) == 1
or "upwards deviation price" in commitments[c].columns
else None
),
# 0 if "upwards deviation price" in commitments[c].columns else None, # todo: possible simplification
None,
m.commitment_quantity[c, j]
+ m.commitment_downwards_deviation[c]
+ m.commitment_upwards_deviation[c]
- sum(m.ems_power[:, j]),
(
0
if len(commitments[c]) == 1
or "downwards deviation price" in commitments[c].columns
else None
),
# 0 if "downwards deviation price" in commitments[c].columns else None, # todo: possible simplification
- sum(m.ems_power[d, j] for d in devices),
None,
)

def device_derivative_equalities(m, d, j):
Expand Down Expand Up @@ -751,6 +750,22 @@ def cost_function(m):
)

model.commitment_costs = commitment_costs
commodity_costs = {}
for c in model.c:
commodity = None
if "commodity" in commitments[c].columns:
commodity = commitments[c]["commodity"].iloc[0]
if commodity is None or (isinstance(commodity, float) and np.isnan(commodity)):
continue

cost = value(
model.commitment_downwards_deviation[c] * model.down_price[c]
+ model.commitment_upwards_deviation[c] * model.up_price[c]
)
commodity_costs[commodity] = commodity_costs.get(commodity, 0) + cost

model.commodity_costs = commodity_costs

# model.pprint()
# model.display()
# print(results.solver.termination_condition)
Expand Down
Loading
Loading