Skip to content

Commit

Permalink
Merge pull request #25 from PREP-NexT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Zhanwei-Liu authored Jul 10, 2024
2 parents 7332ce2 + 492cb9e commit ae3a783
Show file tree
Hide file tree
Showing 21 changed files with 2,472 additions and 2,271 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This section includes a brief tutorial on running your first PREP-SHOT model.

This example is inspired by real-world data. For a detailed elaboration of this tutorial, check out the [Tutorial Page](https://prep-next.github.io/PREP-SHOT/Tutorial.html) in our documentation.

By default, PREP-SHOT uses open-source freely ``HIGHS`` solver. Solver-specific settings parameters are specified in the ``config.json`` file, which should be located in the current working directory. We also provide the option to use one of these three commercial solvers:
By default, PREP-SHOT uses open-source freely [HiGHS](https://github.com/jump-dev/HiGHS.jl) solver. Solver-specific settings parameters are specified in the ``config.json`` file, which should be located in the current working directory. We also provide the option to use one of these three commercial solvers:

+ [Gurobi](https://www.gurobi.com/)
+ [COPT](https://www.copt.de/)
Expand Down
125 changes: 125 additions & 0 deletions prepshot/_model/co2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

""" This module contains constraints related to carbon emissions.
"""

import pyoptinterface as poi
import numpy as np

class AddCo2EmissionConstraints:
"""Class for carbon emission constraints and calculations.
"""
def __init__(self, model):
"""Initialize the class.
Parameters
----------
model : pyoptinterface._src.solver.Model
Model index.
para : dict
Dictionary containing parameters.
"""
self.model = model
model.carbon_breakdown = poi.make_tupledict(
model.year_zone_tech_tuples,
rule=self.carbon_breakdown
)
model.carbon_capacity = poi.make_tupledict(
model.year_zone_tuples,
rule=self.emission_calc_by_zone_rule
)
model.carbon = poi.make_tupledict(
model.year,
rule=self.emission_calc_rule
)
model.emission_limit_cons = poi.make_tupledict(
model.year,
rule=self.emission_limit_rule
)

def emission_limit_rule(self, y):
"""Annual carbon emission limits across all zones and technologies.
Parameters
----------
y : int
Planned year.
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
"""
model = self.model
limit = model.para['carbon_emission_limit']
if limit[y] == np.Inf:
return None
lhs = model.carbon[y] - limit[y]
return model.add_linear_constraint(lhs, poi.Leq, 0)

def emission_calc_rule(self, y):
"""Calculation of annual carbon emission across all zones and
technologies.
Parameters
----------
y : int
Planned year.
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
"""
model = self.model
return poi.quicksum(
model.carbon_capacity[y, z]
for z in model.zone
)

def emission_calc_by_zone_rule(self, y, z):
"""Calculation of annual carbon emissions by zone.
Parameters
----------
y : int
Planned year.
z : str
Zone.
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
"""
model = self.model
return poi.quicksum(
model.carbon_breakdown[y, z, te]
for te in model.tech
)

def carbon_breakdown(self, y, z, te):
"""Carbon emission cost breakdown.
Parameters
----------
y : int
Year.
z : str
Zone.
te : str
Technology.
Returns
-------
pyoptinterface._src.core_ext.ExprBuilder
index of expression of the model.
"""
model = self.model
ef = model.para['emission_factor'][te, y]
dt = model.para['dt']
return poi.quicksum(
ef * model.gen[h, m, y, z, te] * dt
for h, m in model.hour_month_tuples
)
Loading

0 comments on commit ae3a783

Please sign in to comment.