-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph-printing.rkt
More file actions
32 lines (24 loc) · 850 Bytes
/
graph-printing.rkt
File metadata and controls
32 lines (24 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#lang racket
(require graph)
(require "utilities.rkt")
(provide print-dot print-graph)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Graph Printing
(define (print-dot graph file-name)
(if (at-debug-level? 1)
(call-with-output-file file-name #:exists 'replace
(lambda (out-file)
(write-string "strict graph {" out-file) (newline out-file)
(for ([v (in-vertices graph)])
(write-string (format "~a;\n" v) out-file))
(for ([u (in-vertices graph)])
(for ([v (in-neighbors graph u)])
(write-string (format "~a -- ~a;\n" u v) out-file)))
(write-string "}" out-file)
(newline out-file)))
'()))
(define (print-graph graph)
(for ([u (in-vertices graph)])
(for ([v (in-neighbors graph u)])
(write-string (format "~a -> ~a;\n" u v))
)))