Skip to content

Commit

Permalink
possibility of snapshot modelling (one over night investment) in the …
Browse files Browse the repository at this point in the history
…planning mode
  • Loading branch information
Negnamazi committed Jan 19, 2024
1 parent ce2227c commit f17ffb4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 88 deletions.
191 changes: 110 additions & 81 deletions hypatia/backend/Build.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,6 @@ def _calc_variable_planning(self):
self.sets.data[reg]["inv_taxsub"]["Sub"][key],
)

salvage_inv_regional[key] = cp.multiply(
salvage_factor(
self.sets.main_years,
self.sets.Technologies[reg][key],
self.sets.data[reg]["tech_lifetime"].loc[:, key],
self.sets.data[reg]["interest_rate"].loc[:, key],
self.sets.data[reg]["discount_rate"],
self.sets.data[reg]["economic_lifetime"].loc[:, key],
self.sets.period_step
),
cost_inv_regional[key],
)

accumulated_newcapacity_regional[key] = newcap_accumulated(
self.variables["newcapacity"][reg][key],
self.sets.Technologies[reg][key],
Expand All @@ -523,18 +510,7 @@ def _calc_variable_planning(self):
self.sets.data[reg]["fix_taxsub"]["Sub"][key],
)

decomcapacity_regional[key] = decomcap(
self.variables["newcapacity"][reg][key],
self.sets.Technologies[reg][key],
self.sets.main_years,
self.sets.data[reg]["tech_lifetime"].loc[:, key],
self.sets.period_step,
)

cost_decom_regional[key] = cp.multiply(
self.sets.data[reg]["tech_decom_cost"].loc[:, key].values,
decomcapacity_regional[key],
)

production_annual_regional[key] = annual_activity(
self.variables["productionbyTechnology"][reg][key],
Expand Down Expand Up @@ -568,16 +544,45 @@ def _calc_variable_planning(self):
CO2_equivalent_regional[key],
self.sets.data[reg]["carbon_tax"].loc[:, key],
)

if not self.sets.snapshot:

salvage_inv_regional[key] = cp.multiply(
salvage_factor(
self.sets.main_years,
self.sets.Technologies[reg][key],
self.sets.data[reg]["tech_lifetime"].loc[:, key],
self.sets.data[reg]["interest_rate"].loc[:, key],
self.sets.data[reg]["discount_rate"],
self.sets.data[reg]["economic_lifetime"].loc[:, key],
self.sets.period_step
),
cost_inv_regional[key],
)

decomcapacity_regional[key] = decomcap(
self.variables["newcapacity"][reg][key],
self.sets.Technologies[reg][key],
self.sets.main_years,
self.sets.data[reg]["tech_lifetime"].loc[:, key],
self.sets.period_step,
)

cost_decom_regional[key] = cp.multiply(
self.sets.data[reg]["tech_decom_cost"].loc[:, key].values,
decomcapacity_regional[key],
)

cost_fvalue_regional[key] = invcosts_annuity(
cost_inv_regional[key],
self.sets.data[reg]["interest_rate"].loc[:, key],
self.sets.data[reg]["economic_lifetime"].loc[:, key],
self.sets.Technologies[reg][key],
self.sets.main_years,
self.sets.data[reg]["discount_rate"],
self.sets.period_step
)

cost_fvalue_regional[key] = invcosts_annuity(
cost_inv_regional[key],
self.sets.data[reg]["interest_rate"].loc[:, key],
self.sets.data[reg]["economic_lifetime"].loc[:, key],
self.sets.Technologies[reg][key],
self.sets.main_years,
self.sets.data[reg]["discount_rate"],
self.sets.period_step
)

self.cost_inv[reg] = cost_inv_regional
self.cost_inv_tax[reg] = cost_inv_tax_regional
Expand Down Expand Up @@ -646,20 +651,7 @@ def _calc_variable_planning_line(self):
+ self.sets.trade_data["line_residual_cap"].loc[:, line].values
)

self.line_decommissioned_capacity[line] = line_decomcap(
self.line_newcapacity[line],
self.sets.trade_line[line],
self.sets.main_years,
self.sets.trade_data["line_lifetime"].loc[:, line],
self.sets.period_step,
)

self.cost_decom_line[line] = cp.multiply(cp.multiply(
self.sets.trade_data["line_decom_cost"].loc[:, line].values,
self.line_decommissioned_capacity[line],
), self.sets.trade_data["line_length"].loc[:,line].values)



self.cost_inv_line[line] = cp.multiply(cp.multiply(self.sets.trade_data["line_inv_{}".format(self.sets.sizes[0])].loc[:,line].values ,
self.variables["line_newcapacity_lump"][self.sets.sizes[0]][line]),
Expand All @@ -681,19 +673,33 @@ def _calc_variable_planning_line(self):
self.variables["line_newcapacity_lump"][size][line]),
self.sets.trade_data["line_length"].loc[:,line].values)

