diff --git a/docs/model_library/strategic_water_management/index.rst b/docs/model_library/strategic_water_management/index.rst index 1af21657..005ac9ca 100644 --- a/docs/model_library/strategic_water_management/index.rst +++ b/docs/model_library/strategic_water_management/index.rst @@ -120,6 +120,8 @@ Strategic Model Mathematical Notation :math:`\textcolor{blue}{(r,s) \in RSA}` Treatment-to-storage pipeline arcs +:math:`\textcolor{blue}{(r,o) \in ROA}` Treatment-to-reuse pipeline arcs + :math:`\textcolor{blue}{(s,n) \in SNA}` Storage-to-node pipeline arcs :math:`\textcolor{blue}{(s,p) \in SCA}` Storage-to-completions pipeline arcs @@ -156,8 +158,14 @@ Strategic Model Mathematical Notation :math:`\textcolor{blue}{(s,k) \in SKT}` Storage-to-disposal trucking arcs +:math:`\textcolor{blue}{(s,o) \in SOT}` Storage-to-reuse trucking arcs + :math:`\textcolor{blue}{(r,k) \in RKT}` Treatment-to-disposal trucking arcs +:math:`\textcolor{blue}{(r,s) \in RST}` Treatment-to-storage trucking arcs + +:math:`\textcolor{blue}{(r,o) \in ROT}` Treatment-to-reuse trucking arcs + :math:`\textcolor{blue}{(l,\tilde{l}) \in LLT}` All valid trucking arcs diff --git a/pareto/operational_water_management/operational_produced_water_optimization_model.py b/pareto/operational_water_management/operational_produced_water_optimization_model.py index d9a28d9f..ff581851 100644 --- a/pareto/operational_water_management/operational_produced_water_optimization_model.py +++ b/pareto/operational_water_management/operational_produced_water_optimization_model.py @@ -33,7 +33,7 @@ from enum import Enum from pareto.utilities.units_support import units_setup -from pareto.utilities.build_utils import define_sets +from pareto.utilities.build_utils import build_sets, build_params class ProdTank(Enum): @@ -111,241 +111,11 @@ def create_model(df_sets, df_parameters, default={}): model.proprietary_data = df_parameters["proprietary_data"][0] - # Define sets # - define_sets(model) + # Build sets # + build_sets(model) - # Define model parameters # - model.p_PCA = Param( - model.s_PP, - model.s_CP, - default=0, - initialize={}, - doc="Valid production-to-completions pipeline arcs [-]", - ) - model.p_PNA = Param( - model.s_PP, - model.s_N, - default=0, - initialize={}, - doc="Valid production-to-node pipeline arcs [-]", - ) - model.p_PPA = Param( - model.s_PP, - model.s_PP, - default=0, - initialize={}, - doc="Valid production-to-production pipeline arcs [-]", - ) - model.p_CNA = Param( - model.s_CP, - model.s_N, - default=0, - initialize={}, - doc="Valid completion-to-node pipeline arcs [-]", - ) - model.p_CCA = Param( - model.s_CP, - model.s_CP, - default=0, - initialize={}, - doc="Valid completion-to-completion pipeline arcs [-]", - ) - model.p_NNA = Param( - model.s_N, - model.s_N, - default=0, - initialize={}, - doc="Valid node-to-node pipeline arcs [-]", - ) - model.p_NCA = Param( - model.s_N, - model.s_CP, - default=0, - initialize={}, - doc="Valid node-to-completions pipeline arcs [-]", - ) - model.p_NKA = Param( - model.s_N, - model.s_K, - default=0, - initialize={}, - doc="Valid node-to-disposal pipeline arcs [-]", - ) - model.p_NSA = Param( - model.s_N, - model.s_S, - default=0, - initialize={}, - doc="Valid node-to-storage pipeline arcs [-]", - ) - model.p_NRA = Param( - model.s_N, - model.s_R, - default=0, - initialize={}, - doc="Valid node-to-treatment pipeline arcs [-]", - ) - model.p_NOA = Param( - model.s_N, - model.s_O, - default=0, - initialize={}, - doc="Valid node-to-reuse pipeline arcs [-]", - ) - model.p_RCA = Param( - model.s_R, - model.s_CP, - default=0, - initialize=df_parameters["RCA"], - doc="Valid treatment-to-completions pipeline arcs [-]", - ) - model.p_FCA = Param( - model.s_F, - model.s_CP, - default=0, - initialize=df_parameters["FCA"], - doc="Valid externally sourced water-to-completions pipeline arcs [-]", - ) - model.p_RNA = Param( - model.s_R, - model.s_N, - default=0, - initialize={}, - doc="Valid treatment-to-node pipeline arcs [-]", - ) - model.p_RKA = Param( - model.s_R, - model.s_K, - default=0, - initialize={}, - doc="Valid treatment-to-disposal pipeline arcs [-]", - ) - model.p_SNA = Param( - model.s_S, - model.s_N, - default=0, - initialize={}, - doc="Valid storage-to-node pipeline arcs [-]", - ) - model.p_SCA = Param( - model.s_S, - model.s_CP, - default=0, - initialize={}, - doc="Valid storage-to-completions pipeline arcs [-]", - ) - model.p_SKA = Param( - model.s_S, - model.s_K, - default=0, - initialize={}, - doc="Valid storage-to-disposal pipeline arcs [-]", - ) - model.p_SRA = Param( - model.s_S, - model.s_R, - default=0, - initialize={}, - doc="Valid storage-to-treatment pipeline arcs [-]", - ) - model.p_SOA = Param( - model.s_S, - model.s_O, - default=0, - initialize={}, - doc="Valid storage-to-reuse pipeline arcs [-]", - ) - model.p_PCT = Param( - model.s_PP, - model.s_CP, - default=0, - initialize=df_parameters["PCT"], - doc="Valid production-to-completions trucking arcs [-]", - ) - model.p_FCT = Param( - model.s_F, - model.s_CP, - default=0, - initialize=df_parameters["FCT"], - doc="Valid externally sourced water-to-completions trucking arcs [-]", - ) - model.p_PKT = Param( - model.s_PP, - model.s_K, - default=0, - initialize=df_parameters["PKT"], - doc="Valid production-to-disposal trucking arcs [-]", - ) - model.p_PST = Param( - model.s_PP, - model.s_S, - default=0, - initialize={}, - doc="Valid production-to-storage trucking arcs [-]", - ) - model.p_PRT = Param( - model.s_PP, - model.s_R, - default=0, - initialize=df_parameters["PRT"], - doc="Valid production-to-treatment trucking arcs [-]", - ) - model.p_POT = Param( - model.s_PP, - model.s_O, - default=0, - initialize={}, - doc="Valid production-to-reuse trucking arcs [-]", - ) - model.p_CKT = Param( - model.s_CP, - model.s_K, - default=0, - initialize=df_parameters["CKT"], - doc="Valid completions-to-disposal trucking arcs [-]", - ) - model.p_CST = Param( - model.s_CP, - model.s_S, - default=0, - initialize={}, - doc="Valid completions-to-storage trucking arcs [-]", - ) - model.p_CRT = Param( - model.s_CP, - model.s_R, - default=0, - initialize=df_parameters["CRT"], - doc="Valid completions-to-treatment trucking arcs [-]", - ) - model.p_CCT = Param( - model.s_CP, - model.s_CP, - default=0, - initialize=df_parameters["CCT"], - doc="Valid completions-to-completions trucking arcs [-]", - ) - model.p_SCT = Param( - model.s_S, - model.s_CP, - default=0, - initialize={}, - doc="Valid storage-to-completions trucking arcs [-]", - ) - model.p_SKT = Param( - model.s_S, - model.s_K, - default=0, - initialize={}, - doc="Valid storage-to-disposal trucking arcs [-]", - ) - model.p_RKT = Param( - model.s_R, - model.s_K, - default=0, - initialize={}, - doc="Valid treatment-to-disposal trucking arcs [-]", - ) + # Build parameters # + build_params(model) model.p_LLT = Param( model.s_L, diff --git a/pareto/strategic_water_management/strategic_produced_water_optimization.py b/pareto/strategic_water_management/strategic_produced_water_optimization.py index 05e98103..a17985a0 100644 --- a/pareto/strategic_water_management/strategic_produced_water_optimization.py +++ b/pareto/strategic_water_management/strategic_produced_water_optimization.py @@ -58,7 +58,7 @@ model_infeasibility_detection, ) from pareto.utilities.units_support import units_setup -from pareto.utilities.build_utils import define_sets +from pareto.utilities.build_utils import build_sets, build_params class Objectives(Enum): @@ -291,8 +291,8 @@ def create_model(df_sets, df_parameters, default={}): model.proprietary_data = df_parameters["proprietary_data"][0] - # Define sets # - define_sets(model) + # Build sets # + build_sets(model) # Define continuous variables # @@ -771,279 +771,8 @@ def create_model(df_sets, df_parameters, default={}): # Pre-process Data # _preprocess_data(model) - # Define set parameters # - def init_arc_param(arctype): - # If arctype is a key in the dictionary model.df_parameters, return the - # value of that entry from the dictionary. Otherwise, return an empty - # dictionary. - return model.df_parameters.get(arctype, {}) - - model.p_PCA = Param( - model.s_PP, - model.s_CP, - default=0, - initialize=init_arc_param("PCA"), - doc="Valid production-to-completions pipeline arcs [-]", - ) - model.p_PNA = Param( - model.s_PP, - model.s_N, - default=0, - initialize=init_arc_param("PNA"), - doc="Valid production-to-node pipeline arcs [-]", - ) - model.p_PPA = Param( - model.s_PP, - model.s_PP, - default=0, - initialize=init_arc_param("PPA"), - doc="Valid production-to-production pipeline arcs [-]", - ) - model.p_CNA = Param( - model.s_CP, - model.s_N, - default=0, - initialize=init_arc_param("CNA"), - doc="Valid completion-to-node pipeline arcs [-]", - ) - model.p_CCA = Param( - model.s_CP, - model.s_CP, - default=0, - initialize=init_arc_param("CCA"), - doc="Valid completions-to-completions pipelin arcs [-]", - ) - model.p_NNA = Param( - model.s_N, - model.s_N, - default=0, - initialize=init_arc_param("NNA"), - doc="Valid node-to-node pipeline arcs [-]", - ) - model.p_NCA = Param( - model.s_N, - model.s_CP, - default=0, - initialize=init_arc_param("NCA"), - doc="Valid node-to-completions pipeline arcs [-]", - ) - model.p_NKA = Param( - model.s_N, - model.s_K, - default=0, - initialize=init_arc_param("NKA"), - doc="Valid node-to-disposal pipeline arcs [-]", - ) - model.p_NSA = Param( - model.s_N, - model.s_S, - default=0, - initialize=init_arc_param("NSA"), - doc="Valid node-to-storage pipeline arcs [-]", - ) - model.p_NRA = Param( - model.s_N, - model.s_R, - default=0, - initialize=init_arc_param("NRA"), - doc="Valid node-to-treatment pipeline arcs [-]", - ) - model.p_NOA = Param( - model.s_N, - model.s_O, - default=0, - initialize=init_arc_param("NOA"), - doc="Valid node-to-reuse pipeline arcs [-]", - ) - model.p_FCA = Param( - model.s_F, - model.s_CP, - default=0, - initialize=init_arc_param("FCA"), - doc="Valid externally sourced water-to-completions pipeline arcs [-]", - ) - model.p_RNA = Param( - model.s_R, - model.s_N, - default=0, - initialize=init_arc_param("RNA"), - doc="Valid treatment-to-node pipeline arcs [-]", - ) - model.p_RCA = Param( - model.s_R, - model.s_CP, - default=0, - initialize=init_arc_param("RCA"), - doc="Valid treatment-to-completions pipeline arcs [-]", - ) - model.p_RKA = Param( - model.s_R, - model.s_K, - default=0, - initialize=init_arc_param("RKA"), - doc="Valid treatment-to-disposal pipeline arcs [-]", - ) - model.p_RSA = Param( - model.s_R, - model.s_S, - default=0, - initialize=init_arc_param("RSA"), - doc="Valid treatment-to-storage pipeline arcs [-]", - ) - model.p_SNA = Param( - model.s_S, - model.s_N, - default=0, - initialize=init_arc_param("SNA"), - doc="Valid storage-to-node pipeline arcs [-]", - ) - model.p_SCA = Param( - model.s_S, - model.s_CP, - default=0, - initialize=init_arc_param("SCA"), - doc="Valid storage-to-completions pipeline arcs [-]", - ) - model.p_SKA = Param( - model.s_S, - model.s_K, - default=0, - initialize=init_arc_param("SKA"), - doc="Valid storage-to-disposal pipeline arcs [-]", - ) - model.p_SRA = Param( - model.s_S, - model.s_R, - default=0, - initialize=init_arc_param("SRA"), - doc="Valid storage-to-treatment pipeline arcs [-]", - ) - model.p_SOA = Param( - model.s_S, - model.s_O, - default=0, - initialize=init_arc_param("SOA"), - doc="Valid storage-to-reuse pipeline arcs [-]", - ) - model.p_ROA = Param( - model.s_R, - model.s_O, - default=0, - initialize=init_arc_param("ROA"), - doc="Valid treatment-to-reuse pipeline arcs [-]", - ) - model.p_PCT = Param( - model.s_PP, - model.s_CP, - default=0, - initialize=init_arc_param("PCT"), - doc="Valid production-to-completions trucking arcs [-]", - ) - model.p_PKT = Param( - model.s_PP, - model.s_K, - default=0, - initialize=init_arc_param("PKT"), - doc="Valid production-to-disposal trucking arcs [-]", - ) - model.p_PST = Param( - model.s_PP, - model.s_S, - default=0, - initialize=init_arc_param("PST"), - doc="Valid production-to-storage trucking arcs [-]", - ) - model.p_PRT = Param( - model.s_PP, - model.s_R, - default=0, - initialize=init_arc_param("PRT"), - doc="Valid production-to-treatment trucking arcs [-]", - ) - model.p_POT = Param( - model.s_PP, - model.s_O, - default=0, - initialize=init_arc_param("POT"), - doc="Valid production-to-reuse trucking arcs [-]", - ) - model.p_FCT = Param( - model.s_F, - model.s_CP, - default=0, - initialize=init_arc_param("FCT"), - doc="Valid externally sourced water-to-completions trucking arcs [-]", - ) - model.p_CKT = Param( - model.s_CP, - model.s_K, - default=0, - initialize=init_arc_param("CKT"), - doc="Valid completions-to-disposal trucking arcs [-]", - ) - model.p_CST = Param( - model.s_CP, - model.s_S, - default=0, - initialize=init_arc_param("CST"), - doc="Valid completions-to-storage trucking arcs [-]", - ) - model.p_CRT = Param( - model.s_CP, - model.s_R, - default=0, - initialize=init_arc_param("CRT"), - doc="Valid completions-to-treatment trucking arcs [-]", - ) - model.p_CCT = Param( - model.s_CP, - model.s_CP, - default=0, - initialize=init_arc_param("CCT"), - doc="Valid completion-to-completion trucking arcs [-]", - ) - model.p_SCT = Param( - model.s_S, - model.s_CP, - default=0, - initialize=init_arc_param("SCT"), - doc="Valid storage-to-completions trucking arcs [-]", - ) - model.p_SKT = Param( - model.s_S, - model.s_K, - default=0, - initialize=init_arc_param("SKT"), - doc="Valid storage-to-disposal trucking arcs [-]", - ) - model.p_SOT = Param( - model.s_S, - model.s_O, - default=0, - initialize=init_arc_param("SOT"), - doc="Valid storage-to-reuse trucking arcs [-]", - ) - model.p_RKT = Param( - model.s_R, - model.s_K, - default=0, - initialize=init_arc_param("RKT"), - doc="Valid treatment-to-disposal trucking arcs [-]", - ) - model.p_RST = Param( - model.s_R, - model.s_S, - default=0, - initialize=init_arc_param("RST"), - doc="Valid treatment-to-storage trucking arcs [-]", - ) - model.p_ROT = Param( - model.s_R, - model.s_O, - default=0, - initialize=init_arc_param("ROT"), - doc="Valid treatment-to-reuse trucking arcs [-]", - ) + # Build parameters # + build_params(model) # Define set parameters # diff --git a/pareto/utilities/build_utils.py b/pareto/utilities/build_utils.py index d253a643..44b0eb47 100644 --- a/pareto/utilities/build_utils.py +++ b/pareto/utilities/build_utils.py @@ -16,14 +16,17 @@ Authors: PARETO Team """ -from pyomo.environ import Set +from pyomo.environ import Set, Param from pareto.utilities.process_data import ( get_valid_piping_arc_list, get_valid_trucking_arc_list, ) -def define_sets(model): +def build_sets(model): + """Build sets for operational and strategic models.""" + + # Build sets which are common to operational and strategic models model.s_T = Set( initialize=model.df_sets["TimePeriods"], doc="Time Periods", ordered=True ) @@ -57,6 +60,27 @@ def define_sets(model): doc="Water Quality Components", ) + # Build dictionary of all specified piping arcs + piping_arc_types = get_valid_piping_arc_list() + model.df_parameters["LLA"] = {} + for arctype in piping_arc_types: + if arctype in model.df_parameters: + model.df_parameters["LLA"].update(model.df_parameters[arctype]) + model.s_LLA = Set( + initialize=list(model.df_parameters["LLA"].keys()), doc="Valid Piping Arcs" + ) + + # Build dictionary of all specified trucking arcs + trucking_arc_types = get_valid_trucking_arc_list() + model.df_parameters["LLT"] = {} + for arctype in trucking_arc_types: + if arctype in model.df_parameters: + model.df_parameters["LLT"].update(model.df_parameters[arctype]) + model.s_LLT = Set( + initialize=list(model.df_parameters["LLT"].keys()), doc="Valid Trucking Arcs" + ) + + # Build sets specific to operational model if model.type == "operational": model.s_A = Set( initialize=model.df_sets["ProductionTanks"], doc="Production Tanks" @@ -65,6 +89,7 @@ def define_sets(model): model.s_C = Set(initialize=["C0"], doc="Storage capacities") model.s_I = Set(initialize=["I0"], doc="Injection (i.e. disposal) capacities") + # Build sets specific to strategic model if model.type == "strategic": model.s_D = Set( initialize=model.df_sets["PipelineDiameters"], doc="Pipeline diameters" @@ -88,22 +113,47 @@ def define_sets(model): doc="Air emission components", ) - # Build dictionary of all specified piping arcs - piping_arc_types = get_valid_piping_arc_list(model.type) - model.df_parameters["LLA"] = {} - for arctype in piping_arc_types: - if arctype in model.df_parameters: - model.df_parameters["LLA"].update(model.df_parameters[arctype]) - model.s_LLA = Set( - initialize=list(model.df_parameters["LLA"].keys()), doc="Valid Piping Arcs" - ) - # Build dictionary of all specified trucking arcs - trucking_arc_types = get_valid_trucking_arc_list(model.type) - model.df_parameters["LLT"] = {} - for arctype in trucking_arc_types: - if arctype in model.df_parameters: - model.df_parameters["LLT"].update(model.df_parameters[arctype]) - model.s_LLT = Set( - initialize=list(model.df_parameters["LLT"].keys()), doc="Valid Trucking Arcs" - ) +def build_params(model): + """Build parameters common to operational and strategic models.""" + node_type = { + "P": "PP", + "C": "CP", + "N": "N", + "K": "K", + "S": "S", + "R": "R", + "O": "O", + "F": "F", + } + node_description = { + "P": "production", + "C": "completions", + "N": "node", + "K": "disposal", + "S": "storage", + "R": "treatment", + "O": "reuse", + "F": "externally sourced water", + } + transport_description = { + "A": "piping", + "T": "trucking", + } + + # Build Params for all arc types + arc_types = get_valid_piping_arc_list() + get_valid_trucking_arc_list() + for at in arc_types: + # at is a string of the form "XYZ", where X and Y are node types and Z + # is either A for piping or T for trucking + setattr( + model, + "p_" + at, # e.g., p_PCA + Param( + getattr(model, "s_" + node_type[at[0]]), # e.g., model.s_PP + getattr(model, "s_" + node_type[at[1]]), # e.g., model.s_CP + default=0, + initialize=model.df_parameters.get(at, {}), + doc=f"Valid {node_description[at[0]]}-to-{node_description[at[1]]} {transport_description[at[2]]} arcs", + ), + ) diff --git a/pareto/utilities/process_data.py b/pareto/utilities/process_data.py index 91f49834..fc9e0e4a 100644 --- a/pareto/utilities/process_data.py +++ b/pareto/utilities/process_data.py @@ -28,75 +28,54 @@ from pyomo.environ import Expression, value -def get_valid_trucking_arc_list(model_type="strategic"): +def get_valid_trucking_arc_list(): """Returns a list of all valid trucking arcs.""" - if model_type == "operational": - return [ - "PCT", - "CCT", - "CRT", - "CKT", - "FCT", - "PKT", - "PRT", - ] - else: - # Return the list for strategic model unless operational model - # is specified. - return [ - "PCT", - "PKT", - "PST", - "PRT", - "POT", - "FCT", - "CKT", - "CST", - "CRT", - "CCT", - "SCT", - "SKT", - "SOT", - "RKT", - "RST", - "ROT", - ] - - -def get_valid_piping_arc_list(model_type="strategic"): + return [ + "PCT", + "PKT", + "PST", + "PRT", + "POT", + "FCT", + "CKT", + "CST", + "CRT", + "CCT", + "SCT", + "SKT", + "SOT", + "RKT", + "RST", + "ROT", + ] + + +def get_valid_piping_arc_list(): """Returns a list of all valid piping arcs.""" - if model_type == "operational": - return [ - "RCA", - "FCA", - ] - else: - # Return the list for strategic model unless operational model - # is specified. - return [ - "PCA", - "PNA", - "PPA", - "CNA", - "CCA", - "NNA", - "NCA", - "NKA", - "NSA", - "NRA", - "NOA", - "FCA", - "RNA", - "RCA", - "RKA", - "RSA", - "ROA", - "SNA", - "SCA", - "SKA", - "SRA", - "SOA", - ] + return [ + "PCA", + "PNA", + "PPA", + "CNA", + "CCA", + "NNA", + "NCA", + "NKA", + "NSA", + "NRA", + "NOA", + "FCA", + "RNA", + "RCA", + "RKA", + "RSA", + "ROA", + "SNA", + "SCA", + "SKA", + "SRA", + "SOA", + ] # Process the input data (df_sets, df_parameters) from get_data.py.