Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
6c3b188
added class to compute daily residual consumption
matiasbresciano Apr 9, 2025
31416c1
residual consumption
matiasbresciano Apr 10, 2025
19f08b8
refactor read antares data and added calculate gain function for tempo
matiasbresciano Apr 10, 2025
a97c6c4
gain function and bellman value
matiasbresciano Apr 10, 2025
0fc4fd8
bellman values uv and test
matiasbresciano Apr 11, 2025
ccc53be
trajectories
matiasbresciano Apr 14, 2025
1154c4b
trajectories
matiasbresciano Apr 15, 2025
723f5c9
tempo white and red
matiasbresciano Apr 15, 2025
4ea7076
white and red plot
matiasbresciano Apr 16, 2025
73e856b
red, white+red and red tempo calculation and plot
matiasbresciano Apr 17, 2025
659e97e
added requirements
matiasbresciano Apr 17, 2025
78a4200
test
matiasbresciano Apr 18, 2025
eed93be
update ubuntu on ci.yml
matiasbresciano Apr 18, 2025
008ebe3
refactor class names
matiasbresciano Apr 18, 2025
927ffb3
refactor file names
matiasbresciano Apr 18, 2025
34da20c
names
matiasbresciano Apr 18, 2025
fb0eb40
final names
matiasbresciano Apr 18, 2025
731caa5
import plotly
matiasbresciano Apr 18, 2025
117b3c9
rename
matiasbresciano Apr 18, 2025
ea6b081
name
matiasbresciano Apr 18, 2025
b745997
name
matiasbresciano Apr 18, 2025
025517a
index issue fix and test passing verification
matiasbresciano Apr 18, 2025
c6488eb
bellman and usage values , trajectories for hydro storage
matiasbresciano May 5, 2025
67d02d1
test fix
matiasbresciano May 5, 2025
e71511e
fix cy issues
matiasbresciano May 5, 2025
798de3d
merge for tempo trajectories calculation
matiasbresciano May 6, 2025
1afed82
merge trajectories tempo
matiasbresciano May 6, 2025
3c1b752
merge tempo calculation and tests
matiasbresciano May 6, 2025
383d8c0
rename residual load to net load
matiasbresciano May 6, 2025
f08092e
numpy version forced to 1.26.4
matiasbresciano May 7, 2025
eb75371
fix imports
matiasbresciano May 7, 2025
56acc47
improve calculation time for gain function
matiasbresciano May 19, 2025
82e11fc
Merge branch 'main' into Matias-Bresciano-branch
matiasbresciano May 19, 2025
2d10aba
2 options to compute gain functions : reversed method which starts wi…
matiasbresciano May 20, 2025
9e6640c
methods to exports controls and trajectories added
matiasbresciano May 20, 2025
6f94547
Bellman values calculation modified to incorporate CVar calculation (…
matiasbresciano May 22, 2025
5b61b35
CVar as parameter missing, fixed
matiasbresciano May 22, 2025
5e2643e
I changed the structure of the code (now it must be run from a termin…
matiasbresciano May 28, 2025
8e4970c
final version
matiasbresciano May 28, 2025
9f5553f
bug fix
matiasbresciano May 28, 2025
0f11416
The stage cost function now integrates pumping and turbine
matiasbresciano Jun 3, 2025
4feb06b
Trajectories are now calculated with standard Bellman values optimiza…
matiasbresciano Jun 4, 2025
e048af6
CVar integrated
matiasbresciano Jun 4, 2025
35d2abb
Calculation of trajectories simplified.
matiasbresciano Jun 4, 2025
423b301
Adapted the tests to the new trajectories structure
matiasbresciano Jun 5, 2025
45fec8c
Penalty function added to compute rule curves constraints
matiasbresciano Jun 6, 2025
d14483c
I added an option to see overlaid curves for all MC. Also the plot is…
matiasbresciano Jun 6, 2025
231313c
error in max pumping parameter
matiasbresciano Jun 6, 2025
b61c44e
deleted useless coments
matiasbresciano Jun 6, 2025
7aff139
gain function is now computed over all possible controls (negative an…
matiasbresciano Jun 6, 2025
9c06c61
plot is now saved into html file. It is also possible to see overlaid…
matiasbresciano Jun 6, 2025
30f57c4
New feature added : now we can see the energy tubined and pumped each…
matiasbresciano Jun 10, 2025
da129bc
heatmap plot added to visualize water values. Error on bellman value …
matiasbresciano Jun 12, 2025
44b093b
indexation errors fix and alignement between hydro and tempo model. A…
matiasbresciano Jun 12, 2025
093d51d
index errors fix and alignment between hydro and tempo model
matiasbresciano Jun 12, 2025
c769374
penalty function modified
matiasbresciano Jun 20, 2025
c5bd9c7
added log, modified penalty function, added a method to compute initi…
matiasbresciano Jun 20, 2025
7991aef
modified methods parameters
matiasbresciano Jun 20, 2025
03fbdb2
added daily inflows
matiasbresciano Jun 20, 2025
4ab836f
Launcher class and new file names
matiasbresciano Jun 23, 2025
034bbe5
hourly rule curves calculation method, modification of the antares st…
matiasbresciano Jun 25, 2025
5386805
clip max daily pumping and generating to avoid unfesabilities in antares
matiasbresciano Jun 25, 2025
98c0eb0
modify definition of daily rule curves
matiasbresciano Jun 25, 2025
de2e68f
mofidy hourly rule curves calculation
matiasbresciano Jul 1, 2025
539fe38
computation of hourly rule curve
matiasbresciano Jul 1, 2025
d1ba1c5
computation of hourly rule curves with trajectories
matiasbresciano Jul 2, 2025
699797e
refactor structure and added multi-areas computation
matiasbresciano Jul 3, 2025
e7281b3
added allocation matrix read
matiasbresciano Jul 7, 2025
4ec6d8f
adjust trajectories to respect rule curves and 0-100 stock bounds
matiasbresciano Jul 7, 2025
374f22d
net load calculation modified with allocation matrix and bug fix
matiasbresciano Jul 11, 2025
25d7ddc
rounding errors fix
matiasbresciano Jul 15, 2025
01f5d4e
round to 1e-6 all calculations
matiasbresciano Jul 15, 2025
eb1b243
code refactor
matiasbresciano Jul 16, 2025
49a1e66
refactor
matiasbresciano Jul 21, 2025
b43ecd9
added optionnal parser target area
matiasbresciano Jul 23, 2025
874d454
post-process of shared file modified
matiasbresciano Jul 24, 2025
b194611
adjust inflow
matiasbresciano Jul 24, 2025
9fe1c9e
input errors fix
matiasbresciano Jul 25, 2025
e9fcc0b
hourly rule curves calculation added and added parser MC_years list o…
matiasbresciano Jul 28, 2025
92d9750
hourly rule curves calculation added
matiasbresciano Jul 28, 2025
33e85e5
undo last commit
matiasbresciano Jul 28, 2025
62f99a8
mc_years replaced by nb_scenarios
matiasbresciano Jul 28, 2025
5645f9c
fictive node capacity read in link
matiasbresciano Jul 28, 2025
3261a5d
added parsers and exports of vu
matiasbresciano Jul 29, 2025
d2c4255
commentaries added
matiasbresciano Jul 30, 2025
46b859b
adapted to new variable in read_antares_data
matiasbresciano Jul 30, 2025
d7ba3b3
tests updated
matiasbresciano Jul 30, 2025
680daa2
tqdm add
matiasbresciano Aug 6, 2025
c0c7154
tqdm add
matiasbresciano Aug 6, 2025
777cbc3
added margin factor h
matiasbresciano Aug 8, 2025
ee127bd
added rule curves
matiasbresciano Aug 11, 2025
76660d0
cleaned code
matiasbresciano Aug 28, 2025
1437cda
cleaned code
matiasbresciano Aug 28, 2025
ceaac7b
cleaned code
matiasbresciano Aug 28, 2025
53f34a2
cleaned code
matiasbresciano Aug 28, 2025
560f8f6
cleaned code
matiasbresciano Aug 28, 2025
4e2df13
added test data, test code, modified value of penalty (upper bound on…
matiasbresciano Sep 10, 2025
f2d8e76
added tqdm
matiasbresciano Sep 10, 2025
3571edb
removed old adjusted rule curves calculations, cleaned the code, modi…
matiasbresciano Sep 10, 2025
0591af7
lower rule curve for tempo red can now be modified at the top of the …
matiasbresciano Sep 10, 2025
dc2f04d
cleaned and simplified plots
matiasbresciano Sep 10, 2025
f8bda6e
uncomment bellman values calculation
matiasbresciano Sep 10, 2025
b88c0b6
modified tests and code for more efficiency
matiasbresciano Sep 15, 2025
73025b5
added tests
matiasbresciano Sep 23, 2025
4aa8936
updated code
matiasbresciano Sep 23, 2025
94c7eb5
max_control is now a parameter of Bellman_values class, only one calc…
matiasbresciano Sep 25, 2025
e081bd8
updated test to latests changes
matiasbresciano Sep 25, 2025
627a9d2
usage values plot added
matiasbresciano Sep 26, 2025
6afd2f7
changed usage values calculation
matiasbresciano Sep 26, 2025
6062c8b
added function to export usage values
matiasbresciano Sep 26, 2025
273d14e
added export usage values action
matiasbresciano Sep 26, 2025
5d03266
added usage values plotter
matiasbresciano Sep 26, 2025
a0f6f09
changed computation of stage cost functions, bellman values and traje…
matiasbresciano Dec 27, 2025
c6d961e
added run_log file with general information about the simulation
matiasbresciano Dec 29, 2025
be13729
removed detailed logger
matiasbresciano Dec 29, 2025
f53de95
updated comments
matiasbresciano Dec 29, 2025
c8b4ee2
removed useless methods
matiasbresciano Dec 29, 2025
4b46a8d
removed useless methods
matiasbresciano Dec 29, 2025
dcf49db
removed useless methods
matiasbresciano Dec 29, 2025
8910a8e
updated comments
matiasbresciano Dec 29, 2025
616b77b
uupdated test
matiasbresciano Dec 29, 2025
fc42363
fixed typing
matiasbresciano Dec 29, 2025
dde676c
removed calculation of turbined and pumped energy each week
matiasbresciano Dec 30, 2025
4e47ada
fixed typing issue
matiasbresciano Dec 30, 2025
1bfe577
fixed typing issue
matiasbresciano Dec 30, 2025
e2d9f10
corrections
matiasbresciano Jan 5, 2026
0d0da48
corrections
matiasbresciano Jan 5, 2026
93c931a
vectorized bellman values and trajectories computation
matiasbresciano Jan 6, 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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:

jobs:
ci:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
uses: actions/setup-python@v4
with:
python-version: 3.11
python-version: 3.12
cache: pip
cache-dependency-path: |
requirements.txt
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ black
isort
mypy
pytest
plotly
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
numpy
numpy==1.26.4
matplotlib
scipy
xpress
ortools
ortools
tqdm
38 changes: 19 additions & 19 deletions src/calculate_reward_and_bellman_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ def get_penalty(self, week: int, len_week: int) -> Callable:
pen = interp1d(
[
0,
self.reservoir.bottom_rule_curve[week],
self.reservoir.upper_rule_curve[week],
self.reservoir.weekly_lower_rule_curve[week],
self.reservoir.weekly_upper_rule_curve[week],
self.reservoir.capacity,
],
[
-self.penalty_bottom_rule_curve
* (self.reservoir.bottom_rule_curve[week]),
* (self.reservoir.weekly_lower_rule_curve[week]),
0,
0,
-self.penalty_upper_rule_curve
* (self.reservoir.capacity - self.reservoir.upper_rule_curve[week]),
* (self.reservoir.capacity - self.reservoir.weekly_upper_rule_curve[week]),
],
)
return pen
Expand Down Expand Up @@ -287,13 +287,13 @@ def solve_weekly_problem_with_approximation(
X = self.stock_discretization

for i_fut in range(len(X)):
u = -X[i_fut] + level_i + stock.inflow[week, scenario]
if -stock.max_pumping[week] * stock.efficiency <= u:
u = -X[i_fut] + level_i + stock.weekly_inflow[week, scenario]
if -stock.max_weekly_pump[week] * stock.efficiency <= u:
if (
self.reservoir_management.overflow
or u <= stock.max_generating[week]
or u <= stock.max_weekly_turb[week]
):
u = min(u, stock.max_generating[week])
u = min(u, stock.max_weekly_turb[week])
G = reward_fn(u)
penalty = pen(X[i_fut])
if (G + V_fut(X[i_fut]) + penalty) > Vu:
Expand All @@ -302,7 +302,7 @@ def solve_weekly_problem_with_approximation(
control = u

for u in range(len(points)):
state_fut = level_i - points[u] + stock.inflow[week, scenario]
state_fut = level_i - points[u] + stock.weekly_inflow[week, scenario]
if 0 <= state_fut <= stock.capacity:
penalty = pen(state_fut)
G = reward_fn(points[u])
Expand All @@ -311,35 +311,35 @@ def solve_weekly_problem_with_approximation(
xf = state_fut
control = points[u]

Umin = level_i + stock.inflow[week, scenario] - stock.bottom_rule_curve[week]
Umin = level_i + stock.weekly_inflow[week, scenario] - stock.weekly_lower_rule_curve[week]
if (
-stock.max_pumping[week] * stock.efficiency
-stock.max_weekly_pump[week] * stock.efficiency
<= Umin
<= stock.max_generating[week]
<= stock.max_weekly_turb[week]
):
state_fut = level_i - Umin + stock.inflow[week, scenario]
state_fut = level_i - Umin + stock.weekly_inflow[week, scenario]
penalty = pen(state_fut)
if (reward_fn(Umin) + V_fut(state_fut) + penalty) > Vu:
Vu = reward_fn(Umin) + V_fut(state_fut) + penalty
xf = state_fut
control = Umin

Umax = level_i + stock.inflow[week, scenario] - stock.upper_rule_curve[week]
Umax = level_i + stock.weekly_inflow[week, scenario] - stock.weekly_upper_rule_curve[week]
if (
-stock.max_pumping[week] * stock.efficiency
-stock.max_weekly_pump[week] * stock.efficiency
<= Umax
<= stock.max_generating[week]
<= stock.max_weekly_turb[week]
):
state_fut = level_i - Umax + stock.inflow[week, scenario]
state_fut = level_i - Umax + stock.weekly_inflow[week, scenario]
penalty = pen(state_fut)
if (reward_fn(Umax) + V_fut(state_fut) + penalty) > Vu:
Vu = reward_fn(Umax) + V_fut(state_fut) + penalty
xf = state_fut
control = Umax

control = min(
-(xf - level_i - stock.inflow[week, scenario]),
stock.max_generating[week],
-(xf - level_i - stock.weekly_inflow[week, scenario]),
stock.max_weekly_turb[week],
)
return (Vu, xf, control)

Expand Down
4 changes: 2 additions & 2 deletions src/functions_iterative.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,9 @@ def init_iterative_calculation(
for week in range(len_week):
for scenario in range(len_scenario):
r = RewardApproximation(
lb_control=-reservoir_management.reservoir.max_pumping[week]
lb_control=-reservoir_management.reservoir.max_weekly_pump[week]
* reservoir_management.reservoir.efficiency,
ub_control=reservoir_management.reservoir.max_generating[week],
ub_control=reservoir_management.reservoir.max_weekly_turb[week],
ub_reward=0,
)
G[TimeScenarioIndex(week, scenario)] = r
Expand Down
14 changes: 7 additions & 7 deletions src/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ def create_weekly_problem_itr(
)

U = model.Var(
lb=-reservoir_management.reservoir.max_pumping[self.week]
lb=-reservoir_management.reservoir.max_weekly_pump[self.week]
* reservoir_management.reservoir.efficiency,
ub=reservoir_management.reservoir.max_generating[self.week],
ub=reservoir_management.reservoir.max_weekly_turb[self.week],
integer=False,
name="u",
)
Expand All @@ -236,15 +236,15 @@ def create_weekly_problem_itr(
x_s_1
<= x_s
- U
+ reservoir_management.reservoir.inflow[self.week, self.scenario],
+ reservoir_management.reservoir.weekly_inflow[self.week, self.scenario],
name=f"ReservoirConservation::area<{reservoir_management.reservoir.area}>::week<{self.week}>",
)
else:
model.Add(
x_s_1
== x_s
- U
+ reservoir_management.reservoir.inflow[self.week, self.scenario],
+ reservoir_management.reservoir.weekly_inflow[self.week, self.scenario],
name=f"ReservoirConservation::area<{reservoir_management.reservoir.area}>::week<{self.week}>",
)

Expand All @@ -256,13 +256,13 @@ def create_weekly_problem_itr(
model.Add(
y
>= -reservoir_management.penalty_bottom_rule_curve
* (x_s_1 - reservoir_management.reservoir.bottom_rule_curve[self.week]),
* (x_s_1 - reservoir_management.reservoir.weekly_lower_rule_curve[self.week]),
name=f"PenaltyForViolatingBottomRuleCurve::area<{reservoir_management.reservoir.area}>::week<{self.week}>",
)
model.Add(
y
>= reservoir_management.penalty_upper_rule_curve
* (x_s_1 - reservoir_management.reservoir.upper_rule_curve[self.week]),
* (x_s_1 - reservoir_management.reservoir.weekly_upper_rule_curve[self.week]),
name=f"PenaltyForViolatingUpperRuleCurve::area<{reservoir_management.reservoir.area}>::week<{self.week}>",
)
else:
Expand Down Expand Up @@ -506,7 +506,7 @@ def solve_problem_with_bellman_values(
-(
xf
- level_i
- bellman_value_calculation.reservoir_management.reservoir.inflow[
- bellman_value_calculation.reservoir_management.reservoir.weekly_inflow[
self.week, self.scenario
]
),
Expand Down
Loading