Skip to content

Commit

Permalink
Merge pull request #235 from BESTenergytrade/feature/optimisation
Browse files Browse the repository at this point in the history
Feature/optimisation
  • Loading branch information
j-ti authored Sep 20, 2024
2 parents c3cdeec + f6471be commit 9bf70f0
Show file tree
Hide file tree
Showing 32 changed files with 71,497 additions and 56 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
- name: Install CBC solver
run: |
sudo apt-get update
sudo apt-get install -y coinor-cbc
- name: Set up Python 3.8
uses: actions/setup-python@v3
with:
python-version: "3.10"
python-version: "3.8"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -34,3 +38,6 @@ jobs:
- name: Run match_market.py
run: |
python match_market.py projects/example_projects/example_project
- name: Run match_market.py EV optimisation
run: |
python match_market.py projects/example_projects/example_project_ev_opt
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.10"
python: "3.8"

python:
install:
Expand Down
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ After cloning the repository, a virtual environment is created (e.g. using virtu
# create virtual environment
virtualenv venv --python=python3.8
source venv/bin/activate
# install cbc-solver to be able to use optimization with pyomo
sudo apt-get update
sudo apt-get install -y coinor-cbc
Then there are two options to use simply:

Expand Down
3 changes: 2 additions & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ sphinx_rtd_theme
networkx
matplotlib
pandas
pytest
pytest
pyomo
37 changes: 22 additions & 15 deletions doc/source/actor_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ actor corresponds to the price of the market maker at the time of electricity tr
constraints, energy has to be drawn from or fed into the grid, the actor sends an order with a price that corresponds to the
market maker prices (incl. grid fees). This way a successful trade is guaranteed.

There are four different actor strategies. Strategy 0 represents the simplest case, which is only based on the market maker's
electricity price of the current time slot. The other three strategies represent forecast-based,
There are five different actor strategies. Strategy 0 represents the simplest case, which is only based on the market maker's
electricity price of the current time slot. The other four strategies represent forecast-based,
market-oriented alternatives: The market maker's price time series as well as the actor's demand and supply of
electrical energy are considered for the near future given the configured horizon. Thus, the timing of
electricity trading based on future market maker prices permits the actor to
Expand All @@ -23,21 +23,21 @@ the selected matching algorithm, applied grid fees and additional pricing strate
(cf. :ref:`pricing_strategies` and :ref:`matching_algorithms`). As a result, this allows the actor - within its constraints - to
purchase energy at a lower price or sell energy at a higher price with respect to the guaranteed trading with the market maker.

The four actor strategies build on each other and are characterized by different features:
The first four actor strategies (0-3) build on each other and are characterized by different features:

+--------------------------+--------------+--------------+--------------+--------------+
| | Strategy 0 | Strategy 1 | Strategy 2 | Strategy 3 |
+==========================+==============+==============+==============+==============+
| Forecast based purchase | | x | x | x |
+--------------------------+--------------+--------------+--------------+--------------+
| Forecast based sale | | | x | x |
+--------------------------+--------------+--------------+--------------+--------------+
| Time arbitrage | | | | x |
+--------------------------+--------------+--------------+--------------+--------------+
+--------------------------+--------------+--------------+--------------+--------------+--------------+
| | Strategy 0 | Strategy 1 | Strategy 2 | Strategy 3 | Strategy 4 |
+==========================+==============+==============+==============+==============+==============+
| Forecast based purchase | | x | x | x | x |
+--------------------------+--------------+--------------+--------------+--------------+--------------+
| Forecast based sale | | | x | x | x |
+--------------------------+--------------+--------------+--------------+--------------+--------------+
| Time arbitrage | | | | x | x |
+--------------------------+--------------+--------------+--------------+--------------+--------------+

From left to right, the strategies gain in economic advantage for the actor, but also in complexity. While an actor in
strategy 0 can only directly use or feed in energy from its own generation, in strategies 1 - 3 an actor can also have a
battery storage system, which enables it to temporarily store energy that is not used by the household or, for example,
strategy 0 can only directly use or feed in energy from its own generation, in strategies 1 - 4 an actor can also use a
battery storage system, which enables it to temporarily store energy that is not used by the household loads or, for example,
an electric vehicle. In this way, the strategies serve self-consumption. By also selling electrical energy from the battery
in strategy 2 und 3 the economic efficiency of the generator and the battery storage system is increased.

Expand Down Expand Up @@ -70,13 +70,20 @@ causes the positive deviation from the SOC of 1 can be sold the optimal time for
energy can be sold it is checked if later time windows with a SOC > 1 can be served and if that would lead to maximum
profit.


Strategy 3
==========

Strategy 3 uses strategy 2 and considers time arbitrage to better exploit the market maker's dynamic prices.
If price fluctuations are strong enough to make it profitable to buy and later sell, the remaining capacity of the
battery is used to conduct this trade.

Strategy 4
==========

Strategy 4 is independent of strategies 0-3 and optimizes for the prediction horizon a mathematical optimization
problem to profit from the market maker's dynamic prices, while considering the constraints of the local system, e.g.
the availability of an electric vehicle, power constraints or the capacity of the stationary battery.
Comparable to strategy 3 price for strong fluctuations energy can be actively bought to be sold at a higher price later.



Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"comment": "An example of a residential prosumer with load and pv data specified by their 'deviceID'",
"prosumerName": "residential_1",
"prosumerType": "residential",
"gridLocation": "N01",
"devices": [
{
"deviceType": "load",
"deviceID": "CHH10_sample.csv"
},
{
"deviceType": "solar",
"deviceID": "generated_pv.csv"
}
]
},
{
"comment": "An example of a residential prosumer with load data specified by their 'deviceID' but without pv",
"prosumerName": "residential_2",
"prosumerType": "residential",
"gridLocation": "N02",
"devices": [
{
"deviceType": "load",
"deviceID": "CHH9_sample.csv"
}
],
"strategy": 4
},
{
"comment": "An example of a residential prosumer with load, pv and electric vehicle data specified by their 'deviceID' and a battery",
"prosumerName": "residential_3",
"prosumerType": "residential",
"gridLocation": "N02",
"devices": [
{
"deviceType": "load",
"deviceID": "CHH16_sample.csv"
},
{
"deviceType": "solar",
"deviceID": "generated_pv.csv"
},
{
"deviceType": "battery",
"capacityKwh": 3,
"initialSOC": 0.5
},
{
"deviceType": "ev",
"deviceID": "ev_0000.csv"
}
],
"strategy": 4,
"pricing_strategy": {"name": "linear", "param": [0.01]}
}
]
42 changes: 42 additions & 0 deletions projects/example_projects/example_project_ev_opt/config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#--------------------------
# scenario
#--------------------------
# load existing scenario
load_scenario = True
# possible data_formats: json, csv
data_format = csv

