Blame


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-advanced-reader.ss" "lang")((modname |29.3|) (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 #t #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 (find-route1 ori dest G)
5 12687dd9 2023-08-04 jrmu (local ((define (find-route ori dest G)
6 12687dd9 2023-08-04 jrmu (cond
7 12687dd9 2023-08-04 jrmu [(symbol=? ori dest) (list ori)]
8 12687dd9 2023-08-04 jrmu [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
9 12687dd9 2023-08-04 jrmu (cond
10 12687dd9 2023-08-04 jrmu [(boolean? possible-route) false]
11 12687dd9 2023-08-04 jrmu [else (cons ori possible-route)]))]))
12 12687dd9 2023-08-04 jrmu (define (find-route/list lo-ori dest G)
13 12687dd9 2023-08-04 jrmu (cond
14 12687dd9 2023-08-04 jrmu [(empty? lo-ori) false]
15 12687dd9 2023-08-04 jrmu [else (local ((define possible-route (find-route (first lo-ori) dest G)))
16 12687dd9 2023-08-04 jrmu (cond [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
17 12687dd9 2023-08-04 jrmu [else possible-route]))]))
18 12687dd9 2023-08-04 jrmu (define (neighbors anode G)
19 12687dd9 2023-08-04 jrmu (first (rest (assf (lambda (x) (equal? anode x)) G)))))
20 12687dd9 2023-08-04 jrmu find-route ori dest G))
21 12687dd9 2023-08-04 jrmu
22 12687dd9 2023-08-04 jrmu (define (neighbors anode agraph)
23 12687dd9 2023-08-04 jrmu (vector-ref agraph anode))
24 12687dd9 2023-08-04 jrmu
25 12687dd9 2023-08-04 jrmu
26 12687dd9 2023-08-04 jrmu (define G (vector '(1 4)
27 12687dd9 2023-08-04 jrmu '(4 5)
28 12687dd9 2023-08-04 jrmu '(3)
29 12687dd9 2023-08-04 jrmu empty
30 12687dd9 2023-08-04 jrmu '(2 5)
31 12687dd9 2023-08-04 jrmu '(3 6)
32 12687dd9 2023-08-04 jrmu empty))
33 12687dd9 2023-08-04 jrmu
34 12687dd9 2023-08-04 jrmu ;find-route : node node graph -> (listof nodes)
35 12687dd9 2023-08-04 jrmu ;Find a route from ori to dest given G and return the route as a (listof nodes).
36 12687dd9 2023-08-04 jrmu
37 12687dd9 2023-08-04 jrmu (define (find-route ori dest G)
38 12687dd9 2023-08-04 jrmu (cond
39 12687dd9 2023-08-04 jrmu [(= ori dest) (list ori)]
40 12687dd9 2023-08-04 jrmu [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
41 12687dd9 2023-08-04 jrmu (cond [(boolean? possible-route) false]
42 12687dd9 2023-08-04 jrmu [else (cons ori possible-route)]))]))
43 12687dd9 2023-08-04 jrmu
44 12687dd9 2023-08-04 jrmu ;find-route/list : (listof nodes) node graph -> (listof nodes)
45 12687dd9 2023-08-04 jrmu ;Find a route from lo-ori (listof nodes) to dest given G and return the route as a (listof nodes).
46 12687dd9 2023-08-04 jrmu
47 12687dd9 2023-08-04 jrmu (define (find-route/list lo-ori dest G)
48 12687dd9 2023-08-04 jrmu (cond
49 12687dd9 2023-08-04 jrmu [(empty? lo-ori) false]
50 12687dd9 2023-08-04 jrmu [else (local ((define possible-route (find-route (first lo-ori) dest G)))
51 12687dd9 2023-08-04 jrmu (cond
52 12687dd9 2023-08-04 jrmu [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
53 12687dd9 2023-08-04 jrmu [else possible-route]))]))