Add dijkstra.
This commit is contained in:
parent
124c9f51b5
commit
d406e58074
12
graph.rkt
12
graph.rkt
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
|
min-st-kruskal max-st-kruskal min-st-prim max-st-prim
|
||||||
|
|
||||||
bellman-ford
|
bellman-ford dijkstra
|
||||||
|
|
||||||
graphviz)
|
graphviz)
|
||||||
|
|
||||||
|
@ -199,6 +199,8 @@
|
||||||
;; 6 Single-source Shortest Paths
|
;; 6 Single-source Shortest Paths
|
||||||
(define (bellman-ford g source)
|
(define (bellman-ford g source)
|
||||||
(g:bellman-ford (gg g) source))
|
(g:bellman-ford (gg g) source))
|
||||||
|
(define (dijkstra g source)
|
||||||
|
(g:dijkstra (gg g) source))
|
||||||
|
|
||||||
;; 10 Graphviz
|
;; 10 Graphviz
|
||||||
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
(define (graphviz g #:output [output #f] #:colors [colors #f])
|
||||||
|
@ -294,6 +296,8 @@
|
||||||
;; Single-source Shortest Paths
|
;; Single-source Shortest Paths
|
||||||
[bellman-ford (-> Graph Any (Values (Mutable-HashTable Any Number)
|
[bellman-ford (-> Graph Any (Values (Mutable-HashTable Any Number)
|
||||||
(Mutable-HashTable Any Any)))]
|
(Mutable-HashTable Any Any)))]
|
||||||
|
[dijkstra (-> Graph Any (Values (Mutable-HashTable Any Number)
|
||||||
|
(Mutable-HashTable Any Any)))]
|
||||||
|
|
||||||
;; 10 Graphviz
|
;; 10 Graphviz
|
||||||
[graphviz (->* (Graph)
|
[graphviz (->* (Graph)
|
||||||
|
@ -425,6 +429,12 @@
|
||||||
(check-equal? (hash->ordered-list bf-dists)
|
(check-equal? (hash->ordered-list bf-dists)
|
||||||
'((a . 0) (b . 1) (c . 2) (d . 4)))
|
'((a . 0) (b . 1) (c . 2) (d . 4)))
|
||||||
(check-equal? (hash->ordered-list bf-pred)
|
(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))))
|
'((a . #f) (b . a) (c . a) (d . b))))
|
||||||
|
|
||||||
(test-case "10 Graphviz"
|
(test-case "10 Graphviz"
|
||||||
|
|
Loading…
Reference in New Issue