Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 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
4ad215d
feat: add stock-id field in Storage and DB flex model schemas
Ahmad-Wahid Feb 25, 2026
65fc268
feat: build stock groups
Ahmad-Wahid Feb 25, 2026
ef7cf60
feat: get stock groups
Ahmad-Wahid Feb 25, 2026
55ded46
feat: add a test case for multi feed stock
Ahmad-Wahid Feb 25, 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
d740c0d
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid Mar 4, 2026
8bd859f
feat: add support for shared storage
Ahmad-Wahid Mar 5, 2026
6658803
remove the breakpoint
Ahmad-Wahid Mar 5, 2026
d500052
feat: update the test case for two devices with shared stock
Ahmad-Wahid Mar 5, 2026
09e9780
feat: add assertions with clear reasons
Ahmad-Wahid Mar 5, 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
d4a15eb
Add support for multi-device charging of shared storage
Ahmad-Wahid Mar 12, 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
26a1993
fix: sum all devices soc contribution, and use individual device effi…
Ahmad-Wahid Mar 23, 2026
c98b178
update test case for multi feed stock
Ahmad-Wahid Mar 13, 2026
358afb8
expect to charge the battery early to see the effect of fully discharge
Ahmad-Wahid Mar 23, 2026
4932cf9
fix: update the assert statements according to the scheduler results
Ahmad-Wahid 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
b8ff719
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
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
29785fa
dev: first step in resolving merge conflicts
Flix6x Mar 23, 2026
cefe507
chore: code annotation
Flix6x Mar 23, 2026
118587b
fix: not all flex-models have sensors
Flix6x 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
74b665f
fix: static method has no self
Flix6x Mar 31, 2026
fbcf2e5
delete: remove inapplicable fields for stock model
Flix6x Mar 31, 2026
4259ffa
fix: fix interpretation of test results
Flix6x Mar 31, 2026
bc3991a
fix: move initialization of ems_constraints
Flix6x Mar 31, 2026
aefaf0d
fix: resolve merge conflicts on _build_soc_schedule, copied from Ahmad
Flix6x Mar 31, 2026
63b6bd7
fix: remove redundant code block
Flix6x Mar 31, 2026
0be435f
dev: use "state-of-charge" key instead of "sensor" key for stock models
Flix6x Mar 31, 2026
123f543
fix: skip StockCommitment for device models that outsource their stoc…
Flix6x Mar 31, 2026
f02e2ee
fix: old flex models that describe a device that serves both as a fee…
Flix6x Mar 31, 2026
5fb576e
fix: model stock devices using the state-of-charge field instead of t…
Flix6x Mar 31, 2026
cb110a9
fix: identify asset to merge with db flex-model
Flix6x Mar 31, 2026
b5bb77e
fix: validation
Flix6x Mar 31, 2026
816eda7
fix: flex-model setup in test
Flix6x Mar 31, 2026
1d5433f
fix: create stock group
Ahmad-Wahid Apr 4, 2026
eeffbf3
use soc-sensor in case of missing power sensor and also correct stock…
Ahmad-Wahid Apr 4, 2026
d8cab12
fix: create stock model for a model which has itself stock
Ahmad-Wahid Apr 5, 2026
ba7b433
update the assert statements
Ahmad-Wahid Apr 5, 2026
ea96b53
fix: merge conflicts
Ahmad-Wahid Apr 5, 2026
a229502
remove stock-id field
Ahmad-Wahid Apr 5, 2026
8190044
fix: correct the stock groups
Ahmad-Wahid Apr 7, 2026
177154c
refactor: remove unneccessary test function
Ahmad-Wahid Apr 9, 2026
a110f0e
fix: shared soc-gain, soc-usage, soc-minima and soc-maxima
Flix6x Apr 9, 2026
c7679ef
fix: shared StockCommitment for preferring a full SoC
Flix6x Apr 9, 2026
53d27c7
dev: todo
Flix6x Apr 9, 2026
69b5e27
dev: add "test" test case
Flix6x Apr 9, 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
b95a594
fix commodity-level commitments by grouping devices and aligning devi…
Ahmad-Wahid Apr 28, 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
0360d01
dev: Support commodity-specific prices and site capacities in storage…
Ahmad-Wahid May 14, 2026
775a52d
dev: Add commodity-specific flex-context schema
Ahmad-Wahid May 14, 2026
b9aece4
dev: Add dynamic commodity prices and split flex-context settings to …
Ahmad-Wahid May 14, 2026
433fe17
feat: create a shared schema for flex-context and commodity-context
Ahmad-Wahid May 26, 2026
85a105f
update the test case to have inflexible-devices-sensors for each comm…
Ahmad-Wahid May 26, 2026
4e5aee1
refactor: loop over flex-context fields and choose all fields except …
Ahmad-Wahid May 26, 2026
4a6910a
fix: add inflexible-device-sensors to the gas commodity model
Ahmad-Wahid May 26, 2026
5bbb515
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid May 26, 2026
7a0e7fe
fix: use net energy costs instead of individual device costs
Ahmad-Wahid May 26, 2026
c5351e0
fix: comment out the buggy lines
Ahmad-Wahid May 26, 2026
2105d28
Merge remote-tracking branch 'origin/feat/multi-feed-stock' into dev/…
Ahmad-Wahid May 26, 2026
e9c2681
fix: remove self
Ahmad-Wahid May 26, 2026
683fd57
feat: coupling groups for CHP
Flix6x May 29, 2026
391a5d7
feat: test factory model
Flix6x May 29, 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
84ed22b
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Flix6x Jun 3, 2026
d2b1812
fix: merge conflicts
Flix6x Jun 3, 2026
92c3324
Merge remote-tracking branch 'origin/feat/multi-feed-stock' into dev/…
Flix6x Jun 3, 2026
d5d241b
Merge remote-tracking branch 'origin/dev/split-flexcontext-by-commodi…
Flix6x Jun 3, 2026
afba390
Merge remote-tracking branch 'origin/main' into feat/multi-commodity
Flix6x Jun 3, 2026
2d662b0
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Flix6x Jun 3, 2026
9b0b9ac
Merge remote-tracking branch 'origin/feat/multi-feed-stock' into dev/…
Flix6x Jun 3, 2026
e84084d
Merge remote-tracking branch 'origin/dev/split-flexcontext-by-commodi…
Flix6x Jun 3, 2026
a7bbe45
refactor: make variables for gas boiler and e-heater capacities
Flix6x Jun 3, 2026
9d090bb
docs: clarify e-heater efficiency assumption
Flix6x Jun 3, 2026
3af4c52
feat: add scenario with merit order: gas boiler ≪ e-heater ≪ CHP
Flix6x Jun 3, 2026
e4f8fc9
feat: support flex-model coupling constraint in StorageScheduler
Flix6x Jun 3, 2026
1662283
docs: clarify calculation of coupling coefficients
Flix6x Jun 3, 2026
0d92dc4
feat: invert interpretation of coefficients to better match thermal a…
Flix6x Jun 3, 2026
a12032f
feat: support multiple inputs to coupling point
Flix6x Jun 3, 2026
ee33e27
feat: stop collapsing the heat buffer and steam node in the factory test
Flix6x Jun 3, 2026
094cd5d
tests/planning: align storage CHP coupling test with current coeffici…
Flix6x Jun 3, 2026
d119391
planning/coupling: infer internal sign from directional capacities
Flix6x Jun 3, 2026
a86f6a7
tests/planning: clarify signed internal CHP coefficients in storage d…
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
6fea3e7
Merge remote-tracking branch 'origin/feat/multi-commodity' into feat/…
Ahmad-Wahid Jun 4, 2026
5e76191
fix: add device-model in groups if it's missing
Ahmad-Wahid Jun 4, 2026
55dbced
fix: restore SOC constraints and state-of-charge handling broken by m…
Ahmad-Wahid Jun 4, 2026
9d6986d
Merge remote-tracking branch 'origin/feat/multi-feed-stock' into dev/…
Ahmad-Wahid Jun 4, 2026
5d02af4
fix: fall back to deprecated price fields
Flix6x Jun 8, 2026
abb41ff
fix: typo
Flix6x Jun 8, 2026
134563e
feat: store commitment costs on job meta
Flix6x Jun 8, 2026
dba828e
refactor: clarify which job is which
Flix6x Jun 8, 2026
02cfbb6
fix: update test expectation: the battery could save more?
Flix6x Jun 8, 2026
b7b21c2
dev: add todo
Flix6x Jun 8, 2026
193bca4
fix: price window should match scheduling window
Flix6x Jun 8, 2026
76b5fca
fix: comment out unreasoned check
Flix6x Jun 8, 2026
b13e239
fix: update test expectation; apparently the battery could save more?
Flix6x Jun 8, 2026
478c348
dev: add todo
Flix6x Jun 8, 2026
1dd6e80
chore: flake8
Flix6x Jun 8, 2026
e4d9c67
dev: exclude commodities field from flex-context schema referencing a…
Flix6x Jun 8, 2026
48bfe1c
fix: only save commitment costs on job if we have a job to save it on
Flix6x Jun 8, 2026
455f495
fix: inflexible devices are electricity devices by default
Flix6x Jun 8, 2026
e19984c
delete: no more need for backwards-compatibility of the temporary gas…
Flix6x Jun 8, 2026
e17a570
Merge remote-tracking branch 'origin/dev/split-flexcontext-by-commodi…
Flix6x Jun 8, 2026
bc6a88f
chore: black
Flix6x Jun 8, 2026
c1c7d96
chore: black
Flix6x Jun 8, 2026
a7773a8
fix: optional dict key
Flix6x Jun 8, 2026
ae42d6e
Merge remote-tracking branch 'origin/dev/split-flexcontext-by-commodi…
Flix6x Jun 8, 2026
229349d
fix: keep ems-constraints and fix the test cases (#2233)
Ahmad-Wahid Jun 12, 2026
bf09a81
fix: keep ems-constraints and fix the test cases (#2233)
Ahmad-Wahid Jun 12, 2026
926941a
fix: only raise in case of multiple EMS constraint DataFrames
Flix6x Jun 12, 2026
9f5d342
Merge remote-tracking branch 'origin/dev/split-flexcontext-by-commodi…
Flix6x Jun 12, 2026
953d3f1
chore: the wait for https://github.com/marshmallow-code/apispec/pull/…
Flix6x Jun 12, 2026
c6b8223
feat: allow any commodity, with electricity and gas serving as examples
Flix6x Jun 12, 2026
b706f79
delete: remove unreleased flex-context field for gas price
Flix6x Jun 12, 2026
b5f2c27
fix: add all relaxation fields to the list of fields to ignore when m…
Flix6x Jun 12, 2026
bd972aa
delete: gas_price is no longer a field (remove reference to unrelease…
Flix6x Jun 12, 2026
bcd54de
delete: just treat the whole old flex-context as the electricity flex…
Flix6x Jun 12, 2026
ed17a93
chore: update openapi-specs.json
Flix6x Jun 12, 2026
28d4529
Merge branch 'dev/split-flexcontext-by-commodity' into feat/chp
Flix6x Jun 12, 2026
afa5eb5
feat: list the commodity field first rather than last
Flix6x Jun 12, 2026
bf22eb8
feat: commodity is a field in both flex-model and flex-context
Flix6x Jun 12, 2026
710bf22
feat: flex-model commodity can also be more than just electricity and…
Flix6x Jun 12, 2026
410bb4c
docs: remove mention of gas-price field
Flix6x Jun 12, 2026
e994767
docs: adjust scheduling section for multi-commodity
Flix6x Jun 12, 2026
12ff212
docs: adjust field descriptions for multi-commodity
Flix6x Jun 12, 2026
c664e2a
docs: add type annotation
Flix6x Jun 16, 2026
fd66372
fix: keep track of inflexible device sensors per commodity, too
Flix6x Jun 16, 2026
7d99f1a
refactor: place all group args at the end
Flix6x Jun 16, 2026
73f8004
dev: add todos for checking prices
Flix6x Jun 16, 2026
e3f7cbd
fix: test should exclude COMMODITY_FLEX_CONTEXT and COMMODITY_FLEX_MO…
Flix6x Jun 30, 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
10 changes: 8 additions & 2 deletions documentation/features/scheduling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Scheduling

Scheduling is the main value-drive of FlexMeasures. We have two major types of schedulers built-in, for storage devices (usually batteries or hot water storage) and processes (usually in industry).

FlexMeasures computes schedules for energy systems that consist of multiple devices that consume and/or produce electricity.
We model a device as an asset with a power sensor, and compute schedules only for flexible devices, while taking into account inflexible devices.
FlexMeasures computes schedules for energy systems that consist of multiple devices that consume and/or produce a commodity (e.g. electricity or gas).
We model a device as an asset with a consumption/production sensor recording power values, and compute schedules only for flexible devices, while taking into account inflexible devices.

.. contents::
:local:
Expand Down Expand Up @@ -58,6 +58,9 @@ And if the asset belongs to a larger system (a hierarchy of assets), the schedul
* - Field
- Example value
- Description
* - ``commodity``
- |COMMODITY_FLEX_CONTEXT.example|
- .. include:: ../_autodoc/COMMODITY_FLEX_CONTEXT.rst
* - ``inflexible-device-sensors``
- |INFLEXIBLE_DEVICE_SENSORS.example|
- .. include:: ../_autodoc/INFLEXIBLE_DEVICE_SENSORS.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_FLEX_MODEL.example|
- .. include:: ../_autodoc/COMMODITY_FLEX_MODEL.rst
* - ``consumption``
- |CONSUMPTION.example|
- .. include:: ../_autodoc/CONSUMPTION.rst
Expand Down
144 changes: 140 additions & 4 deletions flexmeasures/data/models/planning/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections import defaultdict
from collections.abc import Iterable
from dataclasses import dataclass, field
from datetime import datetime, timedelta
Expand Down Expand Up @@ -53,6 +54,7 @@ class Scheduler:

flex_model: list[dict] | dict | None = None
flex_context: dict | None = None
stock_groups: dict | None = None

fallback_scheduler_class: "Type[Scheduler] | None" = None
info: dict | None = None
Expand All @@ -65,6 +67,103 @@ class Scheduler:

return_multiple: bool = False

@staticmethod
def _build_stock_groups(flex_model: list[dict]) -> dict:
"""
Build stock groups where devices sharing the same state-of-charge sensor are grouped together.
"""
groups = defaultdict(list)
soc_usage = defaultdict(list)

for d, fm in enumerate(flex_model):
soc = fm.get("state_of_charge")
if soc is not None:
if hasattr(soc, "id"):
soc_id = soc.id
elif isinstance(soc, dict) and "sensor" in soc:
sensor = soc["sensor"]
soc_id = sensor.id if hasattr(sensor, "id") else sensor
else:
soc_id = soc

soc_usage[soc_id].append(d)

for soc_id, device_list in soc_usage.items():
groups[soc_id] = device_list

already_grouped = {dev for group in groups.values() for dev in group}
missing_soc_sensor_i = -len(flex_model)
for d in range(len(flex_model)):
if d not in already_grouped:
groups[missing_soc_sensor_i].append(d)
missing_soc_sensor_i += 1

return dict(groups)

@staticmethod
def _build_coupling_groups(
flex_model: list[dict],
) -> dict[str, list[tuple[int, float]]]:
"""Build coupling groups from the 'coupling' and 'coupling_coefficient' fields
of each device model.

Devices sharing the same coupling name form a coupling group.
The optimization model introduces a decision variable ``alpha`` per group per time
step, and constrains every device by ``P[d] == coeff_d * alpha``.

Coupling coefficients in flex-models are user-facing positive magnitudes.
The internal sign is inferred from directional capacities:

- ``consumption_capacity == 0`` -> output device -> internally negative coefficient
- ``production_capacity == 0`` -> input device -> internally positive coefficient

If neither direction is explicitly blocked, the coefficient stays positive.

Example — a CHP with 50% heat efficiency and 30% power efficiency:

[
{"coupling": "chp", "coupling_coefficient": 1.0}, # gas input (alpha = P_gas)
{"coupling": "chp", "coupling_coefficient": 0.5}, # heat output (50% of gas)
{"coupling": "chp", "coupling_coefficient": 0.3}, # power output (30% of gas)
]

:param flex_model: List of deserialized device flex-model dicts.
:returns: Mapping from coupling-group name to a list of
``(device_index, internal_signed_coefficient)`` tuples suitable for
passing to ``device_scheduler(coupling_groups=...)``. Returns an empty dict
when no device defines a ``coupling`` field.
"""

def _is_zero_capacity(value: Any) -> bool:
"""Return True if the capacity value is numerically zero."""

if value is None:
return False

# Pint quantities expose ``magnitude``.
magnitude = getattr(value, "magnitude", value)
try:
return bool(np.isclose(float(magnitude), 0.0))
except (TypeError, ValueError):
return False

groups: dict[str, list[tuple[int, float]]] = defaultdict(list)
for d, fm in enumerate(flex_model):
coupling_name = fm.get("coupling")
if coupling_name is None:
continue
coefficient = abs(float(fm.get("coupling_coefficient", 1.0)))

is_output = _is_zero_capacity(fm.get("consumption_capacity"))
is_input = _is_zero_capacity(fm.get("production_capacity"))

if is_output and not is_input:
coefficient = -coefficient

groups[coupling_name].append((d, coefficient))

return dict(groups)

def __init__(
self,
sensor: Sensor | None = None, # deprecated
Expand Down Expand Up @@ -203,12 +302,19 @@ def collect_flex_config(self):
# Listify the flex-model for the next code block, which actually does the merging with the db_flex_model
flex_model = [flex_model]

# Find which asset is relevant for a given device model in the flex-model from the trigger message
for flex_model_d in flex_model:
asset_id = flex_model_d.get("asset")
if asset_id is None:
sensor_id = flex_model_d["sensor"]
sensor = db.session.get(Sensor, sensor_id)
asset_id = sensor.asset_id
sensor_id = flex_model_d.get("sensor")
if sensor_id is not None:
sensor = db.session.get(Sensor, sensor_id)
asset_id = sensor.asset_id
else:
soc_sensor_ref = flex_model_d.get("state-of-charge")
if soc_sensor_ref is not None:
soc_sensor = db.session.get(Sensor, soc_sensor_ref["sensor"])
asset_id = soc_sensor.asset_id
if asset_id in db_flex_model:
flex_model_d = {**db_flex_model[asset_id], **flex_model_d}
amended_flex_model.append(flex_model_d)
Expand Down Expand Up @@ -289,14 +395,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 +508,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 +573,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
Loading
Loading