Skip to content

Commit

Permalink
Added:
Browse files Browse the repository at this point in the history
- Added mathematical notations to the constraint module.

Fixed:

- Fixed the format of the API reference.
  • Loading branch information
github-actions[bot] committed Jul 22, 2024
1 parent b9b54bb commit 079ed17
Show file tree
Hide file tree
Showing 18 changed files with 833 additions and 587 deletions.
13 changes: 12 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,29 @@ class MyReferenceStyle(AuthorYearReferenceStyle):
# Sphinx extension module names and templates location
sys.path.append(os.path.abspath("_extensions"))
extensions = [
"sphinx.ext.autodoc",
"sphinx_tabs.tabs",
"notfound.extension",
"sphinxext.opengraph",
"sphinx.ext.todo",
"sphinx.ext.ifconfig",
"sphinx.ext.mathjax",
"sphinxcontrib.bibtex",
"sphinx.ext.autodoc",
"sphinx_copybutton",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
]

autodoc_typehints = 'description'

# Specify the path to your BibTeX file
bibtex_bibfiles = ['references.bib']

# Enable Napoleon Google style docstrings
# napoleon_google_docstring = True
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = True

# Warning when the Sphinx Tabs extension is used with unknown
# builders (like the dummy builder) - as it doesn't cause errors,
# we can ignore this so we still can treat other warnings as errors.
Expand Down
71 changes: 33 additions & 38 deletions prepshot/_model/co2.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""This module contains constraints related to carbon emissions.
"""
"""This module contains the constraints and expressions related to
carbon emissions. The model computes the carbon emissions for each year,
based on the sum of carbon emissions from each zone, and from each technology
as follows:
.. math::
{\\rm{carbon}}_y=\\sum_{e\\in\\mathcal{E}}\\sum_{z\\in\mathcal{Z}}
\\sum_{m\\in\mathcal{M}}\\sum_{h\\in\mathcal{H}}
\\left({{\\rm{CARBON}}}_{y,z,e}\\times
{\\rm{gen}}_{h,m,y,z,e}\\right)\\quad\\forall y
from typing import Union
The calculated carbon emission for each year lower than its upper bound, as follows:
.. math::
{\\rm{carbon}}_y\\le{\\overline{{\\rm{CARBON}}}}_y\\quad\\forall y
"""
import pyoptinterface as poi
import numpy as np

class AddCo2EmissionConstraints:
"""Class for carbon emission constraints and calculations.
"""
def __init__(self,
model : Union[
poi._src.highs.Model,
poi._src.gurobi.Model,
poi._src.mosek.Model,
poi._src.copt.Model
],
) -> None:
def __init__(self, model : object) -> None:
"""Initialize the class.
Parameters
----------
model : Union[
poi._src.highs.Model,
poi._src.gurobi.Model,
poi._src.mosek.Model,
poi._src.copt.Model
]
model : object
Model object depending on the solver.
"""
self.model = model
model.carbon_breakdown = poi.make_tupledict(
Expand All @@ -50,10 +53,7 @@ def __init__(self,
rule=self.emission_limit_rule
)

def emission_limit_rule(
self,
y : int
) -> poi._src.core_ext.ConstraintIndex:
def emission_limit_rule(self, y : int) -> poi.ConstraintIndex:
"""Annual carbon emission limits across all zones and technologies.
Parameters
Expand All @@ -63,8 +63,8 @@ def emission_limit_rule(
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
poi.ConstraintIndex
A constraint of the model.
"""
model = self.model
limit = model.params['carbon_emission_limit']
Expand All @@ -73,10 +73,7 @@ def emission_limit_rule(
lhs = model.carbon[y] - limit[y]
return model.add_linear_constraint(lhs, poi.Leq, 0)

def emission_calc_rule(
self,
y : int
) -> poi._src.core_ext.ConstraintIndex:
def emission_calc_rule(self, y : int) -> poi.ConstraintIndex:
"""Calculation of annual carbon emission across all zones and
technologies.
Expand All @@ -87,8 +84,8 @@ def emission_calc_rule(
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
poi.ConstraintIndex
A constraint of the model.
"""
model = self.model
return poi.quicksum(
Expand All @@ -97,10 +94,8 @@ def emission_calc_rule(
)

def emission_calc_by_zone_rule(
self,
y : int,
z : str
) -> poi._src.core_ext.ConstraintIndex:
self, y : int, z : str
) -> poi.ConstraintIndex:
"""Calculation of annual carbon emissions by zone.
Parameters
Expand All @@ -112,8 +107,8 @@ def emission_calc_by_zone_rule(
Returns
-------
pyoptinterface._src.core_ext.ConstraintIndex
Constraint index of the model.
poi.ConstraintIndex
A constraint of the model.
"""
model = self.model
return poi.quicksum(
Expand All @@ -126,7 +121,7 @@ def carbon_breakdown(
y : int,
z : str,
te : str
) -> poi._src.core_ext.ExprBuilder:
) -> poi.ExprBuilder:
"""Carbon emission cost breakdown.
Parameters
Expand All @@ -140,8 +135,8 @@ def carbon_breakdown(
Returns
-------
pyoptinterface._src.core_ext.ExprBuilder
index of expression of the model.
poi.ExprBuilder
The expression of the model.
"""
model = self.model
ef = model.params['emission_factor'][te, y]
Expand Down
Loading

0 comments on commit 079ed17

Please sign in to comment.