loosely-coupled-dss-extended/results/analysis4_scalability.R
2021-09-03 14:20:09 +02:00

112 lines
6.5 KiB
R

library("tidyverse")
library("ggthemes")
library("gridExtra")
library("patchwork")
library(RColorBrewer)
data=read_csv("results_scalability.csv")
r_=function(x){round(x,digits=1)}
color=function(){scale_fill_brewer(palette = "Accent")}
color2=function(){scale_fill_brewer(palette = "Set2")}
nolegend=function(){theme(legend.position="none")}
simkeys=unique(data$simkey)
nsimkeys=length(simkeys)
s_=function(x){if(x<0){return("")}else{return("+")}}
simkey_rename=function(key){
if(key=="hint")
return("Hints")
if(key=="baseline")
return("Baseline")
if(key=="extended")
return("Extended")
if(key=="hintandextended")
return("Hints+Extended")
return(key)
}
dformat=function(data){
data%>%rowwise()%>%mutate(simkey=simkey_rename(simkey))%>%mutate(wireless=ifelse(wireless=="lora","LoRa","Nb-IoT"))
}
g_legend <- function(a.gplot){
tmp <- ggplot_gtable(ggplot_build(a.gplot))
leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box")
legend <- tmp$grobs[[leg]]
legend
}
custom_theme=function(){theme_clean()+ theme(plot.background=element_blank())}
data=data%>%dformat()
# Compute delivery success
statsSuccess=data%>%filter(isSender!=0)%>%group_by(wireless,wakeupfor,n_nodes,seed,simkey)%>%summarize(success=mean(nSend))%>%ungroup()
data=data%>%left_join(statsSuccess,by=c("wireless","wakeupfor","n_nodes","seed","simkey"))
# Computer stats senders
statsSender=data%>%filter(isSender!=0)%>%group_by(wireless,wakeupfor,n_nodes,seed,simkey)%>%summarize(success=mean(success),energy=mean(energy))%>%ungroup()
statsSender=statsSender%>%group_by(wireless,wakeupfor,n_nodes,simkey)%>%summarize(success_sd=sd(success),success=mean(success),energy_sd=sd(energy),energy=mean(energy))%>%ungroup()
# Computer stats receiver
statsReceiver=data%>%filter(isSender==0)%>%group_by(wireless,wakeupfor,n_nodes,seed,simkey)%>%summarize(success=mean(success),energy=mean(energy))%>%ungroup()
statsReceiver=statsReceiver%>%group_by(wireless,wakeupfor,n_nodes,simkey)%>%summarize(success_sd=sd(success),success=mean(success),energy_sd=sd(energy),energy=mean(energy))%>%ungroup()
# Energy
sender60sPlotEnergy=ggplot(statsSender%>%filter(wakeupfor==60),aes(n_nodes,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Sender")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
sender180sPlotEnergy=ggplot(statsSender%>%filter(wakeupfor==180),aes(n_nodes,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Sender")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver60sPlotEnergy=ggplot(statsReceiver%>%filter(wakeupfor==60),aes(n_nodes,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Energy consumption (J)")+labs(colour="Policy") + custom_theme()+theme(legend.position="top")+ggtitle("Receiver")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver180sPlotEnergy=ggplot(statsReceiver%>%filter(wakeupfor==180),aes(n_nodes,energy,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=energy-energy_sd, ymax=energy+energy_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Energy consumption (J)")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+ggtitle("Receiver")+
guides(colour=FALSE,fill=guide_legend(title="Policy"))
# Success
sender60sPlotSuccess=ggplot(statsSender%>%filter(wakeupfor==60),aes(n_nodes,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
sender180sPlotSuccess=ggplot(statsSender%>%filter(wakeupfor==180),aes(n_nodes,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver60sPlotSuccess=ggplot(statsReceiver%>%filter(wakeupfor==60),aes(n_nodes,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Number of delivery success")+labs(colour="Policy") + custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
receiver180sPlotSuccess=ggplot(statsReceiver%>%filter(wakeupfor==180),aes(n_nodes,success,color=simkey,group=simkey))+
geom_ribbon(aes(ymin=success-success_sd, ymax=success+success_sd,fill=simkey),linetype=1,alpha=0.4)+
geom_point()+geom_line()+
facet_wrap(~wireless)+xlab("Number of node")+ylab("Number of delivery success")+labs(colour="Policy")+custom_theme()+theme(legend.position="top")+
theme(panel.background = element_rect(fill = '#EFEFEF', color=NA))+guides(colour=FALSE,fill=guide_legend(title="Policy"))
w=15
h=9
space=2
ggsave("scalability_60s.pdf",plot=(sender60sPlotEnergy+theme(plot.margin=unit(c(0.1,space,0,0),"cm"))+receiver60sPlotEnergy)/sender60sPlotSuccess+plot_layout(guides = 'collect')&theme(legend.position="bottom"),width=w,height=h)
ggsave("scalability_180s.pdf",plot=(sender180sPlotEnergy+theme(plot.margin=unit(c(0.1,space,0,0),"cm"))+receiver180sPlotEnergy)/sender180sPlotSuccess+plot_layout(guides = 'collect')&theme(legend.position="bottom"),width=w,height=h)