调试程序:
- (setq lst '(("RQ28" "RQ27")
- ("RQ27" "RQ22")
- ("RQ22" "RQ21")
- ("RQ24" "RQ27")
- ("RQ25" "RQ24")
- ("RQ26" "RQ25")
- ("RQ24" "RQ20")
- )
- )
- ;; (getpath "RQ26" "RQ21")
- (defun getpath (start end / next PD)
- (if (null path)
- (setq path (list start))
- (setq path (cons start path))
- )
- (if (= start end)
- (setq lst nil)
- (if lst
- (progn
- (if (setq next (getnext start))
- (cond
- ((= 1 (length next))
- (getpath (car next) end)
- )
- ((> (length next) 1)
- (setq pd (length path))
- (while next
- (getpath (car next) end)
-
- (setq next (cdr next))
- ;; 路径回退到分支处
- (while (and (/= end (car path)) (> (length path) pd))
- (setq path (cdr path))
- )
- )
- )
- )
- )
- )
- )
- )
- )
- ;; (getnext "RQ26")
- (defun getnext (s / next)
- (setq next (vl-remove-if-not '(lambda (e) (member s e)) lst))
- ;; 总路径表中移除查到的项防止路径返回
- (setq lst (vl-remove-if '(lambda (e) (member e next)) lst))
- (if next
- (mapcar '(lambda (e1) (car (vl-remove-if '(lambda (e) (= s e)) e1)))
- next
- )
- )
- )
- ;;;_$ (findpath "RQ26" "RQ21" lst)
- (defun findpath (start end lst / path)
- (getpath start end)
- (reverse path)
- )
|