Model Module
Multigraph data structure supporting parallel edges.
A multigraph allows multiple edges between the same pair of nodes, useful for modeling scenarios like: - Multi-modal transportation (different routes between cities) - Redundant network connections - Temporal graphs (same edge at different times) - Multiple relationship types (without using hypergraphs)
Comparison with Simple Graph
Aspect |
MultiGraph |
Graph |
|---|---|---|
Parallel edges |
Allowed |
Combined/Not allowed |
Edge identity |
EdgeId per edge |
No identity |
Storage |
Map |
Nested maps |
Use case |
Multi-modal, redundant |
Standard algorithms |
Operations
addEdge: Creates new edge, returns EdgeIdtoSimpleGraph: Collapse parallel edges using merge functiontoSimpleGraphMinEdges: Keep minimum weight edgetoSimpleGraphSumEdges: Sum parallel edge weights
Example
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: |
|
<summary> Multigraph data structure supporting parallel edges. A multigraph allows multiple edges between the same pair of nodes, useful for modeling scenarios like: - Multi-modal transportation (different routes between cities) - Redundant network connections - Temporal graphs (same edge at different times) - Multiple relationship types (without using hypergraphs) ## Comparison with Simple Graph | Aspect | MultiGraph | Graph | |--------|-----------|-------| | Parallel edges | Allowed | Combined/Not allowed | | Edge identity | EdgeId per edge | No identity | | Storage | Map<EdgeId, Edge> | Nested maps | | Use case | Multi-modal, redundant | Standard algorithms | ## Operations - `addEdge`: Creates new edge, returns EdgeId - `toSimpleGraph`: Collapse parallel edges using merge function - `toSimpleGraphMinEdges`: Keep minimum weight edge - `toSimpleGraphSumEdges`: Sum parallel edge weights ## Example ```fsharp open Yog.Multi // Model multiple flights between cities let multiGraph = Model.empty Directed |> Model.addNode 0 "NYC" |> Model.addNode 1 "LON" |> fun g -> let g1, _ = Model.addEdge 0 1 (Flight("BA112", 420)) g let g2, _ = Model.addEdge 0 1 (Flight("VS003", 400)) g1 g2 // Collapse to simple graph with cheapest flight let simple = Model.toSimpleGraphMinEdges compare multiGraph ``` </summary>
<summary> Creates an empty multigraph. ## Parameters - `kind`: Directed or Undirected ## Example ```fsharp let graph = Model.empty Directed ``` </summary>
<summary> Adds a node to the multigraph. ## Example ```fsharp let graph = Model.empty Directed |> Model.addNode 0 "A" ``` </summary>
<summary> Adds an edge between two nodes. ## Returns Tuple of (updated graph, new EdgeId) ## Example ```fsharp let graph, edgeId = Model.addEdge 0 1 "weight" graph ``` </summary>
<summary> Collapses the multigraph by keeping the minimum weight. ## Parameters - `compareFn`: Comparison function for edge weights </summary>
Functions and values
| Function or value |
Description
|
||
Full Usage:
addEdge src dst data graph
Parameters:
NodeId
dst : NodeId
data : 'e
graph : MultiGraph<'n, 'e>
Returns: MultiGraph<'n, 'e> * EdgeId
Tuple of (updated graph, new EdgeId) |
Adds an edge between two nodes.
Example
val graph: obj
val edgeId: obj
|
||
Full Usage:
addNode id data graph
Parameters:
NodeId
data : 'n
graph : MultiGraph<'n, 'e>
Returns: MultiGraph<'n, 'e>
|
Adds a node to the multigraph.
Example
val graph: obj
|
||
|
Creates an empty multigraph.
Parameters
Example
val graph: obj
|
||
Full Usage:
successors id graph
Parameters:
NodeId
graph : MultiGraph<'n, 'e>
Returns: (NodeId * EdgeId * 'e) list
List of (target node, EdgeId, edge data) |
Gets successors with their EdgeIds.
|
||
Full Usage:
toSimpleGraph combineFn graph
Parameters:
'e -> 'e -> 'e
graph : MultiGraph<'n, 'e>
Returns: Graph<'n, 'e>
A simple Graph with combined edges. |
Collapses the multigraph into a simple Graph by combining parallel edges.
Parameters
Example
val simple: obj
val max: e1: 'T -> e2: 'T -> 'T (requires comparison)
|
||
Full Usage:
toSimpleGraphMinEdges compareFn graph
Parameters:
'e -> 'e -> int
graph : MultiGraph<'n, 'e>
Returns: Graph<'n, 'e>
|
Collapses the multigraph by keeping the minimum weight.
Parameters
|
||
Full Usage:
toSimpleGraphSumEdges addFn graph
Parameters:
'e -> 'e -> 'e
graph : MultiGraph<'n, 'e>
Returns: Graph<'n, 'e>
|
Collapses the multigraph by summing weights.
Parameters
|