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 90 times • Downloaded 6 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
  done?
  tiffins-dest-list
  tiffins-collected
  model-station
  tiffins-count
  set-capacity
  collect-strategy
  delay
  time-taken
]

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

dabbawalas-own [ capacity carrying-count my-tiffins target-tiffin at-station? going-to-station? aloted?]
stations-own [ name ]
tiffins-own [ tiffin-start tiffin-dest tiffin-dest-cor chosen? ]

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

to setup [ station-name dw-capacity tiffins-count-per-area collect-strategies]
  clear-all
  setup-globals dw-capacity tiffins-count-per-area collect-strategies
  setup-roads
  set model-station station-name
  setup-stations station-name
  setup-dabbawalas
  setup-tiffins station-name
  if collect-strategy = "regional-equi-load"
  or collect-strategy = "regional-max-capacity"
  [ setup-my-tiffins ]
  reset-ticks
end 

;; Initialize the global variables to appropriate values

to setup-globals [ dw-capacity tiffins-count-per-area collect-strategies ]
  set grid-x-inc world-width / 21
  set grid-y-inc world-height / 21
  set colors [ red blue green pink yellow white brown grey orange lime turquoise sky violet magenta ]
  set done? False
  set tiffins-dest-list []
  set set-capacity dw-capacity
  set tiffins-count tiffins-count-per-area
  set collect-strategy collect-strategies
  set delay 0
  set time-taken 0
end 

to setup-roads
  ask patches
  [
    set pcolor brown
    if random 100 < 5
    [ set pcolor green - 1 ]
  ]
  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 [
    let xy one-of roads
    setxy [pxcor] of xy [pycor] of xy
    set shape "dabbawala"
    set color white
    set size 3
    set going-to-station? false
    set at-station? false
    set my-tiffins 0
    set target-tiffin 0
    set aloted? False
    let index who - 1
    set color item index colors
    set capacity set-capacity ]
end 

to setup-tiffins [ station-name ]
  create-tiffins tiffins-count [
    set shape "dabba"
    set size 3
    set color black
    set chosen? false
    move-to one-of patches with [pcolor = brown]
    set tiffin-dest-cor one-of patches with [ pcolor = brown ]
    set tiffin-start station-name
  ]
end 

to setup-my-tiffins
  ask dabbawalas
  [
    let dabbawala-color color
    ifelse count tiffins with [color = black]> set-capacity
    [
      if collect-strategy = "regional-equi-load"
      [ set my-tiffins min-n-of ceiling ( count tiffins with [color = black] / count dabbawalas with [ not aloted? ] ) (tiffins with [color = black]) [ distance myself ] ]
      if collect-strategy = "regional-max-capacity"
      [ set my-tiffins min-n-of ceiling ( count tiffins / count dabbawalas ) (tiffins with [color = black]) [ distance myself ] ]
    ]
    [ set my-tiffins min-n-of count tiffins with [color = black] (tiffins with [color = black]) [ distance myself ] ]
    ask my-tiffins
    [
      set color dabbawala-color
    ]
    set aloted? True
  ]
end 

to go
  if count dabbawalas with [ at-station? ] = 1
  [ set delay ticks ]
  if not any? dabbawalas with [not at-station?]
  [ stop-condition  ]
  ask dabbawalas with [not at-station? and going-to-station?]
  [ go-to-station ]
  ask dabbawalas with [not at-station? and not going-to-station?]
  [
    ifelse carrying-count < set-capacity and count tiffins with [not hidden?] > 0
    [ collect-tiffins ]
    [ set going-to-station? true ]
  ]
  tick
end 

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

to stop-condition
  set delay ticks - delay
  if time-taken = 0
  [ set time-taken ticks ]
  set tiffins-collected tiffins with [ any? stations in-radius 4 ]
  ask tiffins-collected
  [
    set tiffins-dest-list lput ( list [pxcor] of tiffin-dest-cor [pycor] of tiffin-dest-cor)  tiffins-dest-list
  ]
  set done? True
  stop
end 

to collect-tiffins
  if target-tiffin = 0 or [hidden?] of target-tiffin
  [ choose-next-target ]
  if target-tiffin != nobody
  [ collect-target ]
end 

to go-to-station
  ask dabbawalas with [ not at-station? and going-to-station? ]
  [
    let speed ( set-capacity + 1 - carrying-count ) / 16
    let to-move neighbors with [ pcolor = black ]
    face min-one-of to-move [ distance one-of [ stations ] of myself ]
    fd speed
    if any? stations in-radius 2
    [
      set going-to-station? false
      set at-station? true
    ]
  ]
end 

to choose-next-target
  let my-color color
  (ifelse collect-strategy = "regional-equi-load"
    or collect-strategy = "regional-max-capacity"
    [ set target-tiffin min-one-of tiffins with [not chosen? and color = my-color ] [distance myself ]]
    collect-strategy = "serial"
    [ set target-tiffin min-one-of tiffins with [not chosen? ] [distance myself ]]
    collect-strategy = "random"
    [ set target-tiffin one-of tiffins with [not chosen? ]])
  ifelse target-tiffin = nobody
  [ set going-to-station? true ]
  [
    ask target-tiffin
    [ set chosen? true ]
  ]
end 

to collect-target
  let speed ( set-capacity + 1 - carrying-count ) / ( 5 * set-capacity )
  let to-move neighbors with [ pcolor = black]
  face min-one-of to-move [ distance [ target-tiffin ] of myself ]
  fd speed
  let tiffins-taken one-of tiffins in-radius 2 with [not hidden?]
  if tiffins-taken != nobody and tiffins-taken = target-tiffin
  [
    set target-tiffin 0
    set carrying-count carrying-count + 1
    ask tiffins-taken
    [
      hide-turtle
      create-link-with myself [tie]
    ]
  ]
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'