| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #!/usr/bin/env python3
- import os
- import argparse
- import pandas as pd
- import matplotlib.pyplot as plt
- from pathlib import Path
- def load_and_filter(csv_path, fixed_param, fixed_value):
- """Load a CSV file and filter rows by the fixed parameter."""
- df = pd.read_csv(csv_path)
- df = df[df[fixed_param] == fixed_value]
- return df
- def process_files(csv_files, fixed_param, fixed_value):
- """Combine and average simulation times by the varying parameter."""
- results = {}
- varying_param = "depth" if fixed_param == "width" else "width"
- for path in csv_files:
- df = load_and_filter(path, fixed_param, fixed_value)
- # Average simulation times for identical setups
- grouped = df.groupby(varying_param, as_index=False)["simulation_time"].mean()
- results[path.parent.name + "-" + path.stem] = grouped
- return results, varying_param
- def plot_results(results, varying_param, fixed_param, fixed_value, name):
- plt.figure(figsize=(8, 6))
- for label, df in results.items():
- plt.plot(df[varying_param], df["simulation_time"], marker='o', label=label)
- plt.title(f"Average Simulation Time vs {varying_param.capitalize()} (fixed {fixed_param}={fixed_value})")
- plt.xlabel(varying_param.capitalize())
- plt.ylabel("Average Simulation Time")
- plt.legend()
- plt.grid(True)
- path = "../Plots/"
- output_name = f"{name}_{fixed_param}_{fixed_value}.png"
- plt.tight_layout()
- plt.savefig(path + output_name, dpi=300)
- print(f"✅ Saved plot as {output_name}")
- def main():
- parser = argparse.ArgumentParser(description="Compare simulation results from multiple CSV files.")
- parser.add_argument("csv_files", nargs="+", type=Path, help="Paths to the result CSV files.")
- parser.add_argument("-n", "--name", default="DEVS", type=str, help="Name of the output file.")
- group = parser.add_mutually_exclusive_group(required=True)
- group.add_argument("-w", "--width", type=int, help="Fixed width value.")
- group.add_argument("-d", "--depth", type=int, help="Fixed depth value.")
- args = parser.parse_args()
- if args.width is not None:
- fixed_param, fixed_value = "width", args.width
- else:
- fixed_param, fixed_value = "depth", args.depth
- results, varying_param = process_files(args.csv_files, fixed_param, fixed_value)
- plot_results(results, varying_param, fixed_param, fixed_value, args.name)
- if __name__ == "__main__":
- main()
|