[CHANGE] count_sep_scan: raeumliches Grid zur Vorsortierung der Carrier bei ZAEHLE_SEP_SCAN

cs-assign prueft je Sensor nicht mehr linear alle ILS-Carrier, sondern
nur noch die Kandidaten der eigenen Grid-Zelle (Aufloesung sqrt(Anzahl
Carrier)). Aufwand sinkt von O(Sensoren x Carrier) auf ~O(Sensoren +
Carrier), Zuordnungslogik bleibt unveraendert.
This commit is contained in:
2026-07-30 15:30:38 +02:00
parent 71f52ca3d6
commit 7f5a8036c0
+88 -5
View File
@@ -168,14 +168,93 @@
(<= y (+ (nth 6 rec) *senstol*))) (<= y (+ (nth 6 rec) *senstol*)))
) )
;;; ------------------------------------------------------------
;;; Raeumliches Grid (Vorsortierung nach Zellen) ueber die
;;; Carrier-Boxen, damit cs-assign nicht mehr linear ueber ALLE
;;; Carrier laufen muss, sondern nur ueber die Kandidaten der
;;; eigenen Zelle. Aufloesung ~ sqrt(Anzahl Carrier).
;;; Ein Carrier wird in JEDE Zelle eingetragen, die seine
;;; (toleranzerweiterte) Box beruehrt - dadurch kann kein
;;; Treffer verloren gehen (kein false negative), die exakte
;;; Pruefung (cs-in-box) bleibt unveraendert auf den Kandidaten.
;;; Rueckgabe von cs-grid-build: (gxmin gymin cellw cellh gridn buckets)
;;; buckets: Assoc-Liste (zellindex . (rec rec ...))
;;; ------------------------------------------------------------
(defun cs-grid-cellidx (val minv cellsize gridn / idx)
(setq idx (fix (/ (- val minv) cellsize)))
(cond ((< idx 0) 0) ((> idx (1- gridn)) (1- gridn)) (t idx))
)
(defun cs-grid-bump (buckets key rec / pair)
(setq pair (assoc key buckets))
(if pair
(subst (cons key (cons rec (cdr pair))) pair buckets)
(cons (cons key (list rec)) buckets))
)
(defun cs-grid-add (buckets rec gxmin gymin cellw cellh gridn / cx0 cx1 cy0 cy1 cx cy)
(setq cx0 (cs-grid-cellidx (- (nth 3 rec) *senstol*) gxmin cellw gridn))
(setq cx1 (cs-grid-cellidx (+ (nth 5 rec) *senstol*) gxmin cellw gridn))
(setq cy0 (cs-grid-cellidx (- (nth 4 rec) *senstol*) gymin cellh gridn))
(setq cy1 (cs-grid-cellidx (+ (nth 6 rec) *senstol*) gymin cellh gridn))
(setq cy cy0)
(while (<= cy cy1)
(setq cx cx0)
(while (<= cx cx1)
(setq buckets (cs-grid-bump buckets (+ (* cx gridn) cy) rec))
(setq cx (1+ cx))
)
(setq cy (1+ cy))
)
buckets
)
(defun cs-grid-build (carriers / n gridn gxmin gymin gxmax gymax cellw cellh buckets)
(setq n (length carriers))
(if (= n 0)
(list 0.0 0.0 1.0 1.0 1 nil)
(progn
(setq gxmin (- (nth 3 (car carriers)) *senstol*)
gymin (- (nth 4 (car carriers)) *senstol*)
gxmax (+ (nth 5 (car carriers)) *senstol*)
gymax (+ (nth 6 (car carriers)) *senstol*))
(foreach rec (cdr carriers)
(if (< (- (nth 3 rec) *senstol*) gxmin) (setq gxmin (- (nth 3 rec) *senstol*)))
(if (< (- (nth 4 rec) *senstol*) gymin) (setq gymin (- (nth 4 rec) *senstol*)))
(if (> (+ (nth 5 rec) *senstol*) gxmax) (setq gxmax (+ (nth 5 rec) *senstol*)))
(if (> (+ (nth 6 rec) *senstol*) gymax) (setq gymax (+ (nth 6 rec) *senstol*)))
)
(setq gridn (max 1 (fix (sqrt n))))
(setq cellw (/ (max 1.0 (- gxmax gxmin)) gridn))
(setq cellh (/ (max 1.0 (- gymax gymin)) gridn))
(setq buckets nil)
(foreach rec carriers
(setq buckets (cs-grid-add buckets rec gxmin gymin cellw cellh gridn)))
(list gxmin gymin cellw cellh gridn buckets)
)
)
)
(defun cs-grid-candidates (grid pt / gxmin gymin cellw cellh gridn buckets cx cy pair)
(setq gxmin (nth 0 grid) gymin (nth 1 grid)
cellw (nth 2 grid) cellh (nth 3 grid)
gridn (nth 4 grid) buckets (nth 5 grid))
(setq cx (cs-grid-cellidx (car pt) gxmin cellw gridn))
(setq cy (cs-grid-cellidx (cadr pt) gymin cellh gridn))
(setq pair (assoc (+ (* cx gridn) cy) buckets))
(if pair (cdr pair) nil)
)
;;; ------------------------------------------------------------ ;;; ------------------------------------------------------------
;;; Sensor-Punkt einem ILS-Block zuordnen. ;;; Sensor-Punkt einem ILS-Block zuordnen.
;;; Rueckgabe: ILS-Block-Record oder nil (keine Zuordnung). ;;; Rueckgabe: ILS-Block-Record oder nil (keine Zuordnung).
;;; Bei mehreren Treffern: naechstes Box-Zentrum (X/Y). ;;; Bei mehreren Treffern: naechstes Box-Zentrum (X/Y).
;;; grid = Vorsortierung aus cs-grid-build (statt aller Carrier
;;; wird nur die Kandidatenliste der eigenen Zelle geprueft).
;;; ------------------------------------------------------------ ;;; ------------------------------------------------------------
(defun cs-assign (pt carriers / matches best bestd d) (defun cs-assign (pt grid / matches best bestd d)
(setq matches nil) (setq matches nil)
(foreach rec carriers (foreach rec (cs-grid-candidates grid pt)
(if (cs-in-box pt rec) (setq matches (cons rec matches)))) (if (cs-in-box pt rec) (setq matches (cons rec matches))))
(cond (cond
((null matches) nil) ((null matches) nil)
@@ -346,7 +425,7 @@
;;; HAUPTBEFEHL ;;; HAUPTBEFEHL
;;; ============================================================ ;;; ============================================================
(defun c:ZAEHLE_SEP_SCAN ( / ss i ent ed nm tags bb cx cy label (defun c:ZAEHLE_SEP_SCAN ( / ss i ent ed nm tags bb cx cy label
carriers scanlist seplist kind pt carriers grid scanlist seplist kind pt
scanCounts sepCounts scanCounts sepCounts
rec en nm2 ns nsep internSep newS newP rec en nm2 ns nsep internSep newS newP
s sent spt s sent spt
@@ -408,12 +487,16 @@
) )
;; --- 2. Sensoren zuordnen: zuordnung schreiben bzw. markieren --- ;; --- 2. Sensoren zuordnen: zuordnung schreiben bzw. markieren ---
;; Vorsortierung: Carrier einmalig in ein raeumliches Grid einsortieren,
;; damit cs-assign je Sensor nur die Kandidaten der eigenen Zelle statt
;; aller Carrier prueft (siehe cs-grid-build).
(setq grid (cs-grid-build carriers))
(setq scanCounts nil sepCounts nil (setq scanCounts nil sepCounts nil
n-scan-unassigned 0 n-sep-unassigned 0) n-scan-unassigned 0 n-sep-unassigned 0)
(foreach s scanlist (foreach s scanlist
(setq sent (car s) spt (cadr s)) (setq sent (car s) spt (cadr s))
(setq rec (cs-assign spt carriers)) (setq rec (cs-assign spt grid))
(if rec (if rec
(progn (progn
(setq scanCounts (cs-bump scanCounts (car rec))) (setq scanCounts (cs-bump scanCounts (car rec)))
@@ -426,7 +509,7 @@
(foreach s seplist (foreach s seplist
(setq sent (car s) spt (cadr s)) (setq sent (car s) spt (cadr s))
(setq rec (cs-assign spt carriers)) (setq rec (cs-assign spt grid))
(if rec (if rec
(progn (progn
(setq sepCounts (cs-bump sepCounts (car rec))) (setq sepCounts (cs-bump sepCounts (car rec)))