I'm programming a lisp app that searches the shortest path between two train stations in Berlin.
As you see, both S41 and S42 are circular lines, so I'm creating them as shown above. If i switch to:
And my second question:
In order to find reachable stations, I have to loop throught every line in the map, and then look for the current station within them using member as follows:
I'm currently just printing the station and line when found
(defstruct station name)
(defstruct line name stations)
(defstruct karte linien)
(defstruct point station line)
(defstruct route points)
Stations
(setq Oranienburg (make-station :name "Oranienburg"))
(setq Lehnitz (make-station :name "Lehnitz"))
(setq Borgsdorf (make-station :name "Borgsdorf"))
(setq Birkenwerder (make-station :name "Birkenwerder"))
(setq HohenNeuendorf (make-station :name "Hohen Neuendorf"))
(setq Frohnau (make-station :name "Frohnau"))
(setq Hermsdorf (make-station :name "Hermsdorf"))
[...]
Lines
(setq a (list Gesundbrunnen Wedding BeusselStr
Westhafen Jungfernheide Westend
MesseNordICC Westkreuz Halensee
Hohenzollemdamm HeidelbergerPlatz
Bundesplatz Schoneberg Sudkreuz
Tempelhof Hermannstr Neukolln Sonnenallee
TreptowerPark Ostkreuz FrankfurterAllee
StorkowerStr LandsbergerAllee GreifswalderStr
PrenzlauerAllee ShonhauserAllee)
)
(setq b (nconc a a))
(setf S41 (make-line :name "S41" :stations b))
(setq S42 (make-line :name "S42" :stations b))
Here comes my first question:As you see, both S41 and S42 are circular lines, so I'm creating them as shown above. If i switch to:
(setf S41 (make-line :name "S41" :stations (nconc a a)))
I just doesn't work. Why?And my second question:
In order to find reachable stations, I have to loop throught every line in the map, and then look for the current station within them using member as follows:
I'm currently just printing the station and line when found
(defun nextpoint (apoint)
(dolist (aline (karte-linien mapa))
;; Si la estación de la situación actual está en la línea
(if (member (point-station apoint) (line-stations aline))
;; Su predecesor y sucesor están entre los alcanzables
(printpoint apoint)
)
)
)
This function is never returning as long as the map has any circular list on it. ¿How to use dolist in this case?