Typed Interface for the Generic Graph Library
1 Bug reporting
2 Contributing
3 Technical details
4 Exported types
Graph
Matrix-Graph
4.1 Generic Graph Interface
has-vertex?
has-edge?
vertex=?
add-vertex!
remove-vertex!
rename-vertex!
add-edge!
add-directed-edge!
remove-edge!
remove-directed-edge!
get-vertices
in-vertices
get-neighbors
in-neighbors
get-edges
in-edges
edge-weight
transpose
graph-copy
graph-union!
4.2 Graph Constructors
unweighted-graph?
unweighted-graph/  undirected
unweighted-graph/  directed
unweighted-graph/  adj
weighted-graph?
weighted-graph/  undirected
weighted-graph/  directed
undirected-graph
directed-graph
matrix->matrix-graph
matrix-graph->graph
4.3 Graph Properties
4.4 Basic Graph Functions
bfs
bfs/  generalized
fewest-vertices-path
dfs
dfs/  generalized
dag?
tsort
cc
cc/  bfs
scc
4.5 Spanning Trees
min-st-kruskal
max-st-kruskal
min-st-prim
max-st-prim
4.6 Single-source Shortest Paths
bellman-ford
dijkstra
dag-shortest-paths
4.7 All-pairs Shortest Paths
floyd-warshall
transitive-closure
johnson
4.8 Coloring
coloring
coloring/  greedy
coloring/  brelaz
order-smallest-last
valid-coloring?
4.9 Maximum Flow
maxflow
bipartite?
maximum-bipartite-matching
4.10 Graphviz
graphviz
4.11 Other
5 License
8.12

Typed Interface for the Generic Graph Library🔗ℹ

Sergiu Ivanov <sivanov@colimite.fr>

 (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:

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

Graph

The type wrapping the kinds of graphs the generic graph library deals with.

The opaque type corresponding to the predicate matrix-graph?.

4.1 Generic Graph Interface🔗ℹ

procedure

(has-vertex? g v)  Boolean

  g : Graph
  v : Any

procedure

(has-edge? g u v)  Boolean

  g : Graph
  u : Any
  v : Any

procedure

(vertex=? g u v)  Boolean

  g : Graph
  u : Any
  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-edge! g u v [weight])  Void

  g : Graph
  u : Any
  v : Any
  weight : Any = 'default-value

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

(get-edges g)

  (U (Listof (List Any Any)) (Listof (List Any Any Any)))
  g : Graph

procedure

(in-edges g)

  (Sequenceof (U (List Any Any) (List Any Any Any)))
  g : Graph

procedure

(edge-weight g u v [#:default default])  Any

  g : Graph
  u : Any
  v : Any
  default : Any = +inf.0

procedure

(transpose g)  Graph

  g : Graph

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/undirected edges)  Graph

  edges : (Listof (List Any Any))

procedure

(unweighted-graph/directed edges)  Graph

  edges : (Listof (List Any Any))

procedure

(unweighted-graph/adj edges)  Graph

  edges : (Listof (Listof Any))

procedure

(weighted-graph? g)  Boolean

  g : Graph

procedure

(weighted-graph/undirected edges)  Graph

  edges : (Listof (List Any Any Any))

procedure

(weighted-graph/directed edges)  Graph

  edges : (Listof (List Any Any Any))

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
An explicit conversion between Matrix-Graph and Graph. This is necessary to use the general functions of the typed interface with matrix graphs.

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)

procedure

(dag? g)  Boolean

  g : Graph

procedure

(tsort g)  (Listof Any)

  g : Graph

procedure

(cc g)  (Listof (Listof Any))

  g : Graph

procedure

(cc/bfs g)  (Listof (Listof Any))

  g : Graph

procedure

(scc g)  (Listof (Listof Any))

  g : Graph

4.5 Spanning Trees🔗ℹ

procedure

(min-st-kruskal g)  (Listof (List Any Any))

  g : Graph

procedure

(max-st-kruskal g)  (Listof (List Any Any))

  g : Graph

procedure

(min-st-prim g source)  (Listof (List Any Any))

  g : Graph
  source : Any

procedure

(max-st-prim g source)  (Listof (List Any Any))

  g : Graph
  source : Any

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

procedure

(transitive-closure g)

  (Mutable-HashTable (List Any Any) Boolean)
  g : Graph

procedure

(johnson 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

procedure

(valid-coloring? g coloring)  Boolean

  g : Graph
  coloring : (HashTable Any Number)

4.9 Maximum Flow🔗ℹ

procedure

(maxflow g source sink)  (HashTable (List Any Any) Number)

  g : Graph
  source : Any
  sink : Any

procedure

(bipartite? g)  (U (List (Listof Any) (Listof Any)) False)

  g : Graph

procedure

(maximum-bipartite-matching g)  (Listof (List Any Any))

  g : Graph

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.