Skip to content
Snippets Groups Projects
Commit bc6335c7 authored by Pedro L. Magalhães's avatar Pedro L. Magalhães
Browse files

Applied black.

parent f7d386ca
No related branches found
No related tags found
1 merge request!5Revised ResourcePrice class and methods. Added tests for problem...
Showing
with 18590 additions and 20274 deletions
......@@ -29,10 +29,12 @@ from .signal import Signal, FixedSignal
# TODO: create constant terms using fixed signals
class Converter:
"""A class for modular dynamic systems in an integrated energy system."""
def __init__(self,
def __init__(
self,
# converter name/key
key,
# system information
......@@ -57,9 +59,8 @@ class Converter:
# externalities due
input_specific_externality_costs: dict = None, # one for every input
output_specific_externality_costs: dict = None, # one for every input, then another for every time interval
state_specific_externality_costs: dict = None # one for every output, then another for every time interval
state_specific_externality_costs: dict = None, # one for every output, then another for every time interval
):
# *********************************************************************
self.key = key
......@@ -71,45 +72,35 @@ class Converter:
# inputs
if type(inputs) == list:
self.inputs = inputs
elif isinstance(inputs, Signal):
self.inputs = [inputs]
else:
raise TypeError('Unknown format for input signals.')
raise TypeError("Unknown format for input signals.")
# outputs
if type(outputs) == list:
self.outputs = outputs
elif isinstance(outputs, Signal):
self.outputs = [outputs]
else:
raise TypeError('Unknown format for output signals.')
raise TypeError("Unknown format for output signals.")
# states
if type(states) == list:
self.states = states
elif isinstance(states, Signal):
self.states = [states]
else:
raise TypeError('Unknown format for state signals.')
raise TypeError("Unknown format for state signals.")
self.initial_states = initial_states
......@@ -129,17 +120,11 @@ class Converter:
# externality costs: one per signal and time interval
self.input_specific_externality_costs = (
input_specific_externality_costs
)
self.input_specific_externality_costs = input_specific_externality_costs
self.state_specific_externality_costs = (
state_specific_externality_costs
)
self.state_specific_externality_costs = state_specific_externality_costs
self.output_specific_externality_costs = (
output_specific_externality_costs
)
self.output_specific_externality_costs = output_specific_externality_costs
# *********************************************************************
# *********************************************************************
......@@ -149,11 +134,9 @@ class Converter:
# inputs
if type(self.input_specific_amplitude_costs) == type(None):
self.amplitude_penalised_inputs = None
else:
self.amplitude_penalised_inputs = list(
self.input_specific_amplitude_costs.keys()
)
......@@ -161,11 +144,9 @@ class Converter:
# states
if type(self.state_specific_amplitude_costs) == type(None):
self.amplitude_penalised_states = None
else:
self.amplitude_penalised_states = list(
self.state_specific_amplitude_costs.keys()
)
......@@ -173,11 +154,9 @@ class Converter:
# outputs
if type(self.output_specific_amplitude_costs) == type(None):
self.amplitude_penalised_outputs = None
else:
self.amplitude_penalised_outputs = list(
self.output_specific_amplitude_costs.keys()
)
......@@ -190,11 +169,9 @@ class Converter:
# inputs
if type(self.input_specific_externality_costs) == type(None):
self.externality_inducing_inputs = []
else:
self.externality_inducing_inputs = [
key[0] # key is a (m, k) tuple
for key, value in self.input_specific_externality_costs.items()
......@@ -204,11 +181,9 @@ class Converter:
# states
if type(self.state_specific_externality_costs) == type(None):
self.externality_inducing_states = []
else:
self.externality_inducing_states = [
key[0] # key is a (n, k) tuple
for key, value in self.state_specific_externality_costs.items()
......@@ -218,11 +193,9 @@ class Converter:
# outputs
if type(self.output_specific_externality_costs) == type(None):
self.externality_inducing_outputs = []
else:
self.externality_inducing_outputs = [
key[0] # key is a (r, k) tuple
for key, value in self.output_specific_externality_costs.items()
......@@ -257,10 +230,7 @@ class Converter:
@staticmethod
def identify_fixed_signals(signals: list):
return [
u for u, sig in enumerate(signals) if isinstance(sig, FixedSignal)
]
return [u for u, sig in enumerate(signals) if isinstance(sig, FixedSignal)]
# *************************************************************************
# *************************************************************************
......@@ -270,7 +240,6 @@ class Converter:
# TODO: replace the use of the number of time intervals from signals' objects
def matrix_dictionaries(self) -> tuple:
# TODO: exclude fixed signals from the matrices
# how? skip fixed signals = the dicts do not have that information and the indexes will be correct
......@@ -280,7 +249,8 @@ class Converter:
a_innk = {
(self.key, n1, n2, k): self.sys.A_line_k[
k if self.sys.A_line_is_time_varying else 0][n1, n2]
k if self.sys.A_line_is_time_varying else 0
][n1, n2]
for n1 in range(self.sys.number_states) # the state being defined
for n2 in range(self.sys.number_states) # the influencing state
for k in range(number_intervals) # the time interval
......@@ -290,7 +260,8 @@ class Converter:
b_inmk = {
(self.key, n1, m, k): self.sys.B_line_k[
k if self.sys.B_line_is_time_varying else 0][n1, m]
k if self.sys.B_line_is_time_varying else 0
][n1, m]
for n1 in range(self.sys.number_states) # the state being defined
for m in range(self.sys.number_inputs) # the influencing input
if m not in self.fixed_inputs # free inputs only
......@@ -301,7 +272,8 @@ class Converter:
c_irnk = {
(self.key, r, n, k): self.sys.C_line_k[
k if self.sys.C_line_is_time_varying else 0][r, n]
k if self.sys.C_line_is_time_varying else 0
][r, n]
for r in range(self.sys.number_outputs) # the output being defined
for n in range(self.sys.number_states) # the influencing state
for k in range(number_intervals) # the time interval
......@@ -311,7 +283,8 @@ class Converter:
d_irmk = {
(self.key, r, m, k): self.sys.D_line_k[
k if self.sys.D_line_is_time_varying else 0][r, m]
k if self.sys.D_line_is_time_varying else 0
][r, m]
for r in range(self.sys.number_outputs) # the output being defined
for m in range(self.sys.number_inputs) # the influencing input
if m not in self.fixed_inputs # free inputs only
......@@ -324,11 +297,9 @@ class Converter:
# e_x_ink: depends on fixed signals
e_x_ink = {
(self.key,n,k):
sum(
self.sys.B_line_k[
k if self.sys.B_line_is_time_varying else 0][n,m]*
self.inputs[m].samples[k]
(self.key, n, k): sum(
self.sys.B_line_k[k if self.sys.B_line_is_time_varying else 0][n, m]
* self.inputs[m].samples[k]
for m in self.fixed_inputs # b_inmk*u_imk for fixed inputs
)
for n in range(self.sys.number_states) # the state being defined
......@@ -339,9 +310,8 @@ class Converter:
e_y_irk = {
(self.key, r, k): sum(
self.sys.D_line_k[
k if self.sys.D_line_is_time_varying else 0][r,m]*
self.inputs[m].samples[k]
self.sys.D_line_k[k if self.sys.D_line_is_time_varying else 0][r, m]
* self.inputs[m].samples[k]
for m in self.fixed_inputs # d_irmk*u_imk for fixed inputs
)
for r in range(self.sys.number_outputs) # the output being defined
......@@ -352,6 +322,7 @@ class Converter:
return a_innk, b_inmk, c_irnk, d_irmk, e_x_ink, e_y_irk
# # *************************************************************************
# # *************************************************************************
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -15,8 +15,8 @@ from examples_signal import examples as examples_signal
# test with: !python -m pytest -s --cov --cov-report term-missing
def test_suite():
def test_suite():
test_examples_dynsys = True
# test_examples_dynsys = False
......@@ -42,7 +42,7 @@ def test_suite():
# **************************************************************************
solver = 'scip'
solver = "scip"
# scip_exec_path = '/usr/bin/scip'
# solver_options = {'executable': scip_exec_path}
solver_options = {}
......@@ -54,17 +54,17 @@ def test_suite():
# solver_options = {'executable':cplex_exec_path}
list_solvers = [
'fake_solver',
'cbc',
'glpk',
'scip',
"fake_solver",
"cbc",
"glpk",
"scip",
#'cplex'
]
list_solver_options = [
None, # fake
None, # cbc
{'tee': False}, # glpk
{"tee": False}, # glpk
None, # scip
# cplex
# {'executable': cplex_exec_path},
......@@ -76,14 +76,14 @@ def test_suite():
# seed_number = 13501
print('Seed number: ' + str(seed_number))
print("Seed number: " + str(seed_number))
# **************************************************************************
# load pipe data
singlepipedata_files = [
'tests/data/isoplus_singlepipes_s1.csv',
"tests/data/isoplus_singlepipes_s1.csv",
]
singlepipedb = StandardisedPipeDatabase(source=singlepipedata_files)
......@@ -91,7 +91,7 @@ def test_suite():
# twin pipe data files
twinpipedata_files = [
'tests/data/isoplus_twinpipes_s1.csv',
"tests/data/isoplus_twinpipes_s1.csv",
]
twinpipedb = StandardisedPipeDatabase(source=twinpipedata_files)
......@@ -102,11 +102,9 @@ def test_suite():
# get water properties' database
waterdata_file = 'tests/data/incropera2006_saturated_water.csv'
waterdata_file = "tests/data/incropera2006_saturated_water.csv"
water_db = FluidDatabase(fluid='fluid',
phase='l',
source=waterdata_file)
water_db = FluidDatabase(fluid="fluid", phase="l", source=waterdata_file)
# # get oil properties' database
......@@ -132,65 +130,52 @@ def test_suite():
# esipp-network
if test_examples_esipp_network:
print('\'esipp-network\': testing about to start...')
print("'esipp-network': testing about to start...")
examples_esipp_network()
print('\'esipp-network\': testing complete.')
print("'esipp-network': testing complete.")
# **************************************************************************
# esipp-problem
if test_examples_esipp_problem:
print("'esipp-problem': testing about to start...")
print('\'esipp-problem\': testing about to start...')
examples_esipp_problem(solver,
solver_options,
init_aux_sets=False)
examples_esipp_problem(solver, solver_options, init_aux_sets=False)
examples_esipp_problem(solver,
solver_options,
init_aux_sets=True)
examples_esipp_problem(solver, solver_options, init_aux_sets=True)
print('\'esipp-problem\': testing complete.')
print("'esipp-problem': testing complete.")
# **************************************************************************
# esipp
if test_examples_esipp:
print("'esipp': testing about to start...")
print('\'esipp\': testing about to start...')
examples_esipp(solver, solver_options, seed_number, init_aux_sets=False)
examples_esipp(solver,
solver_options,
seed_number,
init_aux_sets=False)
examples_esipp(solver, solver_options, seed_number, init_aux_sets=True)
examples_esipp(solver,
solver_options,
seed_number,
init_aux_sets=True)
print('\'esipp-problem\': testing complete.')
print("'esipp-problem': testing complete.")
# **************************************************************************
# signal
if test_examples_signal:
print('\'signal\': testing about to start...')
print("'signal': testing about to start...")
examples_signal()
print('\'signal\': testing: testing complete.')
print("'signal': testing: testing complete.")
# **************************************************************************
# **************************************************************************
# ******************************************************************************
# ******************************************************************************
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment