1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname |28.1|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu (define Graph
13 12687dd9 2023-08-04 jrmu (define Graph2
14 12687dd9 2023-08-04 jrmu (list (list 'A (list 'B 'E))
15 12687dd9 2023-08-04 jrmu (list 'B (list 'E 'F))
16 12687dd9 2023-08-04 jrmu (list 'C (list 'D))
17 12687dd9 2023-08-04 jrmu (list 'D empty)
18 12687dd9 2023-08-04 jrmu (list 'E (list 'C 'F))
19 12687dd9 2023-08-04 jrmu (list 'F (list 'D 'G))
20 12687dd9 2023-08-04 jrmu (list 'G empty)))
22 12687dd9 2023-08-04 jrmu A node is a symbol.
24 12687dd9 2023-08-04 jrmu A path is a list of the form
25 12687dd9 2023-08-04 jrmu (cons no lon)
26 12687dd9 2023-08-04 jrmu where no is a node and lon is a (listof nodes). A path represents a node and the nodes that can be accessed from the node.
28 12687dd9 2023-08-04 jrmu A graph is either
30 12687dd9 2023-08-04 jrmu 2. (cons pa gr)
31 12687dd9 2023-08-04 jrmu where pa is a path and gr is a graph.
33 12687dd9 2023-08-04 jrmu find-route : node node graph -> (listof nodes) or false
34 12687dd9 2023-08-04 jrmu Given dest, ori, and G, find a route from dest to ori in G and return is as a (listof nodes). The destination and origin are included in the (listof nodes). If no route is available, return false.
36 12687dd9 2023-08-04 jrmu (define (find-route ori dest G)
38 12687dd9 2023-08-04 jrmu [(symbol=? ori dest) (list ori)]
39 12687dd9 2023-08-04 jrmu [else ... (find-route/list (neighbors ori G) dest G) ...]))
41 12687dd9 2023-08-04 jrmu find-route/list : (listof nodes) node graph -> (listof nodes) or false
42 12687dd9 2023-08-04 jrmu Given lo-ori (listof origins), dest, and G, produce a route from some node on lo-ori to dest in G. Return the route as a (listof nodes) or false if no route is available.
44 12687dd9 2023-08-04 jrmu (define (find-route/list lo-ori dest G)
47 12687dd9 2023-08-04 jrmu ;neighbors : node graph -> (listof nodes)
48 12687dd9 2023-08-04 jrmu ;Given anode and G, find all the neighboring nodes of anode in G. If there are no neighboring nodes, return empty.
50 12687dd9 2023-08-04 jrmu (define (neighbors anode G)
51 12687dd9 2023-08-04 jrmu (assf (lambda (x) (equal? anode x)) G))
53 12687dd9 2023-08-04 jrmu ;; assf : (X -> boolean) (listof (list X Y)) -> (list X Y) or false
54 12687dd9 2023-08-04 jrmu ;; to find the first item on alop for whose first item p? holds
56 12687dd9 2023-08-04 jrmu (define (assf op aloxy)
58 12687dd9 2023-08-04 jrmu [(empty? aloxy) false]
59 12687dd9 2023-08-04 jrmu [(op (first (first aloxy))) (first aloxy)]
60 12687dd9 2023-08-04 jrmu [else (assf op (rest aloxy))]))
62 12687dd9 2023-08-04 jrmu (neighbors 'A Graph2