Browse Source

Add dijkstra.

master
Sergiu Ivanov 3 months ago
parent
commit
d406e58074
  1. 12
      graph.rkt

12
graph.rkt

@ -39,7 +39,7 @@
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
bellman-ford
bellman-ford dijkstra
graphviz)
@ -199,6 +199,8 @@
;; 6 Single-source Shortest Paths
(define (bellman-ford g source)
(g:bellman-ford (gg g) source))
(define (dijkstra g source)
(g:dijkstra (gg g) source))
;; 10 Graphviz
(define (graphviz g #:output [output #f] #:colors [colors #f])
@ -294,6 +296,8 @@
;; Single-source Shortest Paths
[bellman-ford (-> Graph Any (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any)))]
[dijkstra (-> Graph Any (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any)))]
;; 10 Graphviz
[graphviz (->* (Graph)
@ -425,6 +429,12 @@
(check-equal? (hash->ordered-list bf-dists)
'((a . 0) (b . 1) (c . 2) (d . 4)))
(check-equal? (hash->ordered-list bf-pred)
'((a . #f) (b . a) (c . a) (d . b)))
(define-values (dj-dists dj-pred) (dijkstra g0 'a))
(check-equal? (hash->ordered-list dj-dists)
'((a . 0) (b . 1) (c . 2) (d . 4)))
(check-equal? (hash->ordered-list dj-pred)
'((a . #f) (b . a) (c . a) (d . b))))
(test-case "10 Graphviz"

Loading…
Cancel
Save