Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business plan plot #12

Merged
merged 41 commits into from
Nov 13, 2023
Merged

Business plan plot #12

merged 41 commits into from
Nov 13, 2023

Conversation

TomFer97
Copy link
Member

No description provided.

@TomFer97
Copy link
Member Author

I've renamed the back but it still shows sankey_branch should I do git fetch?

@davide-f
Copy link
Member

Have you tested the execution of the function?

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice implementation!

I've added some comments.
It could also be nice to add a test once finished.

may you attach a plot of the image you obtain here for discussing it?

Awesome PR!!!

Project.toml Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is getting a very nice shape! :D

src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated
NPV = profit_distribution

# Total reward
Ann_reward = NPV .+ CAPEX .+ OPEX .+ Ann_Replacement .- Ann_Recovery
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't touch this line as I guess it is not clear.

In the original split function all this values where 1D arrays by user that represent the total discounted values by entity.
Therefore, by making the appropriate differences we calculated the total discounted reward allocation by user.

Now with each variable being 2D that is a bit tricky to do.
I think we should first identify the total annualized reward allocation and then (assumption) uniformly distribute it across the years.
Given that all the structures are 2D there is for sure a smart way to do that; I propose an approach, but feel to propose an alternative.

Basically, what we may need to do is to create a proxy total discounted cost of all terms but NPV so to reproduce the old (CAPEX .+ OPEX .+ Ann_Replacement .- Ann_Recovery).
For example, something like:
(CAPEX .+ OPEX .+ Ann_Replacement .- Ann_Recovery).data * ann_factor (note that since they are matrix operation, there may be the need for some transpositions

Then, the resulting vector shall be a 1 column or 1 vector and we can create the equivalent 1D cost vector, so that we can do (total_discounted_reward = NPV .- new_vector).
Then, we can do total_discounted_reward ./(sum(act_factor) - 1) and this should be a 1D vector of the yearly reward allocation by user, that can be exploded into 2D by simply duplicating the entries.

src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated
REWARD = Float64[], RV = Float64[], PEAK = Float64[])
for i in years
CAPEX = sum(business_plan.CAPEX[i, :])
Year = 0 + years[i]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The year set may be obtained from the axis of any function of business_plan, what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll think about it

src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
@TomFer97
Copy link
Member Author

TomFer97 commented Oct 9, 2023

Unfortunately the last commit allow me to obtain something like this.
business_plan

@davide-f
Copy link
Member

I see.
May you please check and post the screen of the table calculated by business_plan?

@TomFer97
Copy link
Member Author

This is the dataframe. For sure OEM, EN_SELL, REWARD and RV must be 0 the first year. And REP 0 except the year of substitution. EN_CONS and PEAK is always 0 except for last year

21×9 DataFrame
Row │ Year CAPEX OEM EN_SELL EN_CONS REP REWARD RV PEAK
│ Int64 Float64 Float64 Float64 Float64 Float64 Float64 Float64 Float64
───┼───────────────────────────────────────────────────────────────────────
1 │ 0 3.96488e5 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
2 │ 1 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
3 │ 2 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
4 │ 3 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
5 │ 4 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
6 │ 5 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
7 │ 6 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
8 │ 7 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
9 │ 8 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
10 │ 9 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
11 │ 10 0.0 5568.01 2337.41 1686.68 -1.07268e5 1666.37 52369.5 0.0
12 │ 11 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
13 │ 12 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
14 │ 13 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
15 │ 14 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
16 │ 15 0.0 5568.01 2337.41 3373.36 -1.07268e5 1666.37 52369.5 0.0
17 │ 16 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
18 │ 17 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
19 │ 18 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
20 │ 19 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 0.0
21 │ 20 0.0 5568.01 2337.41 0.0 -1.07268e5 1666.37 52369.5 36447.2

@TomFer97
Copy link
Member Author

TomFer97 commented Nov 2, 2023

I forgot in which part of the code insert ECModel.results[:R_Reward_agg_tot] = 0 for non_cooperative in order to create a reward variable that is = 0 for non cooperative and >0 for cooperative and ANC. You showed it to me but I forgot and I didn't apply the changes

Copy link
Member

@davide-f davide-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool Tommaso :D
I think we are close to finalize :D
Could you add a sample plot as well?

Project.toml Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
src/ECModel.jl Outdated Show resolved Hide resolved
@davide-f
Copy link
Member

