我正在尝试生成x-y平面中位置的所有可能有效路径的集合,如果存在以下情况,现有点将成为该路径的一部分:
我所编写的代码基本上修改了一个通用的Combine函数,该函数创建一个特定大小的所有可能组合的列表。我想要么保持路径生成不变,然后创建另一个函数来验证每个路径(从列表中删除无效路径),要么修改路径生成以限制路径的创建,以便仅路径有效已创建。
(define-struct point (x y c u))
(define coordinates
(list (make-point 0 0 6 0)
(make-point 0 1 8 25)
(make-point 0 2 10 125)
(make-point 1 0 7 0)
(make-point 1 1 11 0)
(make-point 1 2 11 175)
(make-point 2 0 4 200)
(make-point 2 1 5 75)
(make-point 2 2 12 0)))
(define (apply-list fct L)
(if (null? L)
'()
(cons (fct (car L))
(apply-list fct (cdr L)))))
(define (prefix_path p L)
(apply-list (lambda(e) (cons p e)) L))
(define (generate_paths dim coords)
(cond
[(= dim 0) '(())]
[(null? coords) '()]
[else
(append (prefix_path (car coords)
(generate_paths (- dim 1) (cdr coords)))
(generate_paths dim (cdr coords)))]))
(define (valid_edge? x y)
(if (or (= (point-x x) (point-x y))
(= (point-y x) (point-y y)))
#t
#f)
(define (print_path path)
(if (null? path)
(display "EOP")
(let ([step (car path)])
(display (point-x step))
(display ", ")
(display (point-y step))
(display ", ")
(display (point-c step) )
(display ", ")
(display (point-u step))
(display #\newline)
(print_path (cdr path)))))