Collaborative Diffusion Demo

No preview image

1 collaborator

Default-person Natalie Murray (Author)

Tags

(This model has yet to be categorized with any tags)
Model group MAM-2013 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 916 times • Downloaded 104 times • Run 0 times
Download the 'Collaborative Diffusion Demo' 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?

This model is a demonstration of simple emergent behavior from collaborative diffusion. It is part of a series of models (along with the Pac-Man NetLogo and HubNet activities) designed to teach middle and high school students about path finding, computer science, agent based modeling, and simple game artificial intelligentce. Collaborative diffusion is a path-finding technique where based off of simple rules, multiple agents, called ghosts, work together to find a goal. The goal gives off a scent that diffuse through the 'world' and ghosts follow the gradient of the scent. The 'collaborative' part comes in because the ghosts dampen the scent where they are on the map, thus discouraging ghosts from following the same path. Try out the different configurations to see how they work together! There are three configurations where you can watch the ghosts try to find the star- Three Aisle versions 1 and 2, and Maze.

HOW IT WORKS

The goal (star) diffuses a scent to the patches, called the diffusion value. The ghosts (purple) try to follow the scent to reach the goal. The scent does not diffuse through walls (green). The scent is represented by the orange colors- white represents a strong scent, and the darker orange sections have a weaker scent. At each tick, the ghosts move toward the highest scent (so brightest color). Collaboration emerges from the dampening of diffusion values. When the diffusion values are calculated, parts of the world with ghosts have diffusion values of zero, which lowers all surrounding diffusion values. You will see that the area surrounding ghosts is a little darker- this is why, and it encourages ghosts to take different paths.

HOW TO USE IT

For Three Aisle, Three Aisle- v2, and Maze: choose the configuration, press setup, then press go. Make sure that updates are set on ticks and that the speed bar is slowed down.

For Draw mode: Set configuration to Draw and make sure view updates are set to continuous. Then clear the screen. To draw the maze, select the draw-maze button and click on the view window to place green tile. The erase button clears patches when you click on them. To add ghosts, use the add-ghosts button and click on the screen to place the ghost. To add the goal, use the add-goal button. When the maze is complete select load-maze. The delete-agents button deletes any turtles you click on. To run the maze once it's finished, click load-maze and then press go. Note that draw-maze, erase, add-goal, add-ghosts, and delete-agent are forever buttons, so you need to unclick them before clicking another button.

THINGS TO NOTICE

The orange represents how strong the scent is. Dark orange represents a weak scent, and the color gets brighter as the scent gets stronger (so it is white at the maximum scent). Note that the ghosts always move in the direction of the brightest color at every tick. Also note that the area surrounding ghosts is darker, and that the area under ghosts is black since ghosts block the scent. This is what encourages the ghosts to take a different path when confronted with multiple routes to take.

In the Three Aisle configurations the ghosts all take different paths to reach the goal once they approach the aisles because ofthe dampened diffusion scents. You can see the scent being blocked once ghosts enter an aisle- the cooridor behind the ghost darkens since the scent does not diffuse past the ghost/walls.

In the maze note how the ghosts travelling through corridors can block off entire regions. Note that because of collaborative diffusion they all take different paths.

THINGS TO TRY

For the Three Aisle and Maze configurations, try toggling the collaborative diffusion switch and see what happens.

Try drawing your own maze and see what kind of situations are best suited for collaborative diffusion. Try mixing narrow cooridors with wide open spaces, or any other combination, and see what happens.

EXTENDING THE MODEL

Try adding the capability for multiple goals or add more default configuarions.

RELATED MODELS

The ants model may be of interest, as it also incorporates the diffuse function.

For collaborative diffusion, see the Pac-Man (collaborative diffusion) and PacMan-HubNet models.

CREDITS AND REFERENCES

For collaborative diffusion, see: http://www.cs.colorado.edu/~ralex/papers/PDF/OOPSLA06antiobjects.pdf

Comments and Questions

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

Click to Run Model

breed [ goal star ] ;;the goal
breed [ ghosts pentagon ] ;;agents searching for goal

patches-own [
  dif-val] ;;diffusion values

globals [stop?] ;;true when simulation is complete

to setup
  if config  != "Draw" [
    ca]
  
  if config = "Three Aisle" [import-world "Three-Aisle.csv"]
  if config = "Three Aisle- v2" [import-world "Three-Aisle-v2.csv"]
  if config = "Maze" [import-world "Maze.csv"]
  if config != "Draw"
  [
  ask ghosts [set color violet]
  initialize-diffusion-values
  set stop? false
  while [neighbor-check] [set-diffusion-values] ;;diffuse until the neighbors of the ghosts have
                                                ;;nonzero diffusion values
  repeat 5 [set-diffusion-values]
  ]
  reset-ticks
end 

to-report neighbor-check ;;return true if neighbors have diffusion values of zero
  let x true
  ask ghosts [if sum [dif-val] of neighbors4 > 0 [set x false]]
  report x
end 

to make-ghost [x y] 
  create-ghosts 1 [
    set color violet
    setxy x y
    set heading 90
  ]
end 

to go
  if stop? [stop]
  move-turtles
  set-diffusion-values
  tick
end 

;;COLLABORATIVE DIFFUSION CODE

to initialize-diffusion-values ;;set patches' dif-val to 0, set goal-patch dif-val to 1000 
  ask patches [set dif-val 0] 
  ask goal [ask patch-here [set dif-val 1000]]  
end 

to set-diffusion-values
  
  ;;make sure patches with ghosts on them have diffusion values of zero
  ask patches[if collaboration? [if any? ghosts-on self [set dif-val 0]]]
  
  diffuse4 dif-val 1 ;;diffuse scent
  
  ;;set dif-val of patches with ghosts and green patches to 0
  ask patches[
    if collaboration? [if any? ghosts-on self [set dif-val 0]]
    if pcolor = green [set dif-val 0]
  ]
  
  ask goal [ask patch-here [set dif-val 1000]] ;;update goal patch dif-val
  
  ;;visualize scent
  let min-log-dif min [log-val] of patches with [ dif-val > 0 ]
  let max-log-dif max [log-val] of patches with [ dif-val > 0 ]
  ask patches [
    ifelse dif-val != 0 
      [set pcolor scale-color orange log-val min-log-dif max-log-dif ]
      [if pcolor != green [set pcolor black]]
  ]
end 

to-report log-val 
  report log (dif-val) 10
end 

to move-turtles
  
  ask goal [if any? ghosts-on patch-here [
    set color yellow
    set stop? true]] ;;stop simulation once goal is reached
  
  if stop? [stop]
  
  ;;move to patch with highest dif-val
  ask ghosts [
    let target max-one-of neighbors4 with 
    [not any? ghosts-here and pcolor != green]
    [dif-val]
    if target != nobody [
      set heading towards target
      fd 1]
  ]
end 

;;MAZE-DRAW CODE- this code is pretty self explanatory

to draw-maze
  if config = "Draw"[
  if mouse-down?
  [ask patch mouse-xcor mouse-ycor
    [set pcolor green]
  ]]
end 

to erase
  if config = "Draw" [
  if mouse-down?
  [ask patch mouse-xcor mouse-ycor
    [set pcolor black]
  ]]
end 

to clear
  if config = "Draw" [ca]
end 

to load-maze
  if config = "Draw" [
  initialize-diffusion-values
  set stop? false
  while [neighbor-check] [set-diffusion-values]
  repeat 5 [set-diffusion-values]
  reset-ticks ]
end 

to add-ghosts 
  if config = "Draw" [
  if mouse-down? and not any? ghosts-on patch round mouse-xcor round mouse-ycor
  [create-ghosts 1 [
    set color violet
    setxy round mouse-xcor round mouse-ycor
    set heading 270 ]
  ]]
end 

to add-goal
  if config = "Draw" [
  if mouse-down? and not any? goal-on patch round mouse-xcor round mouse-ycor
  [create-goal 1 [
    set color blue
    set shape "star"
    setxy round mouse-xcor round mouse-ycor
    set heading 270]
  ]]
end 

to delete-agent
  if config = "Draw" [
    if mouse-down?
    [ask turtles with [xcor = (round mouse-xcor) and ycor = (round mouse-ycor)] [die]]]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Natalie Murray over 11 years ago Final Version Download this version
Natalie Murray over 11 years ago Fixed set-diffusion-values Download this version
Natalie Murray over 11 years ago Initial upload Download this version

Attached files

File Type Description Last updated
Collaborative Diffusion Instructor Guide.pdf background Instructor Guide over 11 years ago, by Natalie Murray Download
Collaborative Diffusion Student Guide.pdf background Student Guide over 11 years ago, by Natalie Murray Download
Draw.csv data Sample file for draw mode, include in project directory over 11 years ago, by Natalie Murray Download
Final Paper Natalie Murray.pdf background Final Paper over 11 years ago, by Natalie Murray Download
Final Project Proposal.pdf background Project Proposal over 11 years ago, by Natalie Murray Download
Maze.csv data Maze configuration, final version. over 11 years ago, by Natalie Murray Download
Natalie_Murray_Poster.pdf pdf Poster over 11 years ago, by Natalie Murray Download
NatalieMurray_5June2013.pptx powerpoint Poster Slam Slides over 11 years ago, by Natalie Murray Download
NatalieMurrayProgressReport3June2013.pdf pdf Progress Report, 3 June 2013 over 11 years ago, by Natalie Murray Download
Three-Aisle-v2.csv data Three-Aisle-v2, final version over 11 years ago, by Natalie Murray Download
Three-Aisle.csv data Three-Aisle configuration, final version over 11 years ago, by Natalie Murray Download

This model does not have any ancestors.

This model does not have any descendants.