set.seed(10)
library(plyr)
library(ggplot2)
library(reshape)
## 
## Attaching package: 'reshape'
## 
## The following objects are masked from 'package:plyr':
## 
##     rename, round_any
library(gridExtra)
## Loading required package: grid
Service <- function(n=1,typeservice,x,y,p_det=1) {
# genere un temps de service
  switch(typeservice,
         det = rep(p_det,n),
         uni = runif(n,x,y),
         gamma = rgamma(n,shape=x,scale=y),
         exp = rexp(n,x)
         )
}

FileLIFO <- function(n,lambda,typeservice,x,y,policy,p_det) {
    # simulates a M/GI/1 LIFO queue with different preemption policy
    # parameters:
    #    n :  total number of jobs
    #    lambda : arrival rate
    #    typeservice : service law (det uni gamma exp)
    #    x ,y : parameters of the service law
    #    policy: npmtn, pmtn, pmtn_restart, pmtn_reset
    # return value:
    #    vector with response time of each task assuming the queue is initially empty
    
    A <- rexp(n,lambda)         # inter arrival
    t1 <- cumsum(A)             # arrival dates
    t2 <- rep(NA,n)             # completion dates
    S <- Service(n,typeservice,x,y,p_det) # initial service times
    
    #### Variables that define the state of the queue
    t = 0               # current time
    remaining = rep(NA,n)  # how much work remains to do for each task
    running = NA        # index of the currently running task
    waiting = c()       # stack with tasks which have arrived and have not been completed yet
    next_arrival = 1    # index of the next task to arrive
    
    #### A few useful local functions 
    run_task = function() { # runs the last task of the waiting list
      if(length(waiting)>0) {
        running <<- waiting[length(waiting)]
        remaining[running] <<- switch(policy,
                                      npmtn = S[running],
                                      pmtn = min(S[running],remaining[running],na.rm=T),
                                      pmtn_restart = S[running],
                                      pmtn_reset = Service(1,typeservice,x,y,p_det)
                                      )
        waiting <<- waiting[-length(waiting)]
      }
    }

    push_task = function() { # insert the next_arrival-th task to the waiting list
                             # and run it if there is preemption
      if(policy != "npmtn") {
        if(!is.na(running)) {waiting <<- c(waiting,running)}
        running <<- NA
      }
      waiting <<- c(waiting,next_arrival)
      next_arrival <<- next_arrival+1 
      if(is.na(running)) { run_task() }
    }

    #### Main simulation loop
    while(TRUE) { 
      # Look for next event
      dt = NA
      if(next_arrival <=n) { dt = min(dt,(t1[next_arrival]-t), na.rm=T) }
      if(!is.na(running))  { dt = min(dt,remaining[running], na.rm=T)   }
      if(is.na(dt)) { break }
      
      # Update state
      t=t+dt
      if(!is.na(running)) {
        remaining[running] <- remaining[running] - dt
        if(remaining[running]<=0) {
          t2[running] <- t
          running = NA
          run_task()
        }
      }
      if((next_arrival<=n) & (t==t1[next_arrival])) {
        push_task()
      }
    }
   
    
#     df<-data.frame(response_time=t2-t1,service=S)
#     df$id=1:length(df$response_time)
#     d <- melt(df$response_time,id=c("id"))

#   
#     list(jobs = df, events = data.frame(date=date,count=count),
#          workevolution = data.frame(date=datework,work=work))
# # print(t2-t1)
  t2-t1
}    

Q1:Nature des lois de service Illustrer les différences de natures entre les différentes lois de temps de service. Réponse: Pour observer les différentes comportements des quatre lois plus raisonnablement, on observera 1000 échantillions dont les expérences de temps de service théoriques sont 0.2,0.4,0.6,0.8 pour chacune loi. Et on va appécier leurs espérences et leurs variance de temps de réponse pour chacune policie.

#Pour la loi determinist
###################################################################
#0.2
p111<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="npmtn",p_det=0.2)
p112<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn",p_det=0.2)
p113<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_restart",p_det=0.2)
p114<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_reset",p_det=0.2)
#0.4
p121<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="npmtn",p_det=0.4)
p122<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn",p_det=0.4)
p123<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_restart",p_det=0.4)
p124<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_reset",p_det=0.4)
#0.6
p131<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="npmtn",p_det=0.6)
p132<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn",p_det=0.6)
p133<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_restart",p_det=0.6)
p134<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_reset",p_det=0.6)
#0.8
p141<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="npmtn",p_det=0.8)
p142<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn",p_det=0.8)
p143<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_restart",p_det=0.8)
p144<-FileLIFO(n=1000,lambda=1,typeservice="det",x=0,y=1,policy="pmtn_reset",p_det=0.8)
##################################################################

