Yog.FSharp
Getting Started Examples API Reference GitHub

Examples

Real-world examples demonstrating how to use Yog.FSharp for various graph problems.

Running Examples

All examples are literate F# scripts that you can run directly:

# Run an example script
dotnet fsi docs/examples/gps-navigation.fsx

Or reference in your F# Interactive session:

#load "docs/examples/gps-navigation.fsx"

The examples use literate programming - documentation is embedded in the .fsx files using (** and *) comment blocks.


Pathfinding & Traversal

Example

Description

Demonstrates

GPS Navigation with A*

Find the fastest route between locations using heuristic-based search.

A* algorithm, heuristics, route planning

Dijkstra's Shortest Path

Find the fastest delivery route in a weighted road network.

Dijkstra's algorithm, single-source distances

Bellman-Ford with Negative Weights

Shortest paths with negative weights and negative cycle detection.

Bellman-Ford, negative cycle detection

City Distance Matrix with Floyd-Warshall

Compute shortest distances between all pairs of cities in a network.

All-pairs shortest paths, distance matrices

Cave Path Counting

Count all valid paths through a cave system with complex visit rules.

Custom DFS, backtracking, state-space search

Graph Properties & Algorithms

Example

Description

Demonstrates

The Seven Bridges of Königsberg

The classic problem that founded graph theory.

Eulerian paths/circuits, degree analysis

Task Scheduling with Topological Sort

Determine the correct execution order for tasks with dependencies.

Topological sorting on DAGs, cycle detection

Deterministic Task Ordering

Alphabetically earliest execution order for tasks with multiple valid orderings.

Lexicographical topological sort, stable resolution

Social Network Analysis with SCC

Find communities in a social network using strongly connected components.

Tarjan's & Kosaraju's SCC algorithms

Network Cable Layout Optimization

Find the minimum cost to connect all buildings using Kruskal's algorithm.

Minimum Spanning Trees (MST), cost optimization

Centrality Analysis

Identify the most important nodes using degree, closeness, betweenness, PageRank, and eigenvector centrality.

All 5 centrality measures

Bridges & Articulation Points

Find critical infrastructure whose failure disconnects the network.

Tarjan's bridge-finding algorithm

Clique Finding

Find tightly-knit groups using the Bron-Kerbosch algorithm.

Maximum clique, all maximal cliques, k-cliques

DAG Algorithms

Critical path analysis and transitive closure on a task dependency DAG.

Longest path, transitive closure, topological sort

Flow & Matching

Example

Description

Demonstrates

Job Matching with Maximum Flow

Solve a bipartite matching problem using maximum flow algorithms.

Edmonds-Karp, bipartite matching, network modeling

Network Bandwidth Allocation

Maximize throughput and identify bottlenecks in a computer network.

Edmonds-Karp, Max-Flow Min-Cut Theorem

Global Minimum Cut

Find the "natural" split point of a graph that disconnects it with minimum cost.

Stoer-Wagner algorithm, network reliability

Medical Residency Matching

Solve the stable marriage problem to match residents to hospitals.

Gale-Shapley algorithm, stable matching

Classic Graph Generators

Example

Description

Demonstrates

Complete Graphs

Generate \(K_n\) graphs where every node connects to every other.

Classic.complete

Cycle Graphs

Generate \(C_n\) graphs forming a single closed loop.

Classic.cycle

Path Graphs

Generate \(P_n\) graphs forming a linear chain.

Classic.path

Star Graphs

Generate \(S_n\) graphs with a central hub node.

Classic.star

Wheel Graphs

Generate \(W_n\) graphs by adding a hub to a cycle.

Classic.wheel

2D Grid Graphs

Generate rectangular lattice meshes.

Classic.grid2D

Bipartite Graphs

Generate complete bipartite graphs \(K_{m,n}\).

Classic.completeBipartite

Empty Graphs

Generate \(n\) isolated nodes with no edges.

Classic.emptyGraph

Binary Trees

Generate complete binary trees of a given depth.

Classic.binaryTree

The Petersen Graph

Generate the famous 10-node, 15-edge cubic graph.

Classic.petersenGraph

Stochastic Network Models

Example

Description

Demonstrates

Erdős-Rényi \(G(n,p)\) Graphs

Random graphs where each edge exists with probability \(p\).

Random.erdosRenyiGnp

Erdős-Rényi \(G(n,m)\) Graphs

Random graphs with exactly \(m\) edges added uniformly.

Random.erdosRenyiGnm

Barabási-Albert Networks

Scale-free networks generated via preferential attachment.

Random.barabasiAlbert

Watts-Strogatz Networks

Small-world networks with high clustering and short paths.

Random.wattsStrogatz

Random Spanning Trees

Uniformly random tree structure on \(n\) nodes.

Random.randomTree

IO & Serialization

Example

Description

Demonstrates

DOT Graph Rendering

Export graphs to Graphviz DOT format for professional visualization.

Yog.IO.Dot, visual customization, Graphviz

JSON Data Export

Export graph data to JSON for web APIs and frontend visualization.

Yog.IO.Json, indented serialization, data interchange

GraphML Serialization

Export and import graphs in GraphML format for Gephi, yEd, and Cytoscape.

Yog.IO.GraphML, round-trip, custom attributes

GDF Format Export

Export graphs to GDF format for Gephi and lightweight text-based interchange.

Yog.IO.Gdf, column-based format, custom attributes

Check the GitHub repository for the latest examples!