DES Queueing Model Help

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

DES Queueing Model Help

netlogohelpgmu
Hello,
 

 I am new to using NetLogo and I'm having some trouble with my model logic. I'm trying to figure out how to appropriately show delays in my model but I can't figure out where it's going wrong.
 

 I have pasted my code below and any feedback/advice woudl 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: DES Queueing Model Help

akaarm88
Maybe you already know this, so disregard if you do, but it would probably be a lot easier to do that in a program designed for discrete systems modeling. For example, ARENA https://www.arenasimulation.com/ allows you make those types of production line models really easily, including the time delays at each stage.
Reply | Threaded
Open this post in threaded view
|

Re: DES Queueing Model Help

westlife1002
In reply to this post by netlogohelpgmu
Hi, you might find a classic queueing model coded in Netlogo.

http://modelingcommons.org/browse/one_model/5086#model_tabs_browse_info

Netlogo is perfectly ok for modelling any sorts of queueing system (in fact
I just did one for London heathrow airport). You can flexibly choose whether
you want to simulate the system in discrete time or continious time.

Jie



--
Sent from: http://netlogo-users.18673.x6.nabble.com/