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

Features/Multiobjective Optimization #756

Draft
wants to merge 24 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
24295b4
Update __init__.py
lensum Mar 25, 2021
6cff1c7
Create multiobjective_flow.py
lensum Mar 25, 2021
bfe602e
Update groupings.py
lensum Mar 25, 2021
0b2147b
Update models.py
lensum Mar 25, 2021
7f62a16
Update flow.py
lensum Mar 25, 2021
22fe531
Update options.py
lensum Mar 25, 2021
5cee604
test_model.py, test_model_solve.py und test_multiobjective.py aktuali…
lensum Mar 25, 2021
59fdb49
updated __init__.py in solph and blocks to contain new multiobjective…
lensum Mar 25, 2021
c3dfdcf
fixed missing package import in models.py
lensum Mar 25, 2021
794b83d
dependency of MultiObjectiveModel changed from BaseModel to Model to …
lensum Apr 26, 2021
ce21ef0
added authors and changelog
lensum Apr 27, 2021
ff1073d
enhanced PEP8 conformity
lensum Apr 27, 2021
54e6816
Revert "added authors and changelog"
lensum Apr 29, 2021
5fb6f02
corrected linting errors
lensum Apr 29, 2021
18b4a3d
further linting errors removed
lensum Apr 29, 2021
9606708
Fixed linting error in test script
west-a Apr 29, 2021
4c7e799
Fixed further oversight in style
west-a Apr 29, 2021
1fd6421
Several fixes to import order/documentation
west-a Apr 30, 2021
a912107
Fixed indentation typo
west-a Apr 30, 2021
241530e
Corrected import sorting
west-a Apr 30, 2021
38891c8
fixed import order
west-a Apr 30, 2021
e2ac551
Resolved merge conflict in network/flow.py by incorporating both sugg…
lensum Jun 14, 2021
95da9e5
Fixed wrong parenthesis
west-a Jun 30, 2021
17ead41
WIP: added function to find pareto frontier
west-a Jul 8, 2021
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
2 changes: 2 additions & 0 deletions src/oemof/solph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
from .components import OffsetTransformer # noqa: F401
from .groupings import GROUPINGS # noqa: F401
from .models import Model # noqa: F401
from .models import MultiObjectiveModel # noqa: F401
from .network import Bus # noqa: F401
from .network import EnergySystem # noqa: F401
from .network import Flow # noqa: F401
from .network import Sink # noqa: F401
from .network import Source # noqa: F401
from .network import Transformer # noqa: F401
from .options import Investment # noqa: F401
from .options import MultiObjective # noqa: F401
from .options import NonConvex # noqa: F401
from .plumbing import sequence # noqa: F401
from .processing import parameter_as_dict # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions src/oemof/solph/blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
from .bus import Bus # noqa: F401
from .flow import Flow # noqa: F401
from .investment_flow import InvestmentFlow # noqa: F401
from .multiobjective_flow import MultiObjectiveFlow # noqa: F401
from .non_convex_flow import NonConvexFlow # noqa: F401
from .transformer import Transformer # noqa: F401
92 changes: 92 additions & 0 deletions src/oemof/solph/blocks/multiobjective_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# -*- coding: utf-8 -*-

"""Creating sets, variables, constraints and parts of the objective function
for MultiObjectiveFlow objects.
"""

from collections import defaultdict

from pyomo.core import Set
from pyomo.core.base.block import SimpleBlock


class MultiObjectiveFlow(SimpleBlock):
r""" Block for all flows with :attr:`multiobjective` being not None.

Adds no additional variables or constraints. Used solely to add index set
and objective expressions.

**The following sets are created:** (-> see basic sets at :class:`.Model` )

MULTIOBJECTIVEFLOWS
A set of flows with the attribute :attr:`multiobjective` of type
:class:`.options.MultiObjective`.

**The following parts of the objective function are created:**

If :attr:`variable_costs` are set by the user:
.. math::
\sum_{(i,o)} \sum_t flow(i, o, t) \cdot variable\_costs(e, i, o, t)

\forall e \in \{set\ of\ objective\ functions\}

Specific objectives are created in the same manner as for :class:`Flow`.

"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

def _create(self, group=None):
r"""Creates sets, variables and constraints for all standard flows.

Parameters
----------
group : list
List containing tuples containing flow (f) objects and the
associated source (s) and target (t)
of flow e.g. groups=[(s1, t1, f1), (s2, t2, f2),..]
"""
if group is None:
return None

# ########################## SETS #################################
self.MULTIOBJECTIVEFLOWS = Set(
initialize=[(g[0], g[1]) for g in group])

def _objective_expression(self):
r"""Objective expression for all multiobjective flows with fixed costs
and variable costs.
"""
if not hasattr(self, "MULTIOBJECTIVEFLOWS"):
return 0
m = self.parent_block()

mo_costs = defaultdict(lambda: 0, {'_standard': 0})

for i, o in self.MULTIOBJECTIVEFLOWS:
for mo_key, mo_param in m.flows[i, o].multiobjective.items():
variable_costs = 0
gradient_costs = 0
if mo_param.variable_costs[0] is not None:
for t in m.TIMESTEPS:
variable_costs += (
m.flow[i, o, t]
* m.objective_weighting[t]
* mo_param.variable_costs[t])

if mo_param.positive_gradient["ub"][0] is not None:
for t in m.TIMESTEPS:
gradient_costs += (
self.positive_gradient[i, o, t]
* mo_param.positive_gradient["costs"])

if mo_param.negative_gradient["ub"][0] is not None:
for t in m.TIMESTEPS:
gradient_costs += (
self.negative_gradient[i, o, t]
* mo_param.negative_gradient["costs"])

mo_costs[mo_key] += variable_costs + gradient_costs

return mo_costs
15 changes: 15 additions & 0 deletions src/oemof/solph/groupings.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,24 @@ def _nonconvex_grouping(stf):
)


def _multiobjective_grouping(stf):
if hasattr(stf[2], "multiobjective"):
if stf[2].multiobjective is not None:
return True
else:
return False


multiobjective_flow_grouping = groupings.FlowsWithNodes(
constant_key=blocks.MultiObjectiveFlow,
filter=_multiobjective_grouping
)


GROUPINGS = [
constraint_grouping,
investment_flow_grouping,
standard_flow_grouping,
nonconvex_flow_grouping,
multiobjective_flow_grouping,
]
Loading