Skip to content

Commit

Permalink
Consolidate code for defining sets
Browse files Browse the repository at this point in the history
  • Loading branch information
tarnold17 committed Sep 16, 2024
1 parent 2288913 commit 30391dd
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from enum import Enum

from pareto.utilities.units_support import units_setup
from pareto.utilities.build_utils import define_sets


class ProdTank(Enum):
Expand Down Expand Up @@ -110,37 +111,7 @@ def create_model(df_sets, df_parameters, default={}):
model.proprietary_data = df_parameters["proprietary_data"][0]

# Define sets #
model.s_T = Set(initialize=df_sets["TimePeriods"], doc="Time Periods", ordered=True)
model.s_PP = Set(initialize=df_sets["ProductionPads"], doc="Production Pads")
model.s_CP = Set(initialize=df_sets["CompletionsPads"], doc="Completions Pads")
model.s_A = Set(initialize=df_sets["ProductionTanks"], doc="Production Tanks")
model.s_P = Set(initialize=(model.s_PP | model.s_CP), doc="Pads")
model.s_F = Set(
initialize=df_sets["ExternalWaterSources"], doc="External Water Sources"
)
model.s_K = Set(initialize=df_sets["SWDSites"], doc="Disposal Sites")
model.s_S = Set(initialize=df_sets["StorageSites"], doc="Storage Sites")
model.s_R = Set(initialize=df_sets["TreatmentSites"], doc="Treatment Sites")
model.s_O = Set(initialize=df_sets["ReuseOptions"], doc="Reuse Options")
model.s_N = Set(initialize=df_sets["NetworkNodes"], doc=["Network Nodes"])
model.s_W = Set(
initialize=df_sets["WaterQualityComponents"], doc="Water Quality Components"
)
model.s_L = Set(
initialize=(
model.s_P
| model.s_F
| model.s_K
| model.s_S
| model.s_R
| model.s_O
| model.s_N
),
doc="Locations",
)
model.s_D = Set(initialize=["D0"], doc="Pipeline diameters")
model.s_C = Set(initialize=["C0"], doc="Storage capacities")
model.s_I = Set(initialize=["I0"], doc="Injection (i.e. disposal) capacities")
define_sets(model)

# Define model parameters #
model.p_PCA = Param(
Expand Down Expand Up @@ -283,10 +254,6 @@ def create_model(df_sets, df_parameters, default={}):
initialize={},
doc="Valid storage-to-reuse pipeline arcs [-]",
)
df_parameters["LLA"] = {
**df_parameters["RCA"],
**df_parameters["FCA"],
}
model.p_PCT = Param(
model.s_PP,
model.s_CP,
Expand Down Expand Up @@ -378,24 +345,6 @@ def create_model(df_sets, df_parameters, default={}):
initialize={},
doc="Valid treatment-to-disposal trucking arcs [-]",
)
df_parameters["LLT"] = {
**df_parameters["PCT"],
**df_parameters["CCT"],
**df_parameters["CRT"],
**df_parameters["CKT"],
**df_parameters["FCT"],
**df_parameters["PKT"],
**df_parameters["PRT"],
}

model.s_LLT = Set(
initialize=list(df_parameters["LLT"].keys()),
doc="Location-to-location trucking arcs",
)
model.s_LLA = Set(
initialize=list(df_parameters["LLA"].keys()),
doc="Location-to-location piping arcs",
)

model.p_LLT = Param(
model.s_L,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@
from pathlib import Path

from pareto.utilities.process_data import (
get_valid_piping_arc_list,
get_valid_trucking_arc_list,
check_required_data,
model_infeasibility_detection,
)
from pareto.utilities.units_support import units_setup
from pareto.utilities.build_utils import define_sets


class Objectives(Enum):
Expand Down Expand Up @@ -293,83 +292,7 @@ def create_model(df_sets, df_parameters, default={}):
model.proprietary_data = df_parameters["proprietary_data"][0]

# Define sets #

model.s_T = Set(
initialize=model.df_sets["TimePeriods"], doc="Time Periods", ordered=True
)
model.s_PP = Set(initialize=model.df_sets["ProductionPads"], doc="Production Pads")
model.s_CP = Set(
initialize=model.df_sets["CompletionsPads"], doc="Completions Pads"
)
model.s_P = Set(initialize=(model.s_PP | model.s_CP), doc="Pads")
model.s_F = Set(
initialize=model.df_sets["ExternalWaterSources"], doc="External Water Sources"
)
model.s_K = Set(initialize=model.df_sets["SWDSites"], doc="Disposal Sites")
model.s_S = Set(initialize=model.df_sets["StorageSites"], doc="Storage Sites")
model.s_R = Set(initialize=model.df_sets["TreatmentSites"], doc="Treatment Sites")
model.s_O = Set(initialize=model.df_sets["ReuseOptions"], doc="Reuse Options")
model.s_N = Set(initialize=model.df_sets["NetworkNodes"], doc="Network Nodes")
model.s_QC = Set(
initialize=model.df_sets["WaterQualityComponents"],
doc="Water Quality Components",
)
model.s_L = Set(
initialize=(
model.s_P
| model.s_F
| model.s_K
| model.s_S
| model.s_R
| model.s_O
| model.s_N
),
doc="Locations",
)
model.s_D = Set(
initialize=model.df_sets["PipelineDiameters"], doc="Pipeline diameters"
)
model.s_C = Set(
initialize=model.df_sets["StorageCapacities"], doc="Storage capacities"
)
model.s_J = Set(
initialize=model.df_sets["TreatmentCapacities"], doc="Treatment capacities"
)
model.s_I = Set(
initialize=model.df_sets["InjectionCapacities"],
doc="Injection (i.e. disposal) capacities",
)

model.s_WT = Set(
initialize=model.df_sets["TreatmentTechnologies"], doc="Treatment Technologies"
)

model.s_A = Set(
initialize=model.df_sets["AirEmissionsComponents"],
doc="Air emission components",
)

piping_arc_types = get_valid_piping_arc_list()

# Build dictionary of all specified piping arcs
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"
)

