Typed Interface for the Generic Graph Library
(require typed/graph) | package: typed-graph |
This library provides an incomplete typed interface to the generic graph library. The following parts are not currently covered:
generic graph interface,
generic queues (from the package gen-queue-lib),
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!
1 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.
2 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 README.
3 Technical details
Typed Racket includes very useful primitives require/typed and 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 answer on Stack Overflow. This page also contains a technical explanation of the issue.
4 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.
syntax
syntax
4.1 Generic Graph Interface
procedure
(has-vertex? g v) → Boolean
g : Graph v : Any
procedure
(add-vertex! g v) → Void
g : Graph v : Any
procedure
(remove-vertex! g v) → Void
g : Graph v : Any
procedure
(rename-vertex! g old new) → Void
g : Graph old : Any new : Any
procedure
(add-directed-edge! g u v [weight]) → Void
g : Graph u : Any v : Any weight : Any = 'default-value
procedure
(remove-edge! g u v) → Void
g : Graph u : Any v : Any
procedure
(remove-directed-edge! g u v) → Void
g : Graph u : Any v : Any
procedure
(get-vertices g) → (Listof Any)
g : Graph
procedure
(in-vertices g) → (Sequenceof Any)
g : Graph
procedure
(get-neighbors g v) → (Listof Any)
g : Graph v : Any
procedure
(in-neighbors g v) → (Sequenceof Any)
g : Graph v : Any
procedure
(edge-weight g u v [#:default default]) → Any
g : Graph u : Any v : Any default : Any = +inf.0
procedure
(graph-copy g) → Graph
g : Graph
procedure
(graph-union! g other) → Void
g : Graph other : Graph
4.2 Graph Constructors
procedure
(unweighted-graph? g) → Boolean
g : Graph
procedure
(unweighted-graph/adj edges) → Graph
edges : (Listof (Listof Any))
procedure
(weighted-graph? g) → Boolean
g : Graph
procedure
(undirected-graph edges [wgts]) → Graph
edges : (Listof (List Any Any)) wgts : (Listof Any) = #f
procedure
(directed-graph edges [wgts]) → Graph
edges : (Listof (List Any Any)) wgts : (Listof Any) = #f
procedure
(matrix->matrix-graph mtx) → Matrix-Graph
mtx : (Matrix Any)
procedure
(matrix-graph->graph g) → Graph
g : Matrix-Graph
4.3 Graph Properties
Graph properties are not supported.
4.4 Basic Graph Functions
procedure
(bfs g source) →
(Values (Mutable-HashTable Any Number) (Mutable-HashTable Any Any)) g : Graph source : Any
procedure
(bfs/generalized g source [ #:init-queue Q #:break break? #:init init #:visit? custom-visit?-fn #:discover discover #:visit visit #:return finish]) → Any g : Graph source : Any Q : Any = (mk-empty-fifo)
break? : (-> Graph Any Any Any Boolean) = (λ (G src from to) #f) init : (U (-> Graph Any Void) Void) = void
custom-visit?-fn : (U (-> Graph Any Any Any Boolean) False) = (λ (G src from to) #f)
discover : (-> Graph Any Any Any Any Any) = (λ (G s u v acc) acc) visit : (-> Graph Any Any Any Any) = (λ (G s v acc) acc) finish : (-> Graph Any Any Any) = (λ (G s acc) acc)
procedure
(fewest-vertices-path g source target) → (U (Listof Any) False)
g : Graph source : Any target : Any
procedure
(dfs g) →
(Values (Mutable-HashTable Any Number) (Mutable-HashTable Any Any) (Mutable-HashTable Any Number)) g : Graph
procedure
(dfs/generalized g [ #:order order #:break break? #:init init #:inner-init inner-init #:visit? custom-visit?-fn #:prologue prologue #:epilogue epilogue #:process-unvisited? process-unvisited? #:process-unvisited process-unvisited #:combine combine #:return finish]) → Any g : Graph order : (-> (Listof Any) (Listof Any)) = (λ (x) x)
break? : (-> Graph Any Any Any Boolean) = (λ (g from to acc) #f) init : (U (-> Graph Void) Void) = void inner-init : (-> Any Any) = (λ (acc) acc) custom-visit?-fn : (U (-> Graph Any Any Boolean) False) = #f prologue : (-> Graph Any Any Any Any) = (λ (G u v acc) acc) epilogue : (-> Graph Any Any Any Any) = (λ (G u v acc) acc)
process-unvisited? : (-> Graph Any Any Boolean) = (λ (G u v) #f)
process-unvisited : (-> Graph Any Any Any Any) = (λ (G u v acc) acc) combine : (-> Any Any Any) = (λ (x acc) x) finish : (-> Graph Any Any) = (λ (G acc) acc)
4.5 Spanning Trees
4.6 Single-source Shortest Paths
procedure
(bellman-ford g source) →
(Values (Mutable-HashTable Any Number) (Mutable-HashTable Any Any)) g : Graph source : Any
procedure
(dijkstra g source) →
(Values (Mutable-HashTable Any Number) (Mutable-HashTable Any Any)) g : Graph source : Any
procedure
(dag-shortest-paths g source)
→
(Values (Mutable-HashTable Any Number) (Mutable-HashTable Any Any)) g : Graph source : Any
4.7 All-pairs Shortest Paths
procedure
(floyd-warshall g) → (Mutable-HashTable (List Any Any) Number)
g : Graph
4.8 Coloring
procedure
(coloring g num-colors [#:order order])
→ (U (Mutable-HashTable Any Number) False) g : Graph num-colors : Natural order : (-> (Listof Any) (Listof Any)) = (λ (x) x)
procedure
(coloring/greedy g [#:order order])
→ (Values Number (Mutable-HashTable Any Number)) g : Graph
order : (U (-> (Listof Any) (Listof Any)) 'smallest-last) = 'smallest-last
procedure
(coloring/brelaz g) → (Mutable-HashTable Any Number)
g : Graph
procedure
(order-smallest-last g) → (Listof Any)
g : Graph
4.9 Maximum Flow
4.10 Graphviz
procedure
(graphviz g [#:output output #:colors colors]) → String
g : Graph output : Output-Port = #f colors : (HashTable Any Natural) = #f
4.11 Other
Auxiliary definitions are not supported.
5 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
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 "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.