mirror of
https://github.com/ANL-CEEESA/UnitCommitment.jl.git
synced 2025-12-06 08:18:51 -06:00
Reformat Python scripts
This commit is contained in:
@@ -8,41 +8,49 @@ import seaborn as sns
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
#easy_cutoff = 120
|
# easy_cutoff = 120
|
||||||
|
|
||||||
b1 = pd.read_csv(sys.argv[1], index_col=0)
|
b1 = pd.read_csv(sys.argv[1], index_col=0)
|
||||||
b2 = pd.read_csv(sys.argv[2], index_col=0)
|
b2 = pd.read_csv(sys.argv[2], index_col=0)
|
||||||
|
|
||||||
c1 = b1.groupby(["Group", "Instance", "Sample"])[["Optimization time (s)", "Primal bound"]].mean()
|
c1 = b1.groupby(["Group", "Instance", "Sample"])[
|
||||||
c2 = b2.groupby(["Group", "Instance", "Sample"])[["Optimization time (s)", "Primal bound"]].mean()
|
["Optimization time (s)", "Primal bound"]
|
||||||
|
].mean()
|
||||||
|
c2 = b2.groupby(["Group", "Instance", "Sample"])[
|
||||||
|
["Optimization time (s)", "Primal bound"]
|
||||||
|
].mean()
|
||||||
c1.columns = ["A Time (s)", "A Value"]
|
c1.columns = ["A Time (s)", "A Value"]
|
||||||
c2.columns = ["B Time (s)", "B Value"]
|
c2.columns = ["B Time (s)", "B Value"]
|
||||||
|
|
||||||
merged = pd.concat([c1, c2], axis=1)
|
merged = pd.concat([c1, c2], axis=1)
|
||||||
merged["Speedup"] = merged["A Time (s)"] / merged["B Time (s)"]
|
merged["Speedup"] = merged["A Time (s)"] / merged["B Time (s)"]
|
||||||
merged["Time diff (s)"] = merged["B Time (s)"] - merged["A Time (s)"]
|
merged["Time diff (s)"] = merged["B Time (s)"] - merged["A Time (s)"]
|
||||||
merged["Value diff (%)"] = np.round((merged["B Value"] - merged["A Value"]) / merged["A Value"] * 100.0, 5)
|
merged["Value diff (%)"] = np.round(
|
||||||
|
(merged["B Value"] - merged["A Value"]) / merged["A Value"] * 100.0, 5
|
||||||
|
)
|
||||||
merged.loc[merged.loc[:, "B Time (s)"] <= 0, "Speedup"] = float("nan")
|
merged.loc[merged.loc[:, "B Time (s)"] <= 0, "Speedup"] = float("nan")
|
||||||
merged.loc[merged.loc[:, "B Time (s)"] <= 0, "Time diff (s)"] = float("nan")
|
merged.loc[merged.loc[:, "B Time (s)"] <= 0, "Time diff (s)"] = float("nan")
|
||||||
#merged = merged[(merged["A Time (s)"] >= easy_cutoff) | (merged["B Time (s)"] >= easy_cutoff)]
|
# merged = merged[(merged["A Time (s)"] >= easy_cutoff) | (merged["B Time (s)"] >= easy_cutoff)]
|
||||||
merged.reset_index(inplace=True)
|
merged.reset_index(inplace=True)
|
||||||
merged["Name"] = merged["Group"] + "/" + merged["Instance"]
|
merged["Name"] = merged["Group"] + "/" + merged["Instance"]
|
||||||
#merged = merged.sort_values(by="Speedup", ascending=False)
|
# merged = merged.sort_values(by="Speedup", ascending=False)
|
||||||
|
|
||||||
|
|
||||||
k = len(merged.groupby("Name"))
|
k = len(merged.groupby("Name"))
|
||||||
plt.figure(figsize=(12, 0.50 * k))
|
plt.figure(figsize=(12, 0.50 * k))
|
||||||
plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = True
|
plt.rcParams["xtick.bottom"] = plt.rcParams["xtick.labelbottom"] = True
|
||||||
plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True
|
plt.rcParams["xtick.top"] = plt.rcParams["xtick.labeltop"] = True
|
||||||
sns.set_style("whitegrid")
|
sns.set_style("whitegrid")
|
||||||
sns.set_palette("Set1")
|
sns.set_palette("Set1")
|
||||||
sns.barplot(data=merged,
|
sns.barplot(
|
||||||
|
data=merged,
|
||||||
x="Speedup",
|
x="Speedup",
|
||||||
y="Name",
|
y="Name",
|
||||||
color="tab:red",
|
color="tab:red",
|
||||||
capsize=0.15,
|
capsize=0.15,
|
||||||
errcolor="k",
|
errcolor="k",
|
||||||
errwidth=1.25)
|
errwidth=1.25,
|
||||||
|
)
|
||||||
plt.axvline(1.0, linestyle="--", color="k")
|
plt.axvline(1.0, linestyle="--", color="k")
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
|
|
||||||
@@ -50,7 +58,10 @@ print("Writing tables/compare.png")
|
|||||||
plt.savefig("tables/compare.png", dpi=150)
|
plt.savefig("tables/compare.png", dpi=150)
|
||||||
|
|
||||||
print("Writing tables/compare.csv")
|
print("Writing tables/compare.csv")
|
||||||
merged.loc[:, ["Group",
|
merged.loc[
|
||||||
|
:,
|
||||||
|
[
|
||||||
|
"Group",
|
||||||
"Instance",
|
"Instance",
|
||||||
"Sample",
|
"Sample",
|
||||||
"A Time (s)",
|
"A Time (s)",
|
||||||
@@ -60,5 +71,5 @@ merged.loc[:, ["Group",
|
|||||||
"A Value",
|
"A Value",
|
||||||
"B Value",
|
"B Value",
|
||||||
"Value diff (%)",
|
"Value diff (%)",
|
||||||
]
|
],
|
||||||
].to_csv("tables/compare.csv", index_label="Index")
|
].to_csv("tables/compare.csv", index_label="Index")
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ from tabulate import tabulate
|
|||||||
|
|
||||||
|
|
||||||
def process_all_log_files():
|
def process_all_log_files():
|
||||||
pathlist = list(Path(".").glob('results/*/*/*.log'))
|
pathlist = list(Path(".").glob("results/*/*/*.log"))
|
||||||
pathlist += list(Path(".").glob('results/*/*.log'))
|
pathlist += list(Path(".").glob("results/*/*.log"))
|
||||||
rows = []
|
rows = []
|
||||||
for path in pathlist:
|
for path in pathlist:
|
||||||
if ".ipy" in str(path):
|
if ".ipy" in str(path):
|
||||||
@@ -52,37 +52,55 @@ def process(filename):
|
|||||||
|
|
||||||
with open(filename) as file:
|
with open(filename) as file:
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
m = re.search(r"Explored ([0-9.e+]*) nodes \(([0-9.e+]*) simplex iterations\) in ([0-9.e+]*) seconds", line)
|
m = re.search(
|
||||||
|
r"Explored ([0-9.e+]*) nodes \(([0-9.e+]*) simplex iterations\) in ([0-9.e+]*) seconds",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
nodes += int(m.group(1))
|
nodes += int(m.group(1))
|
||||||
simplex_iterations += int(m.group(2))
|
simplex_iterations += int(m.group(2))
|
||||||
optimize_time += float(m.group(3))
|
optimize_time += float(m.group(3))
|
||||||
|
|
||||||
m = re.search(r"Best objective ([0-9.e+]*), best bound ([0-9.e+]*), gap ([0-9.e+]*)\%", line)
|
m = re.search(
|
||||||
|
r"Best objective ([0-9.e+]*), best bound ([0-9.e+]*), gap ([0-9.e+]*)\%",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
primal_bound = float(m.group(1))
|
primal_bound = float(m.group(1))
|
||||||
dual_bound = float(m.group(2))
|
dual_bound = float(m.group(2))
|
||||||
gap = round(float(m.group(3)), 3)
|
gap = round(float(m.group(3)), 3)
|
||||||
|
|
||||||
m = re.search(r"Root relaxation: objective ([0-9.e+]*), ([0-9.e+]*) iterations, ([0-9.e+]*) seconds", line)
|
m = re.search(
|
||||||
|
r"Root relaxation: objective ([0-9.e+]*), ([0-9.e+]*) iterations, ([0-9.e+]*) seconds",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
root_obj = float(m.group(1))
|
root_obj = float(m.group(1))
|
||||||
root_iterations += int(m.group(2))
|
root_iterations += int(m.group(2))
|
||||||
root_time += float(m.group(3))
|
root_time += float(m.group(3))
|
||||||
|
|
||||||
m = re.search(r"Presolved: ([0-9.e+]*) rows, ([0-9.e+]*) columns, ([0-9.e+]*) nonzeros", line)
|
m = re.search(
|
||||||
|
r"Presolved: ([0-9.e+]*) rows, ([0-9.e+]*) columns, ([0-9.e+]*) nonzeros",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
n_rows_presolved = int(m.group(1))
|
n_rows_presolved = int(m.group(1))
|
||||||
n_cols_presolved = int(m.group(2))
|
n_cols_presolved = int(m.group(2))
|
||||||
n_nz_presolved = int(m.group(3))
|
n_nz_presolved = int(m.group(3))
|
||||||
|
|
||||||
m = re.search(r"Optimize a model with ([0-9.e+]*) rows, ([0-9.e+]*) columns and ([0-9.e+]*) nonzeros", line)
|
m = re.search(
|
||||||
|
r"Optimize a model with ([0-9.e+]*) rows, ([0-9.e+]*) columns and ([0-9.e+]*) nonzeros",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
n_rows_orig = int(m.group(1))
|
n_rows_orig = int(m.group(1))
|
||||||
n_cols_orig = int(m.group(2))
|
n_cols_orig = int(m.group(2))
|
||||||
n_nz_orig = int(m.group(3))
|
n_nz_orig = int(m.group(3))
|
||||||
|
|
||||||
m = re.search(r"Variable types: ([0-9.e+]*) continuous, ([0-9.e+]*) integer \(([0-9.e+]*) binary\)", line)
|
m = re.search(
|
||||||
|
r"Variable types: ([0-9.e+]*) continuous, ([0-9.e+]*) integer \(([0-9.e+]*) binary\)",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
n_cont_vars_presolved = int(m.group(1))
|
n_cont_vars_presolved = int(m.group(1))
|
||||||
n_bin_vars_presolved = int(m.group(3))
|
n_bin_vars_presolved = int(m.group(3))
|
||||||
@@ -103,7 +121,10 @@ def process(filename):
|
|||||||
if m is not None:
|
if m is not None:
|
||||||
total_time = float(m.group(1))
|
total_time = float(m.group(1))
|
||||||
|
|
||||||
m = re.search(r"User-callback calls ([0-9.e+]*), time in user-callback ([0-9.e+]*) sec", line)
|
m = re.search(
|
||||||
|
r"User-callback calls ([0-9.e+]*), time in user-callback ([0-9.e+]*) sec",
|
||||||
|
line,
|
||||||
|
)
|
||||||
if m is not None:
|
if m is not None:
|
||||||
cb_calls = int(m.group(1))
|
cb_calls = int(m.group(1))
|
||||||
cb_time = float(m.group(2))
|
cb_time = float(m.group(2))
|
||||||
@@ -150,6 +171,7 @@ def process(filename):
|
|||||||
"Transmission screening calls": transmission_calls,
|
"Transmission screening calls": transmission_calls,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_chart():
|
def generate_chart():
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@@ -159,7 +181,9 @@ def generate_chart():
|
|||||||
files = ["tables/benchmark.csv"]
|
files = ["tables/benchmark.csv"]
|
||||||
for f in files:
|
for f in files:
|
||||||
table = pd.read_csv(f, index_col=0)
|
table = pd.read_csv(f, index_col=0)
|
||||||
table.loc[:, "Instance"] = table.loc[:,"Group"] + "/" + table.loc[:,"Instance"]
|
table.loc[:, "Instance"] = (
|
||||||
|
table.loc[:, "Group"] + "/" + table.loc[:, "Instance"]
|
||||||
|
)
|
||||||
table.loc[:, "Filename"] = f
|
table.loc[:, "Filename"] = f
|
||||||
tables += [table]
|
tables += [table]
|
||||||
benchmark = pd.concat(tables, sort=True)
|
benchmark = pd.concat(tables, sort=True)
|
||||||
@@ -168,16 +192,18 @@ def generate_chart():
|
|||||||
plt.figure(figsize=(12, 0.50 * k))
|
plt.figure(figsize=(12, 0.50 * k))
|
||||||
sns.set_style("whitegrid")
|
sns.set_style("whitegrid")
|
||||||
sns.set_palette("Set1")
|
sns.set_palette("Set1")
|
||||||
sns.barplot(y="Instance",
|
sns.barplot(
|
||||||
|
y="Instance",
|
||||||
x="Total time (s)",
|
x="Total time (s)",
|
||||||
color="tab:red",
|
color="tab:red",
|
||||||
capsize=0.15,
|
capsize=0.15,
|
||||||
errcolor="k",
|
errcolor="k",
|
||||||
errwidth=1.25,
|
errwidth=1.25,
|
||||||
data=benchmark);
|
data=benchmark,
|
||||||
|
)
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
print("Writing tables/benchmark.png")
|
print("Writing tables/benchmark.png")
|
||||||
plt.savefig("tables/benchmark.png", dpi=150);
|
plt.savefig("tables/benchmark.png", dpi=150)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user