#--------------------------
# market
#--------------------------
# start timestep
start = 0
# number of timesteps in simulation
nb_ts = 13
horizon = 10
# interval between simulation timesteps
ts_per_hour = 4

# which market type to use? fair, pac
market_type = fair
# reset market after each interval (discard unmatched orders)
reset_market = True
# size of energy units to be traded individually
energy_unit = 0.01
# factor describing the relation of grid fee to cumulative power network edge weights
weight_factor = 0.03
# default grid_fee to be used by market maker
default_grid_fee = 0.09
# local grid fee applied for trades within a cluster
local_grid_fee = 0.02

#--------------------------
# output
#--------------------------
# print debug info to console
show_prints = true
# show various plots
show_plots = true
# save orders and matching results to csv files
save_csv = true
#--------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"example_network": {
"directed": false,
"multigraph": false,
"graph": {},
"nodes": [
{
"id": "N01"
},
{
"id": "N02"
}
],
"links": [
{
"weight": 1,
"source": "N01",
"target": "N02"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
,all_buy_prices,all_sell_prices
0,0.05087,0.05087
1,0.05087,0.05087
2,0.05087,0.05087
3,0.05087,0.05087
4,0.04819,0.04819
5,0.04819,0.04819
6,0.04819,0.04819
7,0.04819,0.04819
8,0.04468,0.04468
9,0.04468,0.04468
10,0.04468,0.04468
11,0.04468,0.04468
12,0.04292,0.04292
13,0.04292,0.04292
14,0.04292,0.04292
15,0.04292,0.04292
16,0.04039,0.04039
17,0.04039,0.04039
18,0.04039,0.04039
19,0.04039,0.04039
20,0.0402,0.0402
21,0.0402,0.0402
22,0.0402,0.0402
23,0.0402,0.0402
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rng_seed": 1963995559
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Time,load,pv,schedule
2016-01-01 00:00:00,0.011886246327641098,7.04546466156181e-05,-0.01181579168102548
2016-01-01 00:15:00,0.0410388447933982,0.0002472798864404,-0.040791564906957796
2016-01-01 00:30:00,0.0406771589865564,0.0002556439361969,-0.0404215150503595
2016-01-01 00:45:00,0.0405878697548583,0.00035547628083399996,-0.0402323934740243
2016-01-01 01:00:00,0.0408237818838657,0.0010430721723367,-0.039780709711529
2016-01-01 01:15:00,0.0407177271612198,0.0010594459560612,-0.039658281205158595
2016-01-01 01:30:00,0.0155266774334944,0.0021104014895109,-0.013416275943983499
2016-01-01 01:45:00,0.0163007931439657,0.0012627368346117,-0.015038056309354002
2016-01-01 02:00:00,0.0322130119232581,0.0034005784433971996,-0.028812433479860903
2016-01-01 02:15:00,0.0091297259677855,0.0034302420258755994,-0.0056994839419099
2016-01-01 02:30:00,0.0193711826356853,0.0044974952377916,-0.0148736873978937
2016-01-01 02:45:00,0.028851808922693505,0.0087416387113377,-0.020110170211355805
2016-01-01 03:00:00,0.0092306359903934,0.0054444566014102,-0.0037861793889832004
2016-01-01 03:15:00,0.021129578178791,0.013092584681101398,-0.0080369934976896
2016-01-01 03:30:00,0.0261416596035054,0.0143581217010604,-0.011783537902444999
2016-01-01 03:45:00,0.009300330445916,0.0010009727768025,-0.0082993576691135
2016-01-01 04:00:00,0.0264843050659245,0.0190323954720175,-0.007451909593907003
2016-01-01 04:15:00,0.0405926330346124,0.0020486715257943,-0.0385439615088181
2016-01-01 04:30:00,0.040739211280267,0.0437830919236495,0.003043880643382499
2016-01-01 04:45:00,0.0405072188688263,0.0031536962879483,-0.037353522580878
2016-01-01 05:00:00,0.0364741472516811,0.0083302330939972,-0.0281439141576839
2016-01-01 05:15:00,0.0093203889536746,0.0306331420625005,0.0213127531088259
2016-01-01 05:30:00,0.0255923848829077,0.0366225507371767,0.011030165854268997
2016-01-01 05:45:00,0.022564346575841502,0.0050192915366731,-0.0175450550391684
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Time,load,pv,schedule
2016-01-01 00:00:00,0.0542322728238491,0,-0.0542322728238491
2016-01-01 00:15:00,0.033030005643254305,0,-0.033030005643254305
2016-01-01 00:30:00,0.0142862986715691,0,-0.0142862986715691
2016-01-01 00:45:00,0.0141467792373111,0,-0.0141467792373111
2016-01-01 01:00:00,0.0142478747577574,0,-0.0142478747577574
2016-01-01 01:15:00,0.0142467892610824,0,-0.0142467892610824
2016-01-01 01:30:00,0.0258862073719723,0,-0.0258862073719723
2016-01-01 01:45:00,0.0275837814486352,0,-0.0275837814486352
2016-01-01 02:00:00,0.0143721215284459,0,-0.0143721215284459
2016-01-01 02:15:00,0.0142922358318904,0,-0.0142922358318904
2016-01-01 02:30:00,0.0309747101252188,0,-0.0309747101252188
2016-01-01 02:45:00,0.0174783232826058,0,-0.0174783232826058
2016-01-01 03:00:00,0.0144721663610269,0,-0.0144721663610269
2016-01-01 03:15:00,0.0142060443537789,0,-0.0142060443537789
2016-01-01 03:30:00,0.0140319164885409,0,-0.0140319164885409
2016-01-01 03:45:00,0.0832210665762793,0,-0.0832210665762793
2016-01-01 04:00:00,0.2529950562998062,0,-0.2529950562998062
2016-01-01 04:15:00,0.11682297414734,0,-0.11682297414734
2016-01-01 04:30:00,0.1520900997528187,0,-0.1520900997528187
2016-01-01 04:45:00,0.1552827818895501,0,-0.1552827818895501
2016-01-01 05:00:00,0.1564985586562892,0,-0.1564985586562892
2016-01-01 05:15:00,0.0976440743721818,0,-0.0976440743721818
2016-01-01 05:30:00,0.0298138002225059,0,-0.0298138002225059
2016-01-01 05:45:00,0.0143183628313887,0,-0.0143183628313887
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Time,load,pv,schedule,ev_avail,ev_demand
2016-01-01 00:00:00,0.0183501135461672,7.04546466156181e-05,-0.01827965889955158,1.0,0.0
2016-01-01 00:15:00,0.0183276402096313,0.0002472798864404,-0.0180803603231909,1.0,0.0
2016-01-01 00:30:00,0.0186881603411869,0.0002556439361969,-0.01843251640499,1.0,0.0
2016-01-01 00:45:00,0.0184871298585762,0.00035547628083399996,-0.018131653577742202,1.0,0.0
2016-01-01 01:00:00,0.0179609033250519,0.0010430721723367,-0.0169178311527152,1.0,0.0
2016-01-01 01:15:00,0.0183569591857021,0.0010594459560612,-0.017297513229640897,1.0,0.0
2016-01-01 01:30:00,0.0429906796923723,0.0021104014895109,-0.0408802782028614,1.0,0.0
2016-01-01 01:45:00,0.0468752880631146,0.0012627368346117,-0.0456125512285029,1.0,0.0
2016-01-01 02:00:00,0.04839955195562141,0.0034005784433971996,-0.044998973512224205,1.0,0.0
2016-01-01 02:15:00,0.04895941513644,0.0034302420258755994,-0.0455291731105644,1.0,0.0
2016-01-01 02:30:00,0.0448443403712756,0.0044974952377916,-0.040346845133483994,1.0,0.0
2016-01-01 02:45:00,0.0243064739511402,0.0087416387113377,-0.0155648352398025,1.0,0.0
2016-01-01 03:00:00,0.0495014864417933,0.0054444566014102,-0.0440570298403831,1.0,0.0
2016-01-01 03:15:00,0.0493275564676503,0.013092584681101398,-0.0362349717865489,1.0,0.0
2016-01-01 03:30:00,0.0503633213311156,0.0143581217010604,-0.036005199630055204,1.0,0.0
2016-01-01 03:45:00,0.0499530098865384,0.0010009727768025,-0.0489520371097359,0.0,15.3136
2016-01-01 04:00:00,0.0291384623307321,0.0190323954720175,-0.0101060668587146,0.0,0.0
2016-01-01 04:15:00,0.0181229042056159,0.0020486715257943,-0.016074232679821603,0.0,0.0
2016-01-01 04:30:00,0.0184295811072935,0.0437830919236495,0.025353510816356,0.0,0.0
2016-01-01 04:45:00,0.0184305987280745,0.0031536962879483,-0.0152769024401262,0.0,0.0
2016-01-01 05:00:00,0.0185237682294309,0.0083302330939972,-0.0101935351354337,0.0,0.0
2016-01-01 05:15:00,0.0185859507615892,0.0306331420625005,0.012047191300911302,0.0,0.0
2016-01-01 05:30:00,0.0183005206430141,0.0366225507371767,0.018322030094162597,0.0,0.0
2016-01-01 05:45:00,0.0855216764172982,0.0050192915366731,-0.0805023848806251,0.0,0.0
Loading

0 comments on commit 9bf70f0

Please sign in to comment.