forked from cloudsimplus/cloudsimplus-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogarithmic_boxplot.py
More file actions
61 lines (49 loc) · 1.81 KB
/
logarithmic_boxplot.py
File metadata and controls
61 lines (49 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# Load all CSV files
input_dir = Path("results_csv/results_multiple_iterations_algorithm_smaller_aco")
csv_files = list(input_dir.glob("*.csv"))
# Collect all relevant data
stability_data = []
for file in csv_files:
df = pd.read_csv(file)
if df.empty or "ViolationPct" not in df.columns:
continue
# Extract algorithm base name and run id
df["RunId"] = df["Algorithm"].str.extract(r"times_(\d+)")
df["BaseAlgorithm"] = df["Algorithm"].str.extract(r"(^[^_]+)")
# Filter for SLA < 10%
df = df[df["ViolationPct"] < 10]
if df.empty:
continue
for run_id, group in df.groupby("RunId"):
if not group.empty:
min_power = group["PowerConsumption"].min()
base_name = group["BaseAlgorithm"].iloc[0]
stability_data.append({
"Algorithm": base_name,
"PowerConsumption": min_power
})
# Create DataFrame
stability_df = pd.DataFrame(stability_data)
# Ensure columns are correct
if not stability_df.empty and "Algorithm" in stability_df.columns:
# Plot boxplot (log scale)
plt.figure(figsize=(10, 6))
stability_df.boxplot(by="Algorithm", column="PowerConsumption", grid=True)
plt.yscale("log")
plt.title("Power Consumption Stability per Algorithm (SLA < 10%)")
plt.suptitle("")
plt.xlabel("Algorithm")
plt.ylabel("Power Consumption (W) [Log Scale]")
plt.tight_layout()
# Save
output_dir = Path("plots/boxplots")
output_dir.mkdir(parents=True, exist_ok=True)
plot_path = output_dir / "boxplot_power_stability_log_smaller_aco.png"
plt.savefig(plot_path)
plt.close()
print(f"✅ Boxplot saved to: {plot_path}")
else:
print("⚠ No valid SLA-compliant data found for plotting.")