-
Notifications
You must be signed in to change notification settings - Fork 88
/
ramping.py
51 lines (40 loc) · 1.58 KB
/
ramping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Copyright (C) 2013 Stefan Pfenninger.
Licensed under the Apache 2.0 License (see LICENSE file).
ramping.py
~~~~~~~~~~
Ramping constraints.
"""
from __future__ import print_function
from __future__ import division
import coopr.pyomo as cp
def ramping_rate(model):
"""Depends on: node_energy_balance, node_constraints_build"""
m = model.m
# Constraint rules
def _ramping_rule(m, y, x, t, direction):
try:
# e_ramping: Ramping rate [fraction of installed capacity per hour]
ramping_rate = model.get_option(y + '.constraints.e_ramping')
except KeyError:
# If the technology defines no `e_ramping`, we don't build a
# ramping constraint for it!
return cp.Constraint.NoConstraint
# If there was no KeyError, we build and return a constraint
if m.t.order_dict[t] <= 1:
return cp.Constraint.NoConstraint
else:
carrier = model.get_option(y + '.carrier')
diff = m.e[carrier, y, x, t] - m.e[carrier, y, x, model.prev(t)]
max_ramping_rate = ramping_rate * m.time_res[t] * m.e_cap[y, x]
if direction == 'up':
return diff <= max_ramping_rate
else:
return -1 * max_ramping_rate <= diff
def c_ramping_up_rule(m, y, x, t):
return _ramping_rule(m, y, x, t, direction='up')
def c_ramping_down_rule(m, y, x, t):
return _ramping_rule(m, y, x, t, direction='down')
# Constraints
m.c_ramping_up = cp.Constraint(m.y, m.x, m.t)
m.c_ramping_down = cp.Constraint(m.y, m.x, m.t)