davide-f commented Nov 5, 2023

I forgot in which part of the code insert ECModel.results[:R_Reward_agg_tot] = 0 for non_cooperative in order to create a reward variable that is = 0 for non cooperative and >0 for cooperative and ANC. You showed it to me but I forgot and I didn't apply the changes

Here :)

You can get inspiration from here:

# Power of the aggregator
ECModel.results[:P_agg] = JuMP.Containers.DenseAxisArray(
[sum(ECModel.results[:P_us][:, t]) for t in time_set],
time_set
)
# Shared power: the minimum between the supply and demand for each time step
ECModel.results[:P_shared_agg] = JuMP.Containers.DenseAxisArray(
[
min(
sum(ECModel.results[:P_P_us][:, t]),
sum(ECModel.results[:P_N_us][:, t])
)
for t in time_set],
time_set
)
# Total reward awarded to the community at each time step
ECModel.results[:R_Reward_agg] = JuMP.Containers.DenseAxisArray(
[
profile(ECModel.gen_data,"energy_weight")[t] * profile(ECModel.gen_data, "time_res")[t] *
profile(ECModel.gen_data, "reward_price")[t] * ECModel.results[:P_shared_agg][t]
for t in time_set],
time_set
)
# Total reward awarded to the community in a year
ECModel.results[:R_Reward_agg_tot] = sum(ECModel.results[:R_Reward_agg])
# Total reward awarded to the aggregator in NPV terms
ECModel.results[:R_Reward_agg_NPV] = (
ECModel.results[:R_Reward_agg_tot] * sum(1 / ((1 + field(gen_data, "d_rate"))^y) for y in year_set)
)
# Total reward awarded to the aggregator in NPV terms
ECModel.results[:NPV_agg] = ECModel.results[:R_Reward_agg_NPV]
# Cash flow
ECModel.results[:Cash_flow_agg] = JuMP.Containers.DenseAxisArray(
[(y == 0) ? 0.0 : ECModel.results[:R_Reward_agg_tot] for y in year_set_0],
year_set_0
)
# Cash flow total
ECModel.results[:Cash_flow_tot] = JuMP.Containers.DenseAxisArray(
[
((y == 0) ? 0.0 :
sum(ECModel.results[:Cash_flow_us][y, :]) + ECModel.results[:Cash_flow_agg][y])
for y in year_set_0
],
year_set_0
)
# Social welfare of the users
ECModel.results[:SW_us] = sum(ECModel.results[:NPV_us])
# Social welfare of the entire aggregation
ECModel.results[:SW] = ECModel.results[:SW_us] + ECModel.results[:NPV_agg]
ECModel.results[:objective_value] = ECModel.results[:SW]

Basically all expressions mentioned there should be available in the NC configuration as well, with appropriate values (including many 0s)

Apologies for the late reply, I didn't see the message at first

@TomFer97
Copy link
Member Author

TomFer97 commented Nov 7, 2023

plot_25
I Think that It's almost completed but I still get this problem with the label of the plot. Probably collect(keys(plot_struct)) is making some problems. I tought that with a list it would have been resolved

@davide-f
Copy link
Member

davide-f commented Nov 7, 2023

Maybe its the key: "labelS".
Test it locally

@TomFer97
Copy link
Member Author

TomFer97 commented Nov 8, 2023

The key labelS=bar_labels, kwargs...) cancel completely the following keys. Maybe it's because it's a vector and maybe should require a list but I've tried with [keys(plot_struct)] and It gives me a strange error. Maybe list(keys(plot_struct))?

@davide-f
Copy link
Member

davide-f commented Nov 8, 2023

It may be the type of object that is a matrix instead.

[1 2 3] is a 2D matrix 1×3
[1, 2, 3] is a 1D vector

hcat(collect(keys(..))...)
May work. Maybe the collect is not needed but I'm unsure

@davide-f davide-f force-pushed the sankey_branch branch 2 times, most recently from d25b9e6 to eb0ebae Compare November 13, 2023 17:31
@davide-f davide-f merged commit 4e6a2a8 into SPSUnipi:main Nov 13, 2023
2 checks passed
@davide-f
Copy link
Member

@TomFer97 Merged :D

@davide-f davide-f mentioned this pull request Nov 15, 2023
@TomFer97 TomFer97 deleted the sankey_branch branch November 20, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants