Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def describe_lower_dispatch_constraints(n):
description = {}
key = ' Lower Limit'
for c, attr in nominal_attrs.items():
if c in ['Line', 'Transformer', 'Link']:
dispatch_attr = 'p0'
description[c] = pd.Series({'min':
(n.df(c)[attr + '_opt'] *
get_as_dense(n, c, attr[0] + '_max_pu') +
n.pnl(c)[dispatch_attr]).min().min()})
else:
dispatch_attr = attr[0]
description[c + key] = pd.Series({'min':
(-n.df(c)[attr + '_opt'] *
get_as_dense(n, c, attr[0] + '_min_pu') +
n.pnl(c)[dispatch_attr]).min().min()})
return pd.concat(description, axis=1)
constant = 0
for c, attr in nom_attr:
ext_i = get_extendable_i(n, c)
constant += n.df(c)[attr][ext_i] @ n.df(c).capital_cost[ext_i]
object_const = write_bound(n, constant, constant)
n.objective_f.write(linexpr((-1, object_const), as_pandas=False)[0])
for c, attr in lookup.query('marginal_cost').index:
cost = (get_as_dense(n, c, 'marginal_cost', sns)
.loc[:, lambda ds: (ds != 0).all()]
.mul(n.snapshot_weightings[sns], axis=0))
if cost.empty: continue
terms = linexpr((cost, get_var(n, c, attr).loc[sns, cost.columns]))
n.objective_f.write(join_exprs(terms))
# investment
for c, attr in nominal_attrs.items():
cost = n.df(c)['capital_cost'][get_extendable_i(n, c)]
if cost.empty: continue
terms = linexpr((cost, get_var(n, c, attr)[cost.index]))
n.objective_f.write(join_exprs(terms))
def describe_upper_dispatch_constraints(n):
'''
Recalculates the minimum gap between operational status and nominal capacity
'''
description = {}
key = ' Upper Limit'
for c, attr in nominal_attrs.items():
dispatch_attr = 'p0' if c in ['Line', 'Transformer', 'Link'] else attr[0]
description[c + key] = pd.Series({'min':
(n.df(c)[attr + '_opt'] *
get_as_dense(n, c, attr[0] + '_max_pu') -
n.pnl(c)[dispatch_attr]).min().min()})
return pd.concat(description, axis=1)
def define_objective(n, sns):
"""
Defines and writes out the objective function
"""
# constant for already done investment
nom_attr = nominal_attrs.items()
constant = 0
for c, attr in nom_attr:
ext_i = get_extendable_i(n, c)
constant += n.df(c)[attr][ext_i] @ n.df(c).capital_cost[ext_i]
object_const = write_bound(n, constant, constant)
n.objective_f.write(linexpr((-1, object_const), as_pandas=False)[0])
for c, attr in lookup.query('marginal_cost').index:
cost = (get_as_dense(n, c, 'marginal_cost', sns)
.loc[:, lambda ds: (ds != 0).all()]
.mul(n.snapshot_weightings[sns], axis=0))
if cost.empty: continue
terms = linexpr((cost, get_var(n, c, attr).loc[sns, cost.columns]))
n.objective_f.write(join_exprs(terms))
# investment
for c, attr in nominal_attrs.items():