trucking_arc_types = get_valid_trucking_arc_list()

# Build dictionary of all specified trucking arcs
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"
)
define_sets(model)

# Define continuous variables #

Expand Down
108 changes: 108 additions & 0 deletions pareto/utilities/build_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#####################################################################################################
# PARETO was produced under the DOE Produced Water Application for Beneficial Reuse Environmental
# Impact and Treatment Optimization (PARETO), and is copyright (c) 2021-2024 by the software owners:
# The Regents of the University of California, through Lawrence Berkeley National Laboratory, et al.
# All rights reserved.
#
# NOTICE. This Software was developed under funding from the U.S. Department of Energy and the U.S.
# Government consequently retains certain rights. As such, the U.S. Government has been granted for
# itself and others acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide license in
# the Software to reproduce, distribute copies to the public, prepare derivative works, and perform
# publicly and display publicly, and to permit others to do so.
#####################################################################################################
"""
Module with build utility functions for strategic and operational models.
Authors: PARETO Team
"""

from pyomo.environ import Set
from pareto.utilities.process_data import (
get_valid_piping_arc_list,
get_valid_trucking_arc_list,
)

def define_sets(model):
model.s_T = Set(
initialize=model.df_sets["TimePeriods"], doc="Time Periods", ordered=True
)
model.s_PP = Set(initialize=model.df_sets["ProductionPads"], doc="Production Pads")
model.s_CP = Set(
initialize=model.df_sets["CompletionsPads"], doc="Completions Pads"
)
model.s_P = Set(initialize=(model.s_PP | model.s_CP), doc="Pads")
model.s_F = Set(
initialize=model.df_sets["ExternalWaterSources"], doc="External Water Sources"
)
model.s_K = Set(initialize=model.df_sets["SWDSites"], doc="Disposal Sites")
model.s_S = Set(initialize=model.df_sets["StorageSites"], doc="Storage Sites")
model.s_R = Set(initialize=model.df_sets["TreatmentSites"], doc="Treatment Sites")
model.s_O = Set(initialize=model.df_sets["ReuseOptions"], doc="Reuse Options")
model.s_N = Set(initialize=model.df_sets["NetworkNodes"], doc="Network Nodes")
model.s_L = Set(
initialize=(
model.s_P
| model.s_F
| model.s_K
| model.s_S
| model.s_R
| model.s_O
| model.s_N
),
doc="Locations",
)

if model.type == "operational":
model.s_A = Set(initialize=model.df_sets["ProductionTanks"], doc="Production Tanks")
model.s_W = Set(
initialize=model.df_sets["WaterQualityComponents"], doc="Water Quality Components"
) # TODO change operational model notation to match strategic (s_QC)
model.s_D = Set(initialize=["D0"], doc="Pipeline diameters")
model.s_C = Set(initialize=["C0"], doc="Storage capacities")
model.s_I = Set(initialize=["I0"], doc="Injection (i.e. disposal) capacities")

if model.type == "strategic":
model.s_QC = Set(
initialize=model.df_sets["WaterQualityComponents"],
doc="Water Quality Components",
)
model.s_D = Set(
initialize=model.df_sets["PipelineDiameters"], doc="Pipeline diameters"
)
model.s_C = Set(
initialize=model.df_sets["StorageCapacities"], doc="Storage capacities"
)
model.s_J = Set(
initialize=model.df_sets["TreatmentCapacities"], doc="Treatment capacities"
)
model.s_I = Set(
initialize=model.df_sets["InjectionCapacities"],
doc="Injection (i.e. disposal) capacities",
)
model.s_WT = Set(
initialize=model.df_sets["TreatmentTechnologies"], doc="Treatment Technologies"
)
model.s_A = Set(
initialize=model.df_sets["AirEmissionsComponents"],
doc="Air emission components",
) # TODO change s_A to something else in strategic model to avoid name clash with production tanks in operational model

# 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"
)
Loading

0 comments on commit 30391dd

Please sign in to comment.