Jelajahi Sumber

Created a Dynamic Structure DEVS model for benchmarking that dynamically goes from the LI model to the HI model

Snej69420 3 bulan lalu
induk
melakukan
c45ca08e4f
1 mengubah file dengan 108 tambahan dan 0 penghapusan
  1. 108 0
      devstone/CompareDSDEVS.py

+ 108 - 0
devstone/CompareDSDEVS.py

@@ -0,0 +1,108 @@
+#!/usr/bin/env python3
+"""
+Compares DEVStone benchmark results for different model types (LI, HI, HO, DynamicLIHI, etc.)
+based on varying width and depth.
+
+Input CSV format (same as original):
+  model_type, depth, width, run, creation_time, setup_time, simulation_time
+
+Produces:
+  - Scalability plots (Width & Depth)
+  - Overhead composition
+  - Summary statistics table
+"""
+
+import pandas as pd
+import matplotlib.pyplot as plt
+import seaborn as sns
+from pathlib import Path
+
+# === CONFIGURATION ===
+INPUT_FILE = "./Results-PyPDEVS/DEVSTONE-dynamic.csv"
+OUTPUT_DIR = Path("./Results-PyPDEVS")
+OUTPUT_DIR.mkdir(exist_ok=True)
+
+# === LOAD DATA ===
+data = pd.read_csv(INPUT_FILE)
+if "variant" not in data.columns:
+    data["variant"] = "Default"
+
+# Compute total time
+data["total_time"] = data["creation_time"] + data["setup_time"] + data["simulation_time"]
+
+# Aggregate mean & std
+agg = (
+    data.groupby(["model_type", "depth", "width"], as_index=False)
+    .agg({
+        "creation_time": ["mean", "std"],
+        "setup_time": ["mean", "std"],
+        "simulation_time": ["mean", "std"],
+        "total_time": ["mean", "std"],
+    })
+)
+agg.columns = ["_".join(col).rstrip("_") for col in agg.columns.values]
+
+sns.set_theme(style="whitegrid", font_scale=1.2)
+
+# === Scalability with Width ===
+for depth in sorted(agg["depth"].unique()):
+    subset = agg[agg["depth"] == depth]
+    plt.figure(figsize=(7, 5))
+    sns.lineplot(
+        data=subset, x="width", y="simulation_time_mean",
+        hue="model_type", marker="o"
+    )
+    plt.title(f"Scalability with Width – Depth {depth}")
+    plt.xlabel("Width (# submodels per level)")
+    plt.ylabel("Mean Simulation Time (s)")
+    plt.tight_layout()
+    plt.savefig(OUTPUT_DIR / f"scalability_width_depth{depth}.png")
+    plt.close()
+
+# === Scalability with Depth ===
+for width in sorted(agg["width"].unique()):
+    subset = agg[agg["width"] == width]
+    plt.figure(figsize=(7, 5))
+    sns.lineplot(
+        data=subset, x="depth", y="simulation_time_mean",
+        hue="model_type", marker="o"
+    )
+    plt.title(f"Scalability with Depth – Width {width}")
+    plt.xlabel("Depth (levels)")
+    plt.ylabel("Mean Simulation Time (s)")
+    plt.tight_layout()
+    plt.savefig(OUTPUT_DIR / f"scalability_depth_width{width}.png")
+    plt.close()
+
+# === Overhead Composition per Model Type ===
+comp = data.melt(
+    id_vars=["model_type", "depth", "width"],
+    value_vars=["creation_time", "setup_time", "simulation_time"],
+    var_name="phase",
+    value_name="time"
+)
+plt.figure(figsize=(9, 6))
+sns.barplot(
+    data=comp, x="model_type", y="time", hue="phase",
+    estimator="mean", errorbar="sd"
+)
+plt.title("Average Overhead Composition by Model Type")
+plt.ylabel("Mean time (s)")
+plt.tight_layout()
+plt.savefig(OUTPUT_DIR / "overhead_composition_models.png")
+plt.close()
+
+# === Summary Table ===
+summary = (
+    data.groupby("model_type", as_index=False)
+    .agg({
+        "creation_time": "mean",
+        "setup_time": "mean",
+        "simulation_time": "mean",
+        "total_time": "mean"
+    })
+    .sort_values("total_time")
+)
+summary.to_csv(OUTPUT_DIR / "summary_table.csv", index=False)
+
+print(f"\n✅ Analysis complete. Results saved in: {OUTPUT_DIR}/")