L’objectif est d’analyser l’importance de la distribution du temps de service sur le temps de réponse dans une file d’attente M/GI/1 avec un ordonnancement LIFO. Le processus d’arrivée est un processus de Poisson de taux (débit), les clients ont un temps de service de moyenne 1 pris comme unité de temps de référence.

Simulation de la file LIFO

Pour cette partie, nous utilisons le code de Monsieur Arnaud Legrand (voir ci-dessous) :

set.seed(10)
library(plyr)
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.1.2
Service <- function(n=1,typeservice,x,y) {
# genere un temps de service
  switch(typeservice,
         det = rep(1,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) {
    # 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) # 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)
                                      )
        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()
      }
    }
    
    #tps=t2-t1
    df <- data.frame(N=n,TIME = t2-t1, LAMBDA = lambda, LAW = typeservice, POLICY = policy, LABEL = as.factor(paste(typeservice, "(", x, ",", y, ")", sep = "")))
   return (df)
}    

Q1 : Nature des lois de service

# nombres d'échantillons
sample=1:100
#Dataframe avec chaque service (det,uni,gamma et exp)
df = data.frame(service1=Service(100,typeservice = "det",0,0),service2=Service(100,typeservice = "uni",0,2),service3=Service(100,typeservice = "gamma",.2,5),service4=Service(100,typeservice = "exp",1,0))

Loi deterministe :

#affichage pour chaque service (courbe):
ggplot(data=df)+ geom_point(aes(x=sample,y=service1),color="red") + ylab("time of service") + ggtitle("Loi Deterministe")

plot of chunk unnamed-chunk-3

#affichage sous forme de barre : 
ggplot(data=df, aes(x = sample, y=service1,color="red")) +
  geom_bar(data=df$services1,stat="identity", position="identity") +geom_point() +  geom_line() + xlab("sample") + ylab("time of service")+ ggtitle("Loi Deterministe")

plot of chunk unnamed-chunk-3

mean(df$service1)
## [1] 1

Pour la loi deterministe : On peut voir que pour chaque valeur nous avons un temps de service de 1. Il est constant.

Loi Uniforme :

ggplot(data=df)+ geom_point(aes(x=sample,y=service2),color="yellow") + ylab("time of service") + ggtitle("Loi Uniforme")

plot of chunk unnamed-chunk-4

ggplot(data=df, aes(x = sample, y=service2,color="red")) +
  geom_bar(data=df$services2,stat="identity", position="identity") +geom_point() +  geom_line() + xlab("sample") + ylab("time of service")+ ggtitle("Loi Uniforme")