Skip to content

Commit

Permalink
Merge branch 'master' into kaibel
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantc committed May 24, 2024
2 parents 8e0cdc4 + e2f5ede commit bef720e
Show file tree
Hide file tree
Showing 52 changed files with 14,954 additions and 3,812 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
name: lint/style-and-typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Black Formatting Check
uses: psf/black@stable
with:
options: "-S -C --check --diff"
- name: Spell Check
uses: crate-ci/typos@master
with:
config: ./.github/workflows/typos.toml
5 changes: 5 additions & 0 deletions .github/workflows/typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[default.extend-words]
# Ignore HDA
hda = "hda"
HDA = "HDA"
equil = "equil"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ dmypy.json

# Pycharm
.idea/

gdplib/*/benchmark_result/
43 changes: 43 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cff-version: 1.0.0
message: "If you use this software, please cite it as below."
authors:
- family-names: Bernal Neira
given-names: David E.
orcid: https://orcid.org/0000-0002-8308-5016
- family-names: Peng
given-names: Zedong
orcid: https://orcid.org/0000-0001-6001-1738
- family-names: Chen
given-names: Qi
orcid: https://orcid.org/0000-0002-2389-2238
- family-names: Liu
given-names: Yunshan
- family-names: Johnson
given-names: Emma
orcid: https://orcid.org/0000-0002-4285-5184
title: "GDPLib: an open library of Generalized Disjunctive Programming (GDP) models"
version: 1.0.0
url: https://github.com/SECQUOIA/gdplib
license-url: https://github.com/SECQUOIA/gdplib/blob/master/LICENSE
preferred-citation:
type: incollection
booktitle: "Computer Aided Chemical Engineering"
volume: 49
start: 1285
end: 1290
title: "Advances in Generalized Disjunctive and Mixed-Integer Nonlinear Programming Algorithms and Software for Superstructure Optimization"
year:2022
publisher: "Elsevier"
authors:
- family-names: "Bernal Neira"
given-names: "David E."
- family-names: "Liu"
given-names: "Yunshan"
- family-names: "Bynum"
given-names: "Michael L"
- family-names: "Laird"
given-names: "Carl D"
- family-names: "Siirola"
given-names: "John D"
- family-names: "Grossmann"
given-names: "Ignacio E"
109 changes: 109 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import os
import json
import time
import sys
from datetime import datetime
from importlib import import_module
from pyomo.environ import *


def benchmark(model, strategy, timelimit, result_dir, subsolver="scip"):
"""Benchmark the model using the given strategy and subsolver.
The result files include the solver output and the JSON representation of the results.
Parameters
----------
model : PyomoModel
the model to be solved
strategy : string
the strategy used to solve the model
timelimit : int
the time limit for the solver
result_dir : string
the directory to store the benchmark results
Returns
-------
None
"""
model = model.clone()
stdout = sys.stdout
if strategy in ["gdp.bigm", "gdp.hull"]:
transformation_start_time = time.time()
TransformationFactory(strategy).apply_to(model)
transformation_end_time = time.time()
with open(
result_dir + "/" + strategy + "_" + subsolver + ".log", "w"
) as sys.stdout:
results = SolverFactory(subsolver).solve(
model, tee=True, timelimit=timelimit
)
results.solver.transformation_time = (
transformation_end_time - transformation_start_time
)
print(results)
elif strategy in [
"gdpopt.enumerate",
"gdpopt.loa",
"gdpopt.gloa",
"gdpopt.lbb",
"gdpopt.ric",
]:
with open(
result_dir + "/" + strategy + "_" + subsolver + ".log", "w"
) as sys.stdout:
results = SolverFactory(strategy).solve(
model,
tee=True,
nlp_solver=subsolver,
mip_solver=subsolver,
minlp_solver=subsolver,
local_minlp_solver=subsolver,
time_limit=timelimit,
)
print(results)

sys.stdout = stdout
with open(result_dir + "/" + strategy + "_" + subsolver + ".json", "w") as f:
json.dump(results.json_repn(), f)
return None


if __name__ == "__main__":
instance_list = [
# "batch_processing",
# "biofuel",
# "disease_model",
# "gdp_col",
# "hda",
"jobshop",
# "kaibel",
# "logical",
# "med_term_purchasing",
# "methanol",
# "mod_hens",
# "modprodnet",
# "stranded_gas",
# "syngas",
]
strategy_list = [
"gdp.bigm",
"gdp.hull",
"gdpopt.enumerate",
"gdpopt.loa",
"gdpopt.gloa",
"gdpopt.ric",
]
current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
timelimit = 600

for instance in instance_list:
print("Benchmarking instance: " + instance)
result_dir = "gdplib/" + instance + "/benchmark_result/"
os.makedirs(result_dir, exist_ok=True)

model = import_module("gdplib." + instance).build_model()

for strategy in strategy_list:
benchmark(model, strategy, timelimit, result_dir)
6 changes: 5 additions & 1 deletion gdplib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
import gdplib.modprodnet
import gdplib.biofuel
import gdplib.logical # Requires logical expression system
import gdplib.pyomo_examples
import gdplib.stranded_gas # Requires logical expression system
import gdplib.gdp_col
import gdplib.hda
import gdplib.kaibel
import gdplib.methanol
import gdplib.batch_processing
import gdplib.jobshop
import gdplib.disease_model
import gdplib.med_term_purchasing
import gdplib.syngas
3 changes: 3 additions & 0 deletions gdplib/batch_processing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .batch_processing import build_model

__all__ = ['build_model']
File renamed without changes.
Loading

0 comments on commit bef720e

Please sign in to comment.