Discrete Event Simulation Help: Restaurant Queue

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Discrete Event Simulation Help: Restaurant Queue

netlogohelpgmu
Hello everyone! I am new to using NetLogo and I just want to create a DES for a restaurant queue. Currently, my model is not showing delays like I would like for it to be and I don't know why! I just want there to be delays between service stations, and I want the customers to not go through the line in one single tick!
 

 Any input/feedback would be appreciated.
 

 

 

 globals[
   ;;How long do customers wait in line?
   avg_wait
   max_wait
   total_wait
 

   ;;How long does it take to serve a customer?
   avg_servicetime
   total_served
 

   ;;How many people are waiting in line?
   arrivals
   queue_size
   max_queuesize
 

   ;;not sure what processed variable is for
   processed
 

   SERVER1_X ;;location of server 1
   SERVER1_Y
   SERVER1_SIZE
   SERVER2_X ;;location of server 2
   SERVER2_Y
   SERVER2_SIZE
   SERVER3_X ;;location of server 3
   SERVER3_Y
   SERVER3_SIZE
   SERVER4_X ;;location of server 4
   SERVER4_Y
   SERVER4_SIZE
   REGISTER_X ;;location of register
   REGISTER_Y
   REGISTER_SIZE
   MAX_QUEUE_SIZE
   service-time_one
   service-time_two
   service-time_three
   service-time_four
   service-time_five
 

   customer-ID-globals
 

 

 ]
 

 breed[servers server]
 breed[customers customer]
 

 customers-own[
   in-line? ;;if true, waiting to be served
   queue-position ;;what is his position in queue?
   total-customer-wait-time ;;how long has he been waiting
   customer-ID
   initial-time
   wait-time-one ;;from outside to station one
   wait-time-two ;;from station one to two
   wait-time-three ;;from station two to three
   wait-time-four ;;from station three to four
   wait-time-five ;;from station four to checkout
   
 

 

 ]
 

 servers-own[
  idle? ;;idle or not
  customers?
 ]
 

 to setup
   ca
  reset-ticks
  ;setting the globals
  set total_wait 0
  set queue_size 0
  set SERVER1_X -3
  set SERVER1_Y -1
  set SERVER1_SIZE 2
  set SERVER2_X -1
  set SERVER2_Y -1
  set SERVER2_SIZE 2
  set SERVER3_X 1
  set SERVER3_Y -1
  set SERVER3_SIZE 2
  set SERVER4_X 3
  set SERVER4_Y -1
  set SERVER4_SIZE 2
  set REGISTER_SIZE 2
  set REGISTER_X 5
  set REGISTER_Y -1
  set MAX_QUEUE_SIZE ( SERVER1_X - min-pxcor)
  set service-time_one random-poisson 5
  set service-time_two random-poisson 8
  set service-time_three random-poisson 12
  set service-time_four random-poisson 9
  set service-time_five random-poisson 10
 

  create-servers 1 [
    set idle? TRUE
    set customers? FALSE
    setxy (SERVER1_X) SERVER1_Y
    set size SERVER1_SIZE
    set shape "person"
    set color yellow
   ]
 

    create-servers 1 [
    set idle? TRUE
    setxy (SERVER2_X) SERVER2_Y
    set size SERVER2_SIZE
    set shape "person"
    set color yellow
   ]
 

    create-servers 1 [
    set idle? TRUE
    set customers? FALSE
    setxy (SERVER3_X) SERVER3_Y
    set size SERVER3_SIZE
    set shape "person"
    set color yellow
   ]
 

    create-servers 1 [
    set idle? TRUE
    set customers? FALSE
    setxy (SERVER4_X) SERVER4_Y
    set size SERVER4_SIZE
    set shape "person"
    set color yellow
   ]
 

   create-servers 1 [
    set idle? TRUE
    set customers? FALSE
     setxy REGISTER_X REGISTER_Y
     set size REGISTER_SIZE
     set shape "person"
     set color blue
   ]
 

 

 

 end
 to create-customer
   crt 1 [set breed customers        
     set in-line? TRUE
     set queue-position (queue_size + 8)
     set total-customer-wait-time 0
     set wait-time-one 0
     set wait-time-two 0
     set wait-time-three 0
     set wait-time-four 0
     set wait-time-five 0
     set shape "person"
     ifelse (queue_size > MAX_QUEUE_SIZE) [hide-turtle] [
     setxy (SERVER1_X - queue_size) (SERVER1_Y + 1)
     ;;move-to one-of patches with [pcolor = red]
     set customer-ID-globals  customer-ID-globals + 1   ;; every time we create a turtle will be increasing by 1
      set customer-ID  customer-ID-globals
       set initial-time ticks
     ]
 

   ]
 end
 

 to update_variables
   ;;what variables to update
 increase_wait_time ;; update wait time for all turtles
 ;; How to update average wait time
    ifelse (queue_size != 0) [
    set avg_wait (total_wait / queue_size)
   ][set avg_wait 0]
 ;;
 end
 

 to process
   set processed random-poisson process_mean
 ;;How to do continuous processing after the customer has moved past the first station
 repeat processed [
 process_customer_hello
 decrease_customer_position
 process_customer_1_to_2
 decrease_customer_position
 process_customer_2_to_3
 decrease_customer_position
 process_customer_3_to_4
 process_customer_farewell
 decrease_customer_position
 set queue_size (queue_size - 1)
 ]
 end
 

 to process_customer_hello
 ask customers with [queue-position = 8] [
     set wait-time-one ticks - initial-time ;; wait time spent to reach first server
     set total-customer-wait-time total-customer-wait-time + wait-time-one
 

 ;;set total_wait (total_wait + wait-time)
 if (total-customer-wait-time > max_wait) [set max_wait total-customer-wait-time]
     ifelse(any? customers with [xcor = SERVER2_X]) [set total-customer-wait-time total-customer-wait-time + service-time_two]
     [ set queue-position (queue-position - 1)
       ]
 ]
       ifelse (queue_size = 0)
    [ ask servers with [xcor = SERVER1_X ] [ set idle? TRUE] ]
   [ ask servers with [xcor = SERVER1_X] [ set idle? FALSE] ]
 

 end
 

 to process_customer_1_to_2
 ask customers with [queue-position = 6] [
     
 set wait-time-two ticks - service-time_two ;; wait time spent to reach second server
 set total-customer-wait-time total-customer-wait-time + wait-time-two
     
 

 if (total-customer-wait-time > max_wait) [set max_wait total-customer-wait-time]
      ifelse(any? customers with [xcor = SERVER3_X]) [set total-customer-wait-time total-customer-wait-time + service-time_three]
     [ set queue-position (queue-position - 1)
       ]
   ]
       ifelse (queue_size = 0)
    [ ask servers with [xcor = SERVER2_X ] [ set idle? TRUE] ]
   [ ask servers with [xcor = SERVER2_X ] [ set idle? FALSE] ]
 

 end
 

 to process_customer_2_to_3
 ask customers with [queue-position = 4] [
 set wait-time-three ticks - service-time_three
     set total-customer-wait-time total-customer-wait-time + wait-time-three
 ;;set total_wait (total_wait + wait-time)
 if (total-customer-wait-time > max_wait) [set max_wait total-customer-wait-time]
     ifelse(any? customers with [xcor = SERVER4_X]) [set total-customer-wait-time total-customer-wait-time + service-time_four]
     [ set queue-position (queue-position - 1)
       ]
     
   ]
       ifelse (queue_size = 0)
    [ ask servers with [xcor = SERVER3_X ] [ set idle? TRUE] ]
   [ ask servers with [xcor = SERVER3_X ] [ set idle? FALSE] ]
 

 end
 

 to process_customer_3_to_4
 ask customers with [queue-position = 2] [
 set total-customer-wait-time total-customer-wait-time + wait-time-four
     set total-customer-wait-time total-customer-wait-time + wait-time-four
 ;;set total_wait (total_wait + wait-time)
 if (total-customer-wait-time > max_wait) [set max_wait total-customer-wait-time]
     ifelse(any? customers with [xcor = REGISTER_X]) [set total-customer-wait-time total-customer-wait-time + service-time_five]
     [ set queue-position (queue-position - 1)
       ]
   ]
       ifelse (queue_size = 0)
    [ ask servers with [xcor = SERVER4_X ] [ set idle? TRUE] ]
   [ ask servers with [xcor = SERVER4_X ] [ set idle? FALSE] ]
   
 

 end
 

 to process_customer_farewell
 ask customers with [queue-position = 0] [
 set in-line? FALSE
 set total-customer-wait-time total-customer-wait-time + wait-time-five
     set total-customer-wait-time total-customer-wait-time + wait-time-five
 ;;set total_wait (total_wait + wait-time)
 if (total-customer-wait-time > max_wait) [set max_wait total-customer-wait-time]
 die
 ]
     ifelse (queue_size = 0)
    [ ask servers with [xcor = REGISTER_X ] [ set idle? TRUE] ]
   [ ask servers with [xcor = REGISTER_X ] [ set idle? FALSE] ]
   
     ifelse(any? customers with [xcor = REGISTER_X])[ ask servers with [xcor = REGISTER_X ] [set customers? TRUE]]
     [ ask servers with [xcor = REGISTER_X ] [set customers? FALSE]]
 end
 

 

 ;;moves customer down the line
 to decrease_customer_position
 

   ask customers with [queue-position = (MAX_QUEUE_SIZE + 1) ] [
     show-turtle
     setxy  (REGISTER_X - MAX_QUEUE_SIZE) (REGISTER_Y + 1)
   ]
 

     foreach sort-on [queue-position] customers [ [?1] ->           ;; sorting turtles by ascending queue size and asking each of them
     ask  ?1 [                     ;; only for in-line turtles
       set queue-position (queue-position - 1)
       setxy (xcor + 1) ycor
     ]
   ]
 

   ask customers with[queue-position < 0] [
     die
   ]
 end
 

 to increase_wait_time
 ;ask customers with [in-line?][
 ;set wait-time (wait-time + 1)
 ;]
 end
 

 to arrive
   set arrivals (random-poisson arrival_mean)
   repeat arrivals[
     create-customer
     set queue_size (queue_size + 1)
   ]
 end
 

 to go
   arrive
   process
   set total_wait sum [total-customer-wait-time ] of customers
   update_variables
 

   tick
   if ticks >= 36000 [stop]
 end
 