#Pour la loi uniform
##################################################################
#0.2
p211<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.4,policy="npmtn")
p212<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.4,policy="pmtn")
p213<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.4,policy="pmtn_restart")
p214<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.4,policy="pmtn_reset")
#0.4
p221<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.8,policy="npmtn")
p222<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.8,policy="pmtn")
p223<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.8,policy="pmtn_restart")
p224<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=0.8,policy="pmtn_reset")
#0.6
p231<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.2,policy="npmtn")
p232<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.2,policy="pmtn")
p233<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.2,policy="pmtn_restart")
p234<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.2,policy="pmtn_reset")
#0.8
p241<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.6,policy="npmtn")
p242<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.6,policy="pmtn")
p243<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.6,policy="pmtn_restart")
p244<-FileLIFO(n=1000,lambda=1,typeservice="uni",x=0,y=1.6,policy="pmtn_reset")
################################################################## 

#Pour la loi gamma
##################################################################
#0.2
p311<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.2,y=1,policy="npmtn")
p312<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.2,y=1,policy="pmtn")
p313<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.2,y=1,policy="pmtn_restart")
p314<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.2,y=1,policy="pmtn_reset")
#0.4
p321<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.4,y=1,policy="npmtn")
p322<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.4,y=1,policy="pmtn")
p323<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.4,y=1,policy="pmtn_restart")
p324<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.4,y=1,policy="pmtn_reset")
#0.6
p331<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.6,y=1,policy="npmtn")
p332<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.6,y=1,policy="pmtn")
p333<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.6,y=1,policy="pmtn_restart")
p334<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.6,y=1,policy="pmtn_reset")
#0.8
p341<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.8,y=1,policy="npmtn")
p342<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.8,y=1,policy="pmtn")
p343<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.8,y=1,policy="pmtn_restart")
p344<-FileLIFO(n=1000,lambda=1,typeservice="gamma",x=0.8,y=1,policy="pmtn_reset")
##################################################################

