typed-graph/manual.scrbl
2022-01-02 22:09:29 +01:00

194 lines
8.6 KiB
Racket

#lang scribble/manual
@(require (for-label (only-in typed/racket
require/typed require/typed/provide
Any Boolean Void Sequenceof Listof List U False Number Values
Mutable-HashTable Immutable-HashTable))
(for-label (only-in math/matrix Matrix))
(for-label (only-in graph (matrix-graph? g:matrix-graph?)))
(for-label (only-in data/gen-queue/fifo mk-empty-fifo))
(for-label typed/graph))
@title{Typed Interface for the Generic Graph Library}
@author[@author+email["Sergiu Ivanov" "sivanov@colimite.fr"]]
@defmodule[typed/graph]
This library provides an incomplete typed interface to the
@hyperlink["https://docs.racket-lang.org/graph/index.html"]{generic graph
library}. The following parts are @bold{not currently covered}:
@itemlist[
@item{generic graph interface,}
@item{generic queues (from the package @racket[gen-queue-lib]),}
@item{macros.}
]
I may work on adding these in the future, but it is low priority for me as of
2021-12-21. Feel free to contribute!
@section{Bug reporting}
If you find a bug, first try running your code directly with the graph library,
in untyped Racket. If the bug persists, you should probably report it to the
maintainer of the graph library directly. If unsure, report the bug to me.
@section{Contributing}
As of 2021, GitHub is owned by Microsoft, so I prefer keeping this library on
a different platform.
Do feel free to submit patches to me by E-mail: I will try my best to review
and apply them within a reasonable time frame. More details on contributing in
the
@hyperlink["https://git.marvid.fr/scolobb/typed-graph/src/branch/master/README.md#submitting-patches"]{README}.
@section{Technical details}
Typed Racket includes very useful primitives @racket[require/typed] and
@racket[require/typed/provide]. However, we cannot use this technique with the
graph library. The solution which works consists in wrapping the opaque graph
structure into another structure, which will therefore be a uniform container
for all kinds of graph implementations provided by the library.
This solution comes from Alex Knauth's answer
@hyperlink["https://stackoverflow.com/a/65416020"]{answer on Stack Overflow}.
This page also contains a technical explanation of the issue.
@section{Exported types}
This section lists the types this library gives to re-exported functions.
The subsections correspond to the sections of the documentation of the generic
graph library.
@defidform[Graph]{
The type wrapping the kinds of graphs the generic graph library deals with.
}
@defidform[Matrix-Graph]{
The opaque type corresponding to the predicate @racketlink[g:matrix-graph? "matrix-graph?"].
}
@subsection{Generic Graph Interface}
@defproc[(has-vertex? [g Graph] [v Any]) Boolean]{}
@defproc[(has-edge? [g Graph] [u Any] [v Any]) Boolean]{}
@defproc[(vertex=? [g Graph] [u Any] [v Any]) Boolean]{}
@defproc[(add-vertex! [g Graph] [v Any]) Void]{}
@defproc[(remove-vertex! [g Graph] [v Any]) Void]{}
@defproc[(rename-vertex! [g Graph] [old Any] [new Any]) Void]{}
@defproc[(add-edge! [g Graph] [u Any] [v Any] [weight Any 'default-value]) Void]{}
@defproc[(add-directed-edge! [g Graph] [u Any] [v Any] [weight Any 'default-value]) Void]{}
@defproc[(remove-edge! [g Graph] [u Any] [v Any]) Void]{}
@defproc[(remove-directed-edge! [g Graph] [u Any] [v Any]) Void]{}
@defproc[(get-vertices [g Graph]) (Listof Any)]{}
@defproc[(in-vertices [g Graph]) (Sequenceof Any)]{}
@defproc[(get-neighbors [g Graph] [v Any]) (Listof Any)]{}
@defproc[(in-neighbors [g Graph] [v Any]) (Sequenceof Any)]{}
@defproc[(get-edges [g Graph]) (U (Listof (List Any Any)) (Listof (List Any Any Any)))]{}
@defproc[(in-edges [g Graph]) (Sequenceof (U (List Any Any) (List Any Any Any)))]{}
@defproc[(edge-weight [g Graph] [u Any] [v Any] [#:default default Any +inf.0]) Any]{}
@defproc[(transpose [g Graph]) Graph]{}
@defproc[(graph-copy [g Graph]) Graph]{}
@defproc[(graph-union! [g Graph] [other Graph]) Void]{}
@subsection{Graph Constructors}
@defproc[(unweighted-graph? [g Graph]) Boolean]{}
@defproc[(unweighted-graph/undirected [edges (Listof (List Any Any))]) Graph]{}
@defproc[(unweighted-graph/directed [edges (Listof (List Any Any))]) Graph]{}
@defproc[(unweighted-graph/adj [edges (Listof (Listof Any))]) Graph]{}
@defproc[(weighted-graph? [g Graph]) Boolean]{}
@defproc[(weighted-graph/undirected [edges (Listof (List Any Any Any))]) Graph]{}
@defproc[(weighted-graph/directed [edges (Listof (List Any Any Any))]) Graph]{}
@defproc[(undirected-graph [edges (Listof (List Any Any))] [wgts (Listof Any) #f]) Graph]{}
@defproc[(directed-graph [edges (Listof (List Any Any))] [wgts (Listof Any) #f]) Graph]{}
@defproc[(matrix->matrix-graph [mtx (Matrix Any)]) Matrix-Graph]{}
@defproc[(matrix-graph->graph [g Matrix-Graph]) Graph]{
An explicit conversion between @racket[Matrix-Graph] and @racket[Graph].
This is necessary to use the general functions of the typed interface with
matrix graphs.
}
@subsection{Graph Properties}
Graph properties are not supported.
@subsection{Basic Graph Functions}
@defproc[(bfs [g Graph] [source Any]) (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any))]{}
@defproc[(bfs/generalized [g Graph]
[source Any]
[#:init-queue Q Any (mk-empty-fifo)]
[#:break break? (-> Graph Any Any Any Boolean)
(λ (G src from to) #f)]
[#:init init (U (-> Graph Any Void) Void) void]
[#:visit? custom-visit?-fn (U (-> Graph Any Any Any Boolean) False)
(λ (G src from to) #f)]
[#:discover discover (-> Graph Any Any Any Any Any)
(λ (G s u v acc) acc)]
[#:visit visit (-> Graph Any Any Any Any)
(λ (G s v acc) acc)]
[#:return finish (-> Graph Any Any Any)
(λ (G s acc) acc)]
) Any]{}
@defproc[(fewest-vertices-path [g Graph] [source Any] [target Any]) (U (Listof Any) False)]{}
@defproc[(dfs [g Graph]) (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any)
(Mutable-HashTable Any Number))]{}
@defproc[(dfs/generalized [g Graph]
[#:order order (-> (Listof Any) (Listof Any)) (λ (x) x)]
[#:break break? (-> Graph Any Any Any Boolean) (λ (g from to acc) #f)]
[#:init init (U (-> Graph Void) Void) void]
[#:inner-init inner-init (-> Any Any) (λ (acc) acc)]
[#:visit? custom-visit?-fn (U (-> Graph Any Any Boolean) False) #f]
[#:prologue prologue (-> Graph Any Any Any Any) (λ (G u v acc) acc)]
[#:epilogue epilogue (-> Graph Any Any Any Any) (λ (G u v acc) acc)]
[#:process-unvisited? process-unvisited? (-> Graph Any Any Boolean) (λ (G u v) #f)]
[#:process-unvisited process-unvisited (-> Graph Any Any Any Any) (λ (G u v acc) acc)]
[#:combine combine (-> Any Any Any) (λ (x acc) x)]
[#:return finish (-> Graph Any Any) (λ (G acc) acc)]
) Any]{}
@defproc[(dag? [g Graph]) Boolean]{}
@defproc[(tsort [g Graph]) (Listof Any)]{}
@defproc[(cc [g Graph]) (Listof (Listof Any))]{}
@defproc[(cc/bfs [g Graph]) (Listof (Listof Any))]{}
@defproc[(scc [g Graph]) (Listof (Listof Any))]{}
@subsection{Spanning Trees}
@defproc[(min-st-kruskal [g Graph]) (Listof (List Any Any))]{}
@defproc[(max-st-kruskal [g Graph]) (Listof (List Any Any))]{}
@defproc[(min-st-prim [g Graph] [source Any]) (Listof (List Any Any))]{}
@defproc[(max-st-prim [g Graph] [source Any]) (Listof (List Any Any))]{}
@subsection{Single-source Shortest Paths}
@defproc[(bellman-ford [g Graph] [source Any]) (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any))]{}
@defproc[(dijkstra [g Graph] [source Any]) (Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any))]{}
@defproc[(dag-shortest-paths [g Graph] [source Any])
(Values (Mutable-HashTable Any Number)
(Mutable-HashTable Any Any))]{}
@section{License}
Like the generic graph library, this library is licensed under the Apache
License, Version 2.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
@hyperlink["http://www.apache.org/licenses/LICENSE-2.0"]{http://www.apache.org/licenses/LICENSE-2.0}
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an @bold{"as is" basis, without warranties
or conditions of any kind}, either express or implied. See the License for the
specific language governing permissions and limitations under the License.