self.salvage_inv_line[line] = cp.multiply(
salvage_factor_line(

if not self.sets.snapshot:
self.line_decommissioned_capacity[line] = line_decomcap(
self.line_newcapacity[line],
self.sets.trade_line[line],
self.sets.main_years,
carr_list,
self.sets.trade_data["line_lifetime"].loc[:, line],
self.sets.trade_data["interest_rate"].loc[:, line],
self.sets.global_data["global_discount_rate"],
self.sets.trade_data["line_economic_lifetime"].loc[:, line],
self.sets.period_step
),
self.cost_inv_line[line],
self.sets.period_step,
)


self.cost_decom_line[line] = cp.multiply(cp.multiply(
self.sets.trade_data["line_decom_cost"].loc[:, line].values,
self.line_decommissioned_capacity[line],
), self.sets.trade_data["line_length"].loc[:,line].values)

self.salvage_inv_line[line] = cp.multiply(
salvage_factor_line(
self.sets.main_years,
carr_list,
self.sets.trade_data["line_lifetime"].loc[:, line],
self.sets.trade_data["interest_rate"].loc[:, line],
self.sets.global_data["global_discount_rate"],
self.sets.trade_data["line_economic_lifetime"].loc[:, line],
self.sets.period_step
),
self.cost_inv_line[line],
)

self.cost_variable_line = line_varcost(
self.sets.trade_data["line_var_cost"],
Expand Down Expand Up @@ -1605,24 +1611,38 @@ def _set_regional_objective_planning(self):
# axis=1,
# )

totalcost_regional += cp.sum(
self.cost_inv_tax[reg][ctgry]
- self.cost_inv_sub[reg][ctgry]
+ self.cost_fix[reg][ctgry]
+ self.cost_fix_tax[reg][ctgry]
- self.cost_fix_sub[reg][ctgry]
+ self.cost_variable_annual[reg][ctgry]
+ self.cost_decom[reg][ctgry]
- self.salvage_inv[reg][ctgry],
axis=1,
)

if not self.sets.snapshot:

totalcost_regional += cp.sum(
self.cost_inv_tax[reg][ctgry]
- self.cost_inv_sub[reg][ctgry]
+ self.cost_fix[reg][ctgry]
+ self.cost_fix_tax[reg][ctgry]
- self.cost_fix_sub[reg][ctgry]
+ self.cost_variable_annual[reg][ctgry]
+ self.cost_decom[reg][ctgry]
- self.salvage_inv[reg][ctgry],
axis=1,
)


self.inv_allregions += self.cost_inv_fvalue[reg][ctgry]


else:

totalcost_regional += cp.sum(
self.cost_inv_tax[reg][ctgry]
- self.cost_inv_sub[reg][ctgry]
+ self.cost_fix[reg][ctgry]
+ self.cost_fix_tax[reg][ctgry]
- self.cost_fix_sub[reg][ctgry]
+ self.cost_variable_annual[reg][ctgry],

axis=1,
)

#total_salvage_regional += cp.sum(self.salvage_inv[reg][ctgry], axis =1)



self.inv_allregions += self.cost_inv_fvalue[reg][ctgry]

if ctgry != "Transmission" and ctgry != "Storage":

Expand Down Expand Up @@ -1688,16 +1708,25 @@ def _set_lines_objective_planning(self):
#self.total_salvage_line = np.zeros((len(self.sets.main_years), 1))

for line in self.sets.trade_line.keys():

self.totalcost_lines += cp.sum(
self.cost_inv_line[line]
+ self.cost_fix_line[line]
+ self.cost_decom_line[line]
- self.salvage_inv_line[line],
axis=1,
)


if not self.sets.snapshot:

self.totalcost_lines += cp.sum(
self.cost_inv_line[line]
+ self.cost_fix_line[line]
+ self.cost_decom_line[line]
- self.salvage_inv_line[line],
axis=1,
)

else:

self.totalcost_lines += cp.sum(
self.cost_inv_line[line]
+ self.cost_fix_line[line],
axis=1,
)

#self.total_salvage_line += cp.sum(self.salvage_inv_line[line],axis=1)

for reg_ in self.sets.trade_regions.keys():
Expand Down
3 changes: 2 additions & 1 deletion hypatia/backend/StrData.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ class ReadSets:
A nested dictionary for storing the regional data
"""

def __init__(self, path, mode="Planning", period_step = 1):
def __init__(self, path, mode="Planning", period_step = 1, snapshot=False):

self.mode = mode
self.path = path
self.period_step = period_step
self.snapshot = snapshot

self._init_by_xlsx()

Expand Down
2 changes: 1 addition & 1 deletion hypatia/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Model:
A Hypatia Model
"""

def __init__(self, path, mode, name="unknown", period_step=1):
def __init__(self, path, mode, name="unknown", period_step=1,snapshot=False):

"""Initializes a Hypatia model by passing the optimization mode and
the path of the structural input files
Expand Down
10 changes: 5 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@

#%%
test = Model(
path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/sets',
mode = 'Planning', period_step = 10)
path = 'test/Trilateral/tests/test_snapshot/dummy/sets',
mode = 'Planning', period_step = 1, snapshot=True)
#%%
#test.create_data_excels(path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/parameters')
test.create_data_excels(path = 'test/Trilateral/tests/test_snapshot/dummy/parameters')
#%%
test.read_input_data(
path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/parameters_new'
path = 'test/Trilateral/tests/test_snapshot/dummy/parameters'
)
#%%
test.resample_input_data(downsample=2)
#test.resample_input_data(downsample=2)
#%%
#import gurobipy

Expand Down

0 comments on commit f17ffb4

Please sign in to comment.