Documentation

Complexity.Algorithms.WordRAM.Dijkstra.GenericPQ

Black-Box Dijkstra's Algorithm Parameterized by Any Word-RAM Priority Queue #

This file implements the outer graph-traversal layer of Dijkstra's single-source shortest-path algorithm once (Cslib.Algorithms.WordRAM.Dijkstra.dijkstraCode) on 15 + r_pq registers over Basis.exact, parameterized only by a Cslib.Algorithms.WordRAM.PriorityQueue.PQCode subroutine, and proves its black-box correctness and amortized instruction-count specification (Cslib.Algorithms.WordRAM.Dijkstra.dijkstra_of_pq_spec) for any Cslib.Algorithms.WordRAM.PriorityQueue.PQPackage (supporting arbitrary concrete potentials potential : Data r_pq → ℕ).

Instantiating dijkstra_of_pq_spec with:

Main definitions #

Main results #

References #

def Cslib.Algorithms.WordRAM.Dijkstra.pqMap {r_pq : ℕ} :
Fin r_pq → Fin (15 + r_pq)

Relocation map embedding the r_pq priority-queue registers above the 15 outer registers.

Instances For

    Outer caller registers (0 .. 14) of dijkstraCode #

    @[reducible, inline]

    Constant 0.

    Instances For
      @[reducible, inline]

      Constant 1.

      Instances For
        @[reducible, inline]

        Constant 3.

        Instances For
          @[reducible, inline]

          Number of vertices n.

          Instances For
            @[reducible, inline]

            Base address n + 4 of the edge array.

            Instances For
              @[reducible, inline]

              Base address G.dbase = n + 2 * m + 4 of the n output distance words.

              Instances For
                @[reducible, inline]

                Current vertex u extracted from the priority queue.

                Instances For
                  @[reducible, inline]

                  Distance word best = d[u] of u.

                  Instances For
                    @[reducible, inline]

                    Current edge index j.

                    Instances For
                      @[reducible, inline]

                      End edge index jend of adj u.

                      Instances For
                        @[reducible, inline]

                        Target vertex tv of edge j.

                        Instances For
                          @[reducible, inline]

                          Weight tc of edge j.

                          Instances For
                            @[reducible, inline]

                            Candidate distance word best + tc.

                            Instances For
                              @[reducible, inline]

                              Current distance word d[tv] (inside relaxEdges) and emptiness flag (in outer loop).

                              Instances For
                                @[reducible, inline]

                                Scratch address register.

                                Instances For

                                  Structured Word-RAM Code of Black-Box Dijkstra #

                                  Straight-line outer header: loads n, source, db = G.dbase, eb = n + 4, sets mem[db + source] := 1, and places pqBase = db + n in t.

                                  Instances For

                                    Full setup of dijkstraCode: runs outerHeader, initializes the relocated priority queue at pqBase = G.dbase + G.n via initFresh, inserts (source, 1), and sets dv := 0 (non-empty).

                                    Instances For

                                      Straight-line start of one edge relaxation: loads (tv, tc) for edge j, advances j, forms cand := best + tc, and loads dv := mem[db + tv].

                                      Instances For

                                        Body of relaxEdges for a single outgoing edge.

                                        Instances For

                                          Inner loop scanning all outgoing edges [j, jend) of vertex u.

                                          Instances For

                                            Offset-loading block for u: sets j := offset u and jend := offset (u + 1).

                                            Instances For

                                              One outer round of dijkstraCode: extracts minimum (u, best), loads u's edge range, scans its outgoing edges via relaxEdges, and refreshes the emptiness flag dv via callIsEmpty.

                                              Instances For

                                                Complete structured word-RAM code for Dijkstra's algorithm calling P : PQCode .exact r_pq.

                                                Instances For

                                                  Input Boundedness and Framing Helpers #

                                                  @[reducible, inline]

                                                  Maximum priority-queue key ever inserted or decreased on instance G.

                                                  Instances For
                                                    @[reducible, inline]

                                                    Base address G.dbase + G.n of the priority-queue memory block.

                                                    Instances For

                                                      Inner Edge-Scan Specification (relaxEdges_spec) #

                                                      Discovered vertices (mem[dbase + v] ≠ 0) that are no longer in dom s.

                                                      Instances For

                                                        Total outgoing edges of vertices outside S.

                                                        Instances For
                                                          noncomputable def Cslib.Algorithms.WordRAM.Dijkstra.distWords {r_pq : ℕ} (G : ListInstance) (y : WordRAM.Data (15 + r_pq)) (v : Fin G.n) :

                                                          Tentative distances decoded from y.mem (G.dbase + ·).

                                                          Instances For

                                                            Synchronization between abstract PQ state s and distance array y.mem (G.dbase + ·): every handle in dom s has a nonzero distance word equal to its PQ key.

                                                            Instances For

                                                              Outer Round Invariant, Setup, Round Step, and Main Black-Box Theorems #

                                                              theorem Cslib.Algorithms.WordRAM.Dijkstra.dijkstraCode_exec {r_pq : ℕ} (pkg : PriorityQueue.PQPackage WordRAM.Basis.exact r_pq) (G : ListInstance) (w : ℕ) (hw_in : WordRAM.Fits w (8 * (G.n + G.m + 2) * (G.maxWeight + 2))) (hw_sp : WordRAM.Fits w (G.dbase + G.n + pkg.space G.n)) :
                                                              ∃ (y : WordRAM.Data (15 + r_pq)), WordRAM.ExecWithin w (dijkstraCode pkg.code) (WordRAM.Data.init G.encode) y (pkg.initTime G.n + pkg.insertTime G.n + 28 + min G.n (G.m + 1) * (pkg.extractTime G.n + pkg.emptyTime G.n + 20) + min G.n G.m * (pkg.insertTime G.n + 20) + G.m * (pkg.decreaseTime G.n + 20)) ∧ ∀ (v : Fin G.n), y.mem (G.outAddr v) = encodeDist (G.dist G.source v)

                                                              Black-box structured Dijkstra theorem. For any exact-basis PQPackage, dijkstraCode computes all encoded shortest-path distances within initTime + insertTime + 28 + min(n, m + 1) * (extractTime + emptyTime + 20) + min(n, m) * (insertTime + 20) + m * (decreaseTime + 20) instructions.

                                                              theorem Cslib.Algorithms.WordRAM.Dijkstra.dijkstra_of_pq_spec {r_pq : ℕ} (pkg : PriorityQueue.PQPackage WordRAM.Basis.exact r_pq) (G : ListInstance) (w : ℕ) (hw_in : WordRAM.Fits w (8 * (G.n + G.m + 2) * (G.maxWeight + 2))) (hw_sp : WordRAM.Fits w (G.dbase + G.n + pkg.space G.n)) :
                                                              have p := (dijkstraCode pkg.code).program OuterReg.zero; ∃ (t : WordRAM.State (15 + r_pq)) (steps : ℕ), WordRAM.Runs w p (WordRAM.State.init G.encode) t steps ∧ (∃ (v : ℕ), WordRAM.step w p t = WordRAM.Outcome.halt v) ∧ steps ≤ pkg.initTime G.n + pkg.insertTime G.n + 28 + min G.n (G.m + 1) * (pkg.extractTime G.n + pkg.emptyTime G.n + 20) + min G.n G.m * (pkg.insertTime G.n + 20) + G.m * (pkg.decreaseTime G.n + 20) ∧ ∀ (v : Fin G.n), t.data.mem (G.outAddr v) = encodeDist (G.dist G.source v)

                                                              Black-box flat-program Dijkstra theorem. Compiling dijkstraCode pkg.code produces a flat word-RAM program over Basis.exact that computes all single-source shortest-path distances and halts within the parameterized priority-queue instruction bound.