Reply | Threaded
Open this post in threaded view
|

Re: Discrete Event Simulation Help: Restaurant Queue

Nicolas Payette-2
On 29 Nov 2017 18:22, "[hidden email] [netlogo-users]" <
[hidden email]> wrote:

>
>
> Hello everyone! I am new to using NetLogo and I just want to create a DES
> for a restaurant queue. Currently, my model is not showing delays like I
> would like for it to be and I don't know why! I just want there to be
> delays between service stations, and I want the customers to not go through
> the line in one single tick!
>
>
> Any input/feedback would be appreciated.
>
>
>
>
> globals[
>
>   ;;How long do customers wait in line?
>
>   avg_wait
>
>   max_wait
>
>   total_wait
>
>
>   ;;How long does it take to serve a customer?
>
>   avg_servicetime
>
>   total_served
>
>
>   ;;How many people are waiting in line?
>
>   arrivals
>
>   queue_size
>
>   max_queuesize
>
>
>   ;;not sure what processed variable is for
>
>   processed
>
>
>   SERVER1_X ;;location of server 1
>
>   SERVER1_Y
>
>   SERVER1_SIZE
>
>   SERVER2_X ;;location of server 2
>
>   SERVER2_Y
>
>   SERVER2_SIZE
>
>   SERVER3_X ;;location of server 3
>
>   SERVER3_Y
>
>   SERVER3_SIZE
>
>   SERVER4_X ;;location of server 4
>
>   SERVER4_Y
>
>   SERVER4_SIZE
>
>   REGISTER_X ;;location of register
>
>   REGISTER_Y
>
>   REGISTER_SIZE
>
>   MAX_QUEUE_SIZE
>
>   service-time_one
>
>   service-time_two
>
>   service-time_three
>
>   service-time_four
>
>   service-time_five
>
>
>   customer-ID-globals
>
>
>
> ]
>
>
> breed[servers server]
>
> breed[customers customer]
>
>
> customers-own[
>
>   in-line? ;;if true, waiting to be served
>
>   queue-position ;;what is his position in queue?
>
>   total-customer-wait-time ;;how long has he been waiting
>
>   customer-ID
>
>   initial-time
>
>   wait-time-one ;;from outside to station one
>
>   wait-time-two ;;from station one to two
>
>   wait-time-three ;;from station two to three
>
>   wait-time-four ;;from station three to four
>
>   wait-time-five ;;from station four to checkout
>
>
>
>
>
> ]
>
>
> servers-own[
>
>  idle? ;;idle or not
>
>  customers?
>
> ]
>
>
> to setup
>
>   ca
>
>  reset-ticks
>
>  ;setting the globals
>
>  set total_wait 0
>
>  set queue_size 0
>
>  set SERVER1_X -3
>
>  set SERVER1_Y -1
>
>  set SERVER1_SIZE 2
>
>  set SERVER2_X -1
>
>  set SERVER2_Y -1
>
>  set SERVER2_SIZE 2
>
>  set SERVER3_X 1
>
>  set SERVER3_Y -1
>
>  set SERVER3_SIZE 2
>
>  set SERVER4_X 3
>
>  set SERVER4_Y -1
>
>  set SERVER4_SIZE 2
>
>  set REGISTER_SIZE 2
>
>  set REGISTER_X 5
>
>  set REGISTER_Y -1
>
>  set MAX_QUEUE_SIZE ( SERVER1_X - min-pxcor)
>
>  set service-time_one random-poisson 5
>
>  set service-time_two random-poisson 8
>
>  set service-time_three random-poisson 12
>
>  set service-time_four random-poisson 9
>
>  set service-time_five random-poisson 10
>
>
>  create-servers 1 [
>
>    set idle? TRUE
>
>    set customers? FALSE
>
>    setxy (SERVER1_X) SERVER1_Y
>
>    set size SERVER1_SIZE
>
>    set shape "person"
>
>    set color yellow
>
>   ]
>
>
>    create-servers 1 [
>
>    set idle? TRUE
>
>    setxy (SERVER2_X) SERVER2_Y
>
>    set size SERVER2_SIZE
>
>    set shape "person"
>
>    set color yellow
>
>   ]
>
>
>    create-servers 1 [
>
>    set idle? TRUE
>
>    set customers? FALSE
>
>    setxy (SERVER3_X) SERVER3_Y
>
>    set size SERVER3_SIZE
>
>    set shape "person"
>
>    set color yellow
>
>   ]
>
>
>    create-servers 1 [
>
>    set idle? TRUE
>
>    set customers? FALSE
>
>    setxy (SERVER4_X) SERVER4_Y
>
>    set size SERVER4_SIZE
>
>    set shape "person"
>
>    set color yellow
>
>   ]
>
>
>   create-servers 1 [
>
>    set idle? TRUE
>
>    set customers? FALSE
>
>     setxy REGISTER_X REGISTER_Y
>
>     set size REGISTER_SIZE
>
>     set shape "person"
>
>     set color blue
>
>   ]
>
>
>
>
> end
>
> to create-customer
>
>   crt 1 [set breed customers
>
>     set in-line? TRUE
>
>     set queue-position (queue_size + 8)
>
>     set total-customer-wait-time 0
>
>     set wait-time-one 0
>
>     set wait-time-two 0
>
>     set wait-time-three 0
>
>     set wait-time-four 0
>
>     set wait-time-five 0
>
>     set shape "person"
>
>     ifelse (queue_size > MAX_QUEUE_SIZE) [hide-turtle] [
>
>     setxy (SERVER1_X - queue_size) (SERVER1_Y + 1)
>
>     ;;move-to one-of patches with [pcolor = red]
>
>     set customer-ID-globals  customer-ID-globals + 1   ;; every time we
> create a turtle will be increasing by 1
>
>      set customer-ID  customer-ID-globals
>
>       set initial-time ticks
>
>     ]
>
>
>   ]
>
> end
>
>
> to update_variables
>
>   ;;what variables to update
>
> increase_wait_time ;; update wait time for all turtles
>
> ;; How to update average wait time
>
>    ifelse (queue_size != 0) [
>
>    set avg_wait (total_wait / queue_size)
>
>   ][set avg_wait 0]
>
> ;;
>
> end
>
>
> to process
>
>   set processed random-poisson process_mean
>
> ;;How to do continuous processing after the customer has moved past the
> first station
>
> repeat processed [
>
> process_customer_hello
>
> decrease_customer_position
>
> process_customer_1_to_2
>
> decrease_customer_position
>
> process_customer_2_to_3
>
> decrease_customer_position
>
> process_customer_3_to_4
>
> process_customer_farewell
>
> decrease_customer_position
>
> set queue_size (queue_size - 1)
>
> ]
>
> end
>
>
> to process_customer_hello
>
> ask customers with [queue-position = 8] [
>
>     set wait-time-one ticks - initial-time ;; wait time spent to reach
> first server
>
>     set total-customer-wait-time total-customer-wait-time + wait-time-one
>
>
> ;;set total_wait (total_wait + wait-time)
>
> if (total-customer-wait-time > max_wait) [set max_wait
> total-customer-wait-time]
>
>     ifelse(any? customers with [xcor = SERVER2_X]) [set
> total-customer-wait-time total-customer-wait-time + service-time_two]
>
>     [ set queue-position (queue-position - 1)
>
>       ]
>
> ]
>
>       ifelse (queue_size = 0)
>
>    [ ask servers with [xcor = SERVER1_X ] [ set idle? TRUE] ]
>
>   [ ask servers with [xcor = SERVER1_X] [ set idle? FALSE] ]
>
>
> end
>
>
> to process_customer_1_to_2
>
> ask customers with [queue-position = 6] [
>
>
>
> set wait-time-two ticks - service-time_two ;; wait time spent to reach
> second server
>
> set total-customer-wait-time total-customer-wait-time + wait-time-two
>
>
>
>
> if (total-customer-wait-time > max_wait) [set max_wait
> total-customer-wait-time]
>
>      ifelse(any? customers with [xcor = SERVER3_X]) [set
> total-customer-wait-time total-customer-wait-time + service-time_three]
>
>     [ set queue-position (queue-position - 1)
>
>       ]
>
>   ]
>
>       ifelse (queue_size = 0)
>
>    [ ask servers with [xcor = SERVER2_X ] [ set idle? TRUE] ]
>
>   [ ask servers with [xcor = SERVER2_X ] [ set idle? FALSE] ]
>
>
> end
>
>
> to process_customer_2_to_3
>
> ask customers with [queue-position = 4] [
>
> set wait-time-three ticks - service-time_three
>
>     set total-customer-wait-time total-customer-wait-time + wait-time-three
>
> ;;set total_wait (total_wait + wait-time)
>
> if (total-customer-wait-time > max_wait) [set max_wait
> total-customer-wait-time]
>
>     ifelse(any? customers with [xcor = SERVER4_X]) [set
> total-customer-wait-time total-customer-wait-time + service-time_four]
>
>     [ set queue-position (queue-position - 1)
>
>       ]
>
>
>
>   ]
>
>       ifelse (queue_size = 0)
>
>    [ ask servers with [xcor = SERVER3_X ] [ set idle? TRUE] ]
>
>   [ ask servers with [xcor = SERVER3_X ] [ set idle? FALSE] ]
>
>
> end
>
>
> to process_customer_3_to_4
>
> ask customers with [queue-position = 2] [
>
> set total-customer-wait-time total-customer-wait-time + wait-time-four
>
>     set total-customer-wait-time total-customer-wait-time + wait-time-four
>
> ;;set total_wait (total_wait + wait-time)
>
> if (total-customer-wait-time > max_wait) [set max_wait
> total-customer-wait-time]
>
>     ifelse(any? customers with [xcor = REGISTER_X]) [set
> total-customer-wait-time total-customer-wait-time + service-time_five]
>
>     [ set queue-position (queue-position - 1)
>
>       ]
>
>   ]
>
>       ifelse (queue_size = 0)
>
>    [ ask servers with [xcor = SERVER4_X ] [ set idle? TRUE] ]
>
>   [ ask servers with [xcor = SERVER4_X ] [ set idle? FALSE] ]
>
>
>
>
> end
>
>
> to process_customer_farewell
>
> ask customers with [queue-position = 0] [
>
> set in-line? FALSE
>
> set total-customer-wait-time total-customer-wait-time + wait-time-five
>
>     set total-customer-wait-time total-customer-wait-time + wait-time-five
>
> ;;set total_wait (total_wait + wait-time)
>
> if (total-customer-wait-time > max_wait) [set max_wait
> total-customer-wait-time]
>
> die
>
> ]
>
>     ifelse (queue_size = 0)
>
>    [ ask servers with [xcor = REGISTER_X ] [ set idle? TRUE] ]
>
>   [ ask servers with [xcor = REGISTER_X ] [ set idle? FALSE] ]
>
>
>
>     ifelse(any? customers with [xcor = REGISTER_X])[ ask servers with
> [xcor = REGISTER_X ] [set customers? TRUE]]
>
>     [ ask servers with [xcor = REGISTER_X ] [set customers? FALSE]]
>
> end
>
>
>
> ;;moves customer down the line
>
> to decrease_customer_position
>
>
>   ask customers with [queue-position = (MAX_QUEUE_SIZE + 1) ] [
>
>     show-turtle
>
>     setxy  (REGISTER_X - MAX_QUEUE_SIZE) (REGISTER_Y + 1)
>
>   ]
>
>
>     foreach sort-on [queue-position] customers [ [?1] ->           ;;
> sorting turtles by ascending queue size and asking each of them
>
>     ask  ?1 [                     ;; only for in-line turtles
>
>       set queue-position (queue-position - 1)
>
>       setxy (xcor + 1) ycor
>
>     ]
>
>   ]
>
>
>   ask customers with[queue-position < 0] [
>
>     die
>
>   ]
>
> end
>
>
> to increase_wait_time
>
> ;ask customers with [in-line?][
>
> ;set wait-time (wait-time + 1)
>
> ;]
>
> end
>
>
> to arrive
>
>   set arrivals (random-poisson arrival_mean)
>
>   repeat arrivals[
>
>     create-customer
>
>     set queue_size (queue_size + 1)
>
>   ]
>
> end
>
>
> to go
>
>   arrive
>
>   process
>
>   set total_wait sum [total-customer-wait-time ] of customers
>
>   update_variables
>
>
>   tick
>
>   if ticks >= 36000 [stop]
>
> end
>
>
>
>