#Pour la loi exponentiel
##################################################################
#0.2
p411<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=5,y=1,policy="npmtn")
p412<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=5,y=1,policy="pmtn")
p413<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=5,y=1,policy="pmtn_restart")
p414<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=5,y=1,policy="pmtn_reset")
#0.4
p421<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=2.5,y=1,policy="npmtn")
p422<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=2.5,y=1,policy="pmtn")
p423<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=2.5,y=1,policy="pmtn_restart")
p424<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=2.5,y=1,policy="pmtn_reset")
#0.6
p431<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/6,y=1,policy="npmtn")
p432<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/6,y=1,policy="pmtn")
p433<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/6,y=1,policy="pmtn_restart")
p434<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/6,y=1,policy="pmtn_reset")
#0.8
p441<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/8,y=1,policy="npmtn")
p442<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/8,y=1,policy="pmtn")
p443<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/8,y=1,policy="pmtn_restart")
p444<-FileLIFO(n=1000,lambda=1,typeservice="exp",x=10/8,y=1,policy="pmtn_reset")
##################################################################
dd1<-data.frame(det=c(mean(p111),mean(p121),mean(p131),mean(p141)),uni=c(mean(p211),mean(p221),mean(p231),mean(p241)),gamma=c(mean(p311),mean(p321),mean(p331),mean(p341)),exp=c(mean(p411),mean(p421),mean(p431),mean(p441)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c1<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("Average Response Time") + 
  ggtitle("Average Response time for law:npmtn")
#######################################################
dd1<-data.frame(det=c(var(p111),var(p121),var(p131),var(p141)),uni=c(var(p211),var(p221),var(p231),var(p241)),gamma=c(var(p311),var(p321),var(p331),var(p341)),exp=c(var(p411),var(p421),var(p431),var(p441)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c2<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Average Service Time") +
  ylab("variance of Response Time") + 
  ggtitle("Variance of Response time for law:npmtn")
grid.arrange(c2,c1,as.table = TRUE,main="Evaluation for npmtn")

##################################################################
#pmtn
dd1<-data.frame(det=c(mean(p112),mean(p122),mean(p132),mean(p142)),uni=c(mean(p212),mean(p222),mean(p232),mean(p242)),gamma=c(mean(p312),mean(p322),mean(p332),mean(p342)),exp=c(mean(p412),mean(p422),mean(p432),mean(p442)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c1<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("Average Response Time") + 
  ggtitle("Average Response time for law: pmtn")
############################################################
dd1<-data.frame(det=c(var(p112),var(p122),var(p132),var(p142)),uni=c(var(p212),var(p222),var(p232),var(p242)),gamma=c(var(p312),var(p322),var(p332),var(p342)),exp=c(var(p412),var(p422),var(p432),var(p442)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c2<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("variance of Response Time") + 
  ggtitle("Variance of Response time for law:pmtn")
grid.arrange(c2,c1,as.table = TRUE,main="Evaluation for pmtn")

##################################################################
#pmtn_restart
dd1<-data.frame(det=c(mean(p113),mean(p123),mean(p133),mean(p143)),uni=c(mean(p213),mean(p223),mean(p233),mean(p243)),gamma=c(mean(p313),mean(p323),mean(p333),mean(p343)),exp=c(mean(p413),mean(p423),mean(p433),mean(p443)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c1<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("Average Response Time") + 
  ggtitle("Average Response time for law: pmtn_restart")
##################################################################
dd1<-data.frame(det=c(var(p113),var(p123),var(p133),var(p143)),uni=c(var(p213),var(p223),var(p233),var(p243)),gamma=c(var(p313),var(p323),var(p333),var(p343)),exp=c(var(p413),var(p423),var(p433),var(p443)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c2<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("variance of Response Time") + 
  ggtitle("Variance of Response time for law:pmtn_restart")
grid.arrange(c2,c1,as.table = TRUE,main="Evaluation for pmtn_restart")

##################################################################
#pmtn_reset
dd1<-data.frame(det=c(mean(p114),mean(p124),mean(p134),mean(p144)),uni=c(mean(p214),mean(p224),mean(p234),mean(p244)),gamma=c(mean(p314),mean(p324),mean(p334),mean(p344)),exp=c(mean(p414),mean(p424),mean(p434),mean(p444)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c1<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("Average Response Time") + 
  ggtitle("Average Response time for law: pmtn_reset")
######################################################
dd1<-data.frame(det=c(var(p114),var(p124),var(p134),var(p144)),uni=c(var(p214),var(p224),var(p234),var(p244)),gamma=c(var(p314),var(p324),var(p334),var(p344)),exp=c(var(p414),var(p424),var(p434),var(p444)))
dd1$id=c(0.2,0.4,0.6,0.8)
d <- melt(dd1,id=c("id"))
c2<-ggplot(data=d[d$variable %in% c("det","uni","gamma","exp"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Theoretical Average Service Time") +
  ylab("variance of Response Time") + 
  ggtitle("Variance of Response time for law:pmtn_reset")
grid.arrange(c2,c1,as.table = TRUE,main="Evaluation for pmtn_reset")

Selon les graphes illustrés au dessous, on voit que:

  1. La loi deterministe a un bon comportement général presque pour toutes policies et paramètres observées sauf dans le cas où le débit d’arrivée est proche de capacité de traitement de serveut et la policie de préemption_reset, autrement dit, c’est une loi plus stable et plus efficace par rapport aux temps de réponse pour servir aux clients de tous cas si un serveur peut comporter comme ça théoriquement.D’ailleurs, elle est la meilleur choix pour la policie non préemption.

  2. La loi uniforme comporte prèsque la même que la loi précédant, sauf que dans le cas où le débit s’approche à la capacité de traiter les arrivées. Et en gros, les deux lois ne sont pas les meilleurs choix pour la policie de préemption_reset et non plus pour les haut débit d’arrivées.Mais elle est la meilleur choix pour la policie préemption restart.

  3. La loi gamma ne serait pas une bonne choix pour les policies non préemption et préemption restart puisqu’elle a le temps de service moyen plus long et se varie très brutalement. Mais surtout elle serait une bonne solution pour la policie préemption reset et préemption resume et elle est la meilleur choix pour la dernière.

  4. La loi exponentiel ne serait pas une solution préférable pour tous les cas sauf la policie préemption_reset car elle a un temps de réponse très long et une variance importante. Pour la policie préemption reset, on recommanderait exp et gamma autant préférablement.

Q2:Étude détaillée de la file M/M/1 − LIF O Étudier la distribution stationnaire du temps de réponse pour différents débit d’arrivées (par exemple λ = 0.2, 0.4, 0.6, 0.8) pour la file M/M/1 − LIFO (i.e., avec un temps de service et d’inter-arrivée exponentiel) pour chacun des modes de gestion. Vous représenterez sur un même graphique votre estimation des temps moyens de service en fonction du débit d’arrivée avec une couleur différente pour chacun des modes de gestion. Vous étudierez la stabilité du système, ses performances, les similarités et/ou les différences de comportement observés…

#Pour la loi determinist
###################################################################
getPara<-function(df=dc,pp=1)
  {
  
  df$jobs$id=1:length(df$jobs$arrival)
  df$jobs$response_time = df$jobs$completion-df$jobs$arrival
  d <- melt(df$jobs,id=c("id"))
  df$jobs$response_time
  }

#Pour la loi exponentiel
##################################################################

r411<-FileLIFO(n=1000,lambda=0.2,typeservice="exp",x=1,y=1,policy="pmtn")
# r411<-getPara(df=dc)
r412<-FileLIFO(n=1000,lambda=0.4,typeservice="exp",x=1,y=1,policy="pmtn")
# r412<-getPara(df=dc)
r413<-FileLIFO(n=1000,lambda=0.6,typeservice="exp",x=1,y=1,policy="pmtn")
# r413<-getPara(df=dc)
r414<-FileLIFO(n=1000,lambda=0.8,typeservice="exp",x=1,y=1,policy="pmtn")
# r414<-getPara(df=dc)

##########################
r421<-FileLIFO(n=1000,lambda=0.2,typeservice="exp",x=1,y=1,policy="pmtn_restart")
# r421<-getPara(df=dc)
r422<-FileLIFO(n=1000,lambda=0.4,typeservice="exp",x=1,y=1,policy="pmtn_restart")
# r422<-getPara(df=dc)
r423<-FileLIFO(n=1000,lambda=0.6,typeservice="exp",x=1,y=1,policy="pmtn_restart")
# r423<-getPara(df=dc)
r424<-FileLIFO(n=1000,lambda=0.8,typeservice="exp",x=1,y=1,policy="pmtn_restart")
# r424<-getPara(df=dc)
##########################
r431<-FileLIFO(n=1000,lambda=0.2,typeservice="exp",x=1,y=1,policy="pmtn_reset")
# r431<-getPara(df=dc)
r432<-FileLIFO(n=1000,lambda=0.4,typeservice="exp",x=1,y=1,policy="pmtn_reset")
# r432<-getPara(df=dc)
r433<-FileLIFO(n=1000,lambda=0.6,typeservice="exp",x=1,y=1,policy="pmtn_reset")
# r433<-getPara(df=dc)
r434<-FileLIFO(n=1000,lambda=0.8,typeservice="exp",x=1,y=1,policy="pmtn_reset")
# r434<-getPara(df=dc)
##################################################################
dd1<-data.frame(pmtn=r411,pmtn_restart=r421,pmtn_reset=r431)
dd1$id=1:length(dd1$pmtn)
d <- melt(dd1,id=c("id"))
ggplot(data=d[d$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Job Id") +
  ylab("Response Time") + 
  ggtitle("Response time for debit: 0.2")

print(paste("Average response time for pmtn is:",round(mean(dd1$pmtn),digits=5)))
## [1] "Average response time for pmtn is: 1.32624"
print(paste("Average response time for pmtn_restart is:",round(mean(dd1$pmtn_restart),digits=5)))
## [1] "Average response time for pmtn_restart is: 1.69664"
print(paste("Average response time for pmtn_reset is:",round(mean(dd1$pmtn_reset),digits=5)))
## [1] "Average response time for pmtn_reset is: 1.29505"
######################
dd2<-data.frame(pmtn=r412,pmtn_restart=r422,pmtn_reset=r432)
dd2$id=1:length(dd2$pmtn)
d <- melt(dd2,id=c("id"))
ggplot(data=d[d$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Job Id") +
  ylab("Response Time") + 
  ggtitle("Response time for debit: 0.4")

print(paste("Average response time for pmtn is:",round(mean(dd2$pmtn),digits=5)))
## [1] "Average response time for pmtn is: 1.65902"
print(paste("Average response time for pmtn_restart is:",round(mean(dd2$pmtn_restart),digits=5)))
## [1] "Average response time for pmtn_restart is: 7.30852"
print(paste("Average response time for pmtn_reset is:",round(mean(dd2$pmtn_reset),digits=5)))
## [1] "Average response time for pmtn_reset is: 1.5263"
#########################
dd3<-data.frame(pmtn=r413,pmtn_restart=r423,pmtn_reset=r433)
dd3$id=1:length(dd3$pmtn)
d <- melt(dd3,id=c("id"))
ggplot(data=d[d$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Job Id") +
  ylab("Response Time") + 
  ggtitle("Response time for debit: 0.6")

print(paste("Average response time for pmtn is:",round(mean(dd3$pmtn),digits=5)))
## [1] "Average response time for pmtn is: 2.50614"
print(paste("Average response time for pmtn_restart is:",round(mean(dd3$pmtn_restart),digits=5)))
## [1] "Average response time for pmtn_restart is: 44.52492"
print(paste("Average response time for pmtn_reset is:",round(mean(dd3$pmtn_reset),digits=5)))
## [1] "Average response time for pmtn_reset is: 2.34695"
###########################
dd4<-data.frame(pmtn=r414,pmtn_restart=r424,pmtn_reset=r434)
dd4$id=1:length(dd4$pmtn)
d <- melt(dd4,id=c("id"))
ggplot(data=d[d$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Job Id") +
  ylab("Response Time") + 
  ggtitle("Response time for debit: 0.8")

print(paste("Average response time for pmtn is:",round(mean(dd4$pmtn),digits=5)))
## [1] "Average response time for pmtn is: 5.82814"
print(paste("Average response time for pmtn_restart is:",round(mean(dd4$pmtn_restart),digits=5)))
## [1] "Average response time for pmtn_restart is: 210.82953"
print(paste("Average response time for pmtn_reset is:",round(mean(dd4$pmtn_reset),digits=5)))
## [1] "Average response time for pmtn_reset is: 3.27038"
##############
ff<-data.frame(pmtn=c(mean(r411),mean(r412),mean(r413),mean(r414)),pmtn_restart=
                       c(mean(r421),mean(r422),mean(r423),mean(r424)),
              pmtn_reset=c(mean(r431),mean(r432),mean(r433),mean(r434)))
ff$id=1:4
g <- melt(ff,id=c("id"))
ggplot(data=g[d$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("ave response") +
  ylab("Policy") + 
  ggtitle("Average response time")

###################
kk<-data.frame(pmtn=c(var(r411),var(r412),var(r413),var(r414)),pmtn_restart=
                       c(var(r421),var(r422),var(r423),var(r424)),
              pmtn_reset=c(var(r431),var(r432),var(r433),var(r434)))
kk$id=1:4
h <- melt(kk,id=c("id"))
ggplot(data=h[h$variable %in% c("pmtn","pmtn_restart","pmtn_reset"),],
       aes(x=id,y=value, color=variable)) + 
  geom_line(size=1) + scale_color_brewer(palette="Set1") +
  xlab("Response Time variance") +
  ylab("Policy") + 
  ggtitle("Response time variance")

Selon les graphes générés au-dessus, on voit que pour la policy de préemption résume et préemption reset, ils ont prèsque les mêmes comportements par rapport à l’espérence et la variance sauf préemption restart. Pmtn restart se varie toujours plus brutalement que les deux autres à cause de son mécanisme restart tout d’au début chaque fois au moment où il reprend. Donc danc ce cas là, les deux précédents se comportent plus stable et au fur et au mesure, le temps de réponse pour les clients arrivants maintiennent un taux stationnaire. par contre, on ne pourrait jamais imaginer qu’un système de modèle de “préemption_restart” soit stable ou stationnaire comme il y a une probabilité plus important que le serveur serait “occupé” en servant aux clients qui viennent de reprendre son boulot avec le même temps.

Question 3. Étude de la file M/GI/1 − LIF O Tracer le temps moyen de réponse en fonction de λ pour les différentes lois proposées et les différents modes de gestion ci-dessus. Vous choisirez 2 valeurs pour la famille des lois Gamma. Vous étudierez la stabilité du système, ses performances, les similarités et/ou les différences de comportement observés…