Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into methanol
Browse files Browse the repository at this point in the history
  • Loading branch information
parkyr committed May 30, 2024
2 parents 11e9242 + c1fee75 commit e70851d
Show file tree
Hide file tree
Showing 61 changed files with 13,118 additions and 4,078 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/
110 changes: 110 additions & 0 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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",
# "positioning",
# "spectralog",
# "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)
9 changes: 7 additions & 2 deletions gdplib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import gdplib.mod_hens
import gdplib.modprodnet
import gdplib.biofuel
import gdplib.logical # Requires logical expression system
import gdplib.pyomo_examples
import gdplib.positioning
import gdplib.spectralog
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 e70851d

Please sign in to comment.