forked from zeinaboualbahim-commits/SE-Optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimization-function.cpp
More file actions
75 lines (69 loc) · 3.39 KB
/
Copy pathoptimization-function.cpp
File metadata and controls
75 lines (69 loc) · 3.39 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <algorithm>
using namespace std;
static vector<Device> rankDevices(vector<Device> devices) {
sort(devices.begin(), devices.end(), [](Device& a, Device& b) {
return a.getEnergyConsumed() > b.getEnergyConsumed();
});
return devices;
}
void optimizeEnergy(vector<Device>& devices, double threshold) {
if (devices.empty()) {
cout << "\n[!] No devices found. Please add devices first.\n";
return;
}
cout << "\n╔══════════════════════════════════════════╗" << endl;
cout << "║
ENERGY OPTIMIZATION REPORT
║" << endl;
cout << "╚══════════════════════════════════════════╝" << endl;
cout << " Threshold per device: " << threshold << " kWh/day\n" << endl;
int warningCount = 0;
//
── Per-device analysis ──────────────────────────────────
for (Device& d : devices) {
double consumption = d.getEnergyConsumed();
cout << "--------------------------------------------" << endl;
cout << "Device : " << d.name << endl;
cout << "Power Rating : " << d.powerRating << " kW" << endl;
cout << "Hours/Day : " << d.hoursUsed << " hrs" << endl;
cout << "Consumption : " << consumption << " kWh/day" << endl;
if (consumption > threshold) {
double excess = consumption - threshold;
double safeHours = threshold / d.powerRating;
cout << "Status : *** HIGH CONSUMPTION ***" << endl;
cout << "Recommendation:" << endl;
cout << " -> Exceeds threshold by " << excess << " kWh/day." << endl;
cout << " -> Reduce daily use to " << safeHours
<< " hrs/day to stay within limit." << endl;
warningCount++;
} else {
cout << "Status : OK — within safe range" << endl;
}
cout << endl;
}
//
── Summary banner ───────────────────────────────────────
cout << "============================================" << endl;
cout << " SUMMARY" << endl;
cout << "============================================" << endl;
if (warningCount == 0) {
cout << " All devices are within the recommended threshold." << endl;
cout << " Great job! No changes needed." << endl;
} else {
cout << " " << warningCount << " device(s) exceed the threshold." << endl;
cout << " See recommendations above to reduce consumption." << endl;
}
cout << "\n Devices ranked by consumption (highest first):" << endl;
cout << " ------------------------------------------------" << endl;
vector<Device> ranked = rankDevices(devices);
int rank = 1;
for (Device& d : ranked) {
cout << " " << rank++ << ". " << d.name
<< " — " << d.getEnergyConsumed() << " kWh/day";
if (d.getEnergyConsumed() > threshold)
cout << " [!]";
cout << endl;
}
cout << "============================================\n" << endl;
}