ApasScript.

Graph Theory

net

Creates a graph-theory network with n vertices (undirected by default, or directed).

edge

Adds an edge between two vertices, addressed by 0-based index (unweighted by default, or with an explicit weight).

node

Places a vertex at explicit (x, y) coordinates, required before dijkstra() can trace the graph.

dijkstra

Traces Dijkstra's shortest-path algorithm from a source vertex, optionally to a destination, producing a step-by-step event trace for visualization. Every vertex must already have an explicit position via node().

bfs

Breadth-first search order from a start vertex.

dfs

Depth-first search order from a start vertex.

distances

Shortest distances from a start vertex to every vertex (Dijkstra; inf where unreachable).

shortestPath

The vertices of a shortest path from src to dst, in order.

bellmanFord

Shortest distances and predecessors from a start vertex, allowing negative edge weights (an error on a negative cycle).

minSpanningTree

A minimum spanning tree's edges (Prim's algorithm).

kruskal

A minimum spanning tree's edges (Kruskal's algorithm).

topologicalSort

An order of the vertices of a directed acyclic graph in which every edge points forward.

components

The connected components, each as a list of vertices.

isConnected

True if every vertex can reach every other.

hasCycle

True if the graph contains a cycle.

isBipartite

True if the vertices split into two groups with every edge between the groups.

numVertices

The number of vertices.

numEdges

The number of edges.

neighbors

The vertices joined to v by an edge.

hasEdge

True if there is an edge from u to v.

edgeWeight

The weight of the edge from u to v, or text if there is none.

adjacencyMatrix

The adjacency matrix: edge weights (1 when unweighted), 0 on the diagonal, inf where there is no edge.