Dijkstra's Shortest Path Algorithm

Dijkstra's Shortest Path Algorithm preview image

1 collaborator

Default-person Ron Schildge (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.2 • Viewed 174 times • Downloaded 9 times • Run 0 times
Download the 'Dijkstra's Shortest Path Algorithm' 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

patches-own [dist value]
globals [notVisited]

to setup
  ca
  ask patches[
   set dist 99999
   set value random 10 + 1
   set plabel dist
  ]
  ask patch min-pxcor max-pycor [
    set dist 0
  ]
  set notVisited patches
end 

to go
  while [count notVisited > 0]
  [
    let current min-one-of notVisited [dist]
    ask current [set pcolor white set plabel dist]
    ask current [
      ask neighbors4 [
        let newDist ([dist] of myself + value)
        if newDist < dist
        [set dist newDist]
      ]

    ]
    set notVisited notVisited with [self != current]
    ask patches with [dist < 99999][set pcolor gray]
  ]

  crt 1[
    set color red
    setxy max-pxcor min-pycor
    pd
    while[patch-here != patch min-pxcor max-pycor][
    face min-one-of neighbors4 [dist]
    fd 1
      set pcolor color
    ]
  ]
end 

There is only one version of this model, created almost 2 years ago by Ron Schildge.

Attached files

File Type Description Last updated
Dijkstra's Shortest Path Algorithm.png preview Preview for 'Dijkstra's Shortest Path Algorithm' almost 2 years ago, by Ron Schildge Download

This model does not have any ancestors.

This model does not have any descendants.