Child of Mumbai-Dabbawala-Main

No preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Child of model Mumbai-Dabbawala-Main preview imageMumbai-Dabbawala-Main
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.0 • Viewed 75 times • Downloaded 7 times • Run 0 times
Download the 'Child of Mumbai-Dabbawala-Main' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals
[
  grid-x-inc           ;; the amount of patches in between two roads in the x direction
  grid-y-inc           ;; the amount of patches in between two roads in the y direction
  roads                ;; agentset containing the patches that are roads
  colors
  tiffins-count
  set-capacity
  delivery-cors
  index
  delivery-strategy
  done?
  x-cor
  y-cor
  delay
  time-taken
]

breed [dabbawalas dabbawala ]
breed [stations station ]
breed [tiffins tiffin ]

dabbawalas-own [ capacity carrying-count my-tiffins next-target aloted?]
stations-own [ name ]
tiffins-own [  tiffin-dest-cor picked? delivered?]

;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

to setup [ station-name dw-capacity tiffins-to-deliver main-delivery-cors delivery-strategies ]
  clear-all
  setup-globals dw-capacity tiffins-to-deliver main-delivery-cors delivery-strategies
  setup-roads
  setup-stations station-name
  setup-dabbawalas
  setup-tiffins
  initialize-my-tiffins
  reset-ticks
end 

;; Initialize the global variables to appropriate values

to setup-globals [ dw-capacity tiffins-to-deliver main-delivery-cors delivery-strategies ]
  set grid-x-inc world-width / 21
  set grid-y-inc world-height / 21
  set set-capacity dw-capacity
  set tiffins-count tiffins-to-deliver
  set delivery-cors main-delivery-cors
  set index 0
  set done? False
  set delivery-strategy delivery-strategies
  set delay 0
  set time-taken 0
end 

to setup-roads
  ;; initialize the patch-owned variables and color the patches to a base-color
  ask patches
  [
    set pcolor brown
    if random 100 < 5
    [ set pcolor green - 1 ]
  ]
  ;; initialize the global variables that hold patch agentsets
  set roads patches with
    [(floor((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) or
    (floor((pycor + max-pycor) mod grid-y-inc) = 0)]
  ask roads [ set pcolor black ]
end 

to setup-stations [ station-name ]
  create-stations 1 [
    let xy one-of patches with [pxcor != [pxcor] of roads and pycor != [pycor] of roads]
    setxy [pxcor] of xy [pycor] of xy
    set shape "house two story"
    set size 2
    set name station-name
    set label name
]
end 

to setup-dabbawalas
  let dw-count ceiling ( tiffins-count / set-capacity )
  create-dabbawalas dw-count [
    set shape "dabbawala"
    set color white
    set size 3
    set my-tiffins 0
    set color white
    set aloted? False
    set capacity set-capacity
    setxy [pxcor] of one-of stations [pycor] of one-of stations
  ]
end 

to setup-tiffins
  create-tiffins tiffins-count [
    set shape "dabba"
    set size 3
    set tiffin-dest-cor item index delivery-cors
    set index index + 1
    hide-turtle
    ifelse delivery-strategy = "regional-closest-first"
    [ setxy item 0 tiffin-dest-cor item 1 tiffin-dest-cor ]
    [ setxy [pxcor] of one-of stations [pycor] of one-of stations ]
    set delivered? False
    set picked? False
  ]
end 

to initialize-my-tiffins
  ask dabbawalas
  [
    ifelse count tiffins with [not picked?]> set-capacity
    [
      if delivery-strategy = "random" or delivery-strategy = "closest-first"
      [ set my-tiffins n-of ceiling ( count tiffins with [not picked?]/ count dabbawalas with [not aloted?] ) (tiffins with [not picked?]) ]
      if delivery-strategy = "regional-closest-first"
      [ set my-tiffins min-n-of ceiling ( count tiffins with [not picked?]/ count dabbawalas with [not aloted?] ) (tiffins with [not picked?])[distance myself] ]
    ]
    [ set my-tiffins n-of count tiffins with [not picked?] (tiffins with [not picked?]) ]
    ask my-tiffins
    [
      set picked? True
      setxy [pxcor] of one-of stations [pycor] of one-of stations
    ]
    set carrying-count count my-tiffins
    set aloted? True
  ]
end 

to go
  if count dabbawalas with [ hidden? ] = 1
  [ set delay ticks ]
  if not any? dabbawalas with [ not hidden? ]
  [ stop-condition ]
  ask dabbawalas
  [
  ifelse carrying-count = 0
    [ hide-turtle ]
    [ deliver-lunchboxes
   set label carrying-count ]
  ]
  tick
end 

;;;;;;;;;;;;;;;;;;;;;;
;;   Go Procedures  ;;
;;;;;;;;;;;;;;;;;;;;;;

to stop-condition
  set delay ticks - delay
  if time-taken = 0
  [ set time-taken ticks ]
  set done? True
end 

to deliver-lunchboxes
  if next-target = 0
  [ select-next-target ]
  if next-target != nobody
  [
    set x-cor item 0 [ tiffin-dest-cor ] of next-target
    set y-cor item 1 [ tiffin-dest-cor ] of next-target
    move-towards-target
    if any? patches with [ pxcor = x-cor and pycor = y-cor ] in-radius 2
    [
      drop-lunchbox
      set next-target 0
      set carrying-count carrying-count - 1
    ]
  ]
end 

to select-next-target
  if delivery-strategy = "random"
  [ set next-target one-of my-tiffins with [ not delivered? ]]
  if delivery-strategy = "closest-first" or delivery-strategy = "regional-closest-first"
  [
    set next-target min-one-of my-tiffins with [ not delivered? ]
    [ distance one-of patches with [pxcor = item 0 [ tiffin-dest-cor ] of myself and pycor = item 1 [ tiffin-dest-cor ] of myself] ]
  ]
end 

to move-towards-target
  let speed ( set-capacity + 1 - carrying-count ) / ( 5 * set-capacity )
  let to-move neighbors with [ pcolor = black]
  let to-face min-one-of to-move [ distance one-of patches with [pxcor = x-cor and pycor = y-cor] ]
  face to-face
  fd speed
end 

to drop-lunchbox
  ask next-target
  [
    setxy x-cor y-cor
    show-turtle
    set delivered? True
  ]
end 

There is only one version of this model, created almost 5 years ago by Sai Tanya Kumbharageri.

Attached files

No files

Parent: Mumbai-Dabbawala-Main

This model does not have any descendants.

Graph of models related to 'Child of Mumbai-Dabbawala-Main'