simple market random

No preview image

1 collaborator

Default-person Kashif Zia (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.0 • Viewed 191 times • Downloaded 27 times • Run 0 times
Download the 'simple market random' modelDownload this modelEmbed this model

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


WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)

Comments and Questions

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

Click to Run Model

extensions [table]
globals [stock]

breed [traders trader]
breed [shoppers shopper]

traders-own [mystock]
shoppers-own[mylist speed paces currstall lastpos]

to setup
  clear-all
  reset-ticks

  create-all-stocks
  create-all-traders
  layout-circle sort traders max-pxcor
  create-all-shoppers
end 

to create-all-stocks
  let x 0
  set stock table:make
  while [x < number-of-items][
    table:put stock x 0
    set x x + 1
  ]
  ;print stock
end 

to create-all-traders
  create-traders number-of-traders [
    set shape "house"
    set color red
    set mystock table:make
    set-mystock

    ;print mystock
    ;move-from-origin
  ]
end 

to set-mystock
  let x random 20
  let i 0
  while [i <= x][
    let y random 50
    let z (random 20) + 1
    table:put mystock y z
    set i i + 1
  ]
end 

to create-all-shoppers
  create-shoppers number-of-shoppers [
    set shape "default"
    set color green
    ;setxy random-pxcor random-pycor
    set mylist table:make
    set-mylist
    set speed random-float walking-speed + 0.001
    set paces 0
    set pen-mode "down"
    ;print mylist
  ]
  ask shoppers[
    let stall one-of traders
    set currstall stall
    face currstall
    while [ patch-here != [patch-here] of stall ] [ forward 0.05 * speed]
    set lastpos patch-here
  ]
end 

to set-mylist
  let x random 10
  let i 0
  while [i <= x][
    let y random 50
    let z (random 5) + 1
    table:put mylist y z
    set i i + 1
  ]
end 

to go
  if (count shoppers <= 0) [stop]
  ask shoppers with [table:length mylist > 0]
  [
    let stall one-of traders

    if stall != currstall [
      set currstall stall
      face currstall

      while [ patch-here != [patch-here] of stall ] [ forward 0.05 * speed]
      let stall-stock nobody
      ask stall [set stall-stock mystock]
      set paces distance lastpos
      set lastpos patch-here
      foreach ( table:keys mylist ) [
        [key] ->
        let n table:get mylist key
        if table:has-key? stall-stock key [
          let c table:get stall-stock key
          ifelse c >= n [table:put mylist key 0] [table:put mylist key n - c]
          ask stall [table:put mystock key (table:get mystock key - n)]
        ]
      ]
    ]
  ]
  clean-up
  tick
end 

to clean-up
  ask shoppers [
    foreach (table:keys mylist) [
      [key] ->
      if table:get mylist key <= 0 [table:remove mylist key]
    ]
    if table:length mylist = 0 [die]
  ]

    ask traders [
    foreach (table:keys mystock) [
      [key] ->
      if table:get mystock key <= 0 [table:remove mystock key]
    ]
    if table:length mystock = 0 [set color white]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to move-from-origin
  let free-patches patches with [pcolor = black and not any? traders-here and (pycor > min-pycor and pxcor < max-pxcor)]
  ifelse any? free-patches [
    move-to one-of free-patches
  ]
  [ die ]
end 

There is only one version of this model, created almost 4 years ago by Kashif Zia.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.