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/integrate stochastic programming #809

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/oemof/solph/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ def _add_parent_block_sets(self):
initialize=self.flows.keys(), ordered=True, dimen=2
)


self.FIRSTSTAGE_FLOWS = po.Set(
initialize=[
k
for (k, v) in self.flows.items()
if hasattr(v, "firststage")
],
ordered=True,
dimen=2,
within=self.FLOWS,
)


self.BIDIRECTIONAL_FLOWS = po.Set(
initialize=[
k
Expand Down
24 changes: 24 additions & 0 deletions src/oemof/solph/components/experimental/_ancillary_services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

"""
In-development component for ancillary services demand

SPDX-FileCopyrightText: Ekaterina Zolotarevskaia (e-zolotarevskaya)

SPDX-License-Identifier: MIT

"""
from oemof.solph.components._sink import Sink

class AncillaryServices(Sink):
"""
request
timeindex
price
"""
def __init__(self, request, timeindex, price):
self.request = request
self.timeindex = timeindex
self.price = price


89 changes: 66 additions & 23 deletions src/oemof/solph/flows/_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
from pyomo.core import NonNegativeIntegers
from pyomo.core import Set
from pyomo.core import Var
from pyomo.core import Expression
from pyomo.core import quicksum
from pyomo.core.base.block import SimpleBlock

from oemof.solph._plumbing import sequence
Expand Down Expand Up @@ -394,6 +396,18 @@ def _create(self, group=None):

# ######################### CONSTRAINTS ###############################

# def _fix_value_rule(model):
# """"""
# for inp, out in m.FIRSTSTAGE_FLOWS:
# for t in m.TIMESTEPS:
# self.fix_value_constr.add(
# (inp, out, t),
# m.flow[inp, out, t] ==
# m.flows[inp, out].fix[t] * m.flows[inp, out].nominal_value)
#
# self.fix_value_constr = Constraint(m.FIRSTSTAGE_FLOWS, m.TIMESTEPS, noruleinit=True)
# self.fix_value_build = BuildAction(rule=_fix_value_rule)

Comment on lines +399 to +410
Copy link
Member

Choose a reason for hiding this comment

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

This is obsolete..

def _flow_summed_max_rule(model):
"""Rule definition for build action of max. sum flow constraint."""
for inp, out in self.SUMMED_MAX_FLOWS:
Expand Down Expand Up @@ -480,30 +494,59 @@ def _objective_expression(self):
"""
m = self.parent_block()

variable_costs = 0
gradient_costs = 0
self.first_stage_variable_costs = quicksum(
m.flow[i, o, t]
* m.objective_weighting[t]
* m.flows[i, o].variable_costs[t]
for t in m.TIMESTEPS
for i, o in m.FIRSTSTAGE_FLOWS
if m.flows[i, o].variable_costs[0] is not None
)

for i, o in m.FLOWS:
if m.flows[i, o].variable_costs[0] is not None:
for t in m.TIMESTEPS:
variable_costs += (
m.flow[i, o, t]
* m.objective_weighting[t]
* m.flows[i, o].variable_costs[t]
)
self.variable_costs = quicksum(
m.flow[i, o, t]
* m.objective_weighting[t]
* m.flows[i, o].variable_costs[t]
for t in m.TIMESTEPS
for i, o in m.FLOWS
if m.flows[i, o].variable_costs[0] is not None
)

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

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

return variable_costs + gradient_costs
self.first_stage_gradient_costs += quicksum(
self.negative_gradient[i, o, t]
* m.flows[i, o].positive_gradient["costs"]
for t in m.TIMESTEPS
for (i, o) in m.FIRSTSTAGE_FLOWS
if m.flows[i, o].negative_gradient["ub"][0] is not None
)

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

return (
self.variable_costs
+ self.first_stage_variable_costs
+ self.gradient_costs
+ self.first_stage_gradient_costs
)