ApasScript.

Graph Theory

degreeSequence

Each vertex's degree, largest first (a loop counts twice; for a directed graph, in plus out).

isGraphical

Whether a simple graph with these degrees exists (the Erdos-Gallai test).

eulerKind

Whether a walk can use every edge exactly once: euler circuit (closed), euler path (open) or neither. Vertices with no edges are ignored.

eulerPath

A walk over every edge exactly once, as a list of vertices, or a sentence if there is none. An open walk starts at an odd vertex.

hamiltonPath

A path through every vertex exactly once, or a sentence if there is none. An exact search: up to 24 vertices.

hamiltonCycle

A cycle through every vertex exactly once, or a sentence if there is none. The first vertex is not repeated at the end of the list. An exact search: up to 24 vertices.

graphColouring

The chromatic number and a colouring with that many colours (fields chromatic_number and colours, numbered from 0). An exact search: up to 24 vertices; refused for a vertex joined to itself.

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.