-
Notifications
You must be signed in to change notification settings - Fork 1
/
energy.awk
39 lines (39 loc) · 924 Bytes
/
energy.awk
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
BEGIN {
initialenergy = 1000
n=11
maxenergy=0
totalenergy=0
}
{
# Trace line format: energy
event = $1
if (event == "r" || event == "D" || event == "s"|| event == "f") {
node_id = $3
energy=$14
}
if (event=="N"){
node_id = $5
energy=$7
}
# Store remaining energy
finalenergy[node_id]=energy
}
END {
# Compute consumed energy for each node
for (i=0;i<n;i=i+1) {
consumenergy[i]=initialenergy-finalenergy[i]
totalenergy += consumenergy[i]
if(maxenergy<consumenergy[i]){
maxenergy=consumenergy[i]
}
}
#compute average energy
averagenergy=totalenergy/n
#output
for (i=0; i<n; i++) {
print("node",i, consumenergy[i])
}
print("average",averagenergy)
print("total energy",totalenergy)
print("max energy consumed",maxenergy)
}