Load interlocking data into track database

master
y5nw 2021-08-25 15:04:46 +02:00
parent cf5e76a2fc
commit 960bcf7137
3 changed files with 12 additions and 6 deletions

View File

@ -36,7 +36,7 @@
(defun load-data ()
(let* ((ildb (atil:load-ildb *ildb-path*))
(tdb (tracks:load-trackdb *nodedb-path*)))
(tdb (tracks:load-trackdb *nodedb-path* ildb)))
(psetf *ildb* ildb *trackdb* tdb)
(when *gcp*
#+sbcl(sb-ext:gc :full t))
@ -118,7 +118,7 @@
append (loop with side = (atil:make-tcbside :pos pos :side 1)
for i across (atil:tcbdata-routes (atil:tcb-side-b tcb))
append (list side (atil:route-next i))))))
(ywsw:safe-graphviz-route
(ywsw:safe-text-route
graph-tracks ("/graph/paths" :method :get) ()
("Return a simple graph of paths")
(tracks:gvdump *trackdb*))

View File

@ -9,7 +9,7 @@
;; CDDR representing the list of directions the train can move in
(defstruct track
(connects (make-empty-connects) :type (vector list 16))
(special nil :type list))
(special nil :type boolean))
(defmacro get-track (trackdb pos)
`(gethash ,pos ,trackdb))
@ -35,8 +35,13 @@
when (or (not ,no-eol-p) ,c)
collect (cons ,c ,d))))))
(defun mark-interlocking-tracks (tdb ildb)
;; TODO: actually check whether the TCBs are useful
(loop for pos being the hash-keys of (atil:ildb-tcbs ildb) do
(alexandria:when-let ((track (gethash pos tdb)))
(setf (track-special track) t))))
(defun optimize-track-database (tdb)
(declare (optimize (debug 3)))
(labels ((ndirs (c) (loop for i across c when i count i))
(connect-dirs (from to dist)
(with-track-at-ts (tdb from nil dir track)
@ -96,7 +101,7 @@
(adjust-conns-list-with-param2 clist param2 t))))
tmpdb))))
(defun load-trackdb (fn)
(defun load-trackdb (fn ildb)
(let* ((tmpdb (read-tracks-from-nodedb fn))
(tdb (make-hash-table :test #'equalp :size (hash-table-count tmpdb))))
(loop for pos being the hash-keys of tmpdb using (hash-value clist)
@ -131,6 +136,7 @@
(push dist (aref connects (dir-c i)))
(push adj (aref connects (dir-c i))))
(setf (get-track tdb pos) (make-track :connects connects))))
(mark-interlocking-tracks tdb ildb)
(optimize-track-database tdb)
tdb))

View File

@ -10,6 +10,7 @@
:components ((:file "helpers")
(:file "graphviz")
(:file "serialize-lib")
(:file "interlocking")
(:module "tracks"
:serial t
:components ((:file "package")
@ -17,7 +18,6 @@
(:file "registration")
(:file "database")
(:file "path")))
(:file "interlocking")
(:file "server-wrapper")
(:file "dataserver"))
;; https://lispcookbook.github.io/cl-cookbook/scripting.html