Skip to main content

Graph

Types

AStarResult

AStarResult<T>: object

The result of doing an A* search.

PropertyType
costnumber
The total cost of tranversing the path.
pathArray<Graph.Vertex<T>>
On success, contains the path of vertices.
statusGraph.AStarStatus
Whether the search was successful, timed out, or if there was no path found.

EdgeDescriptor

EdgeDescriptor<T>: object

A descriptor for a graph edge. Used when adding edges to a graph.

PropertyType
dstGraph.Vertex<T>
The destination vertex.
srcGraph.Vertex<T>
The source vertex.
weight?number | undefined
The weight of the edge.

VertexDescriptor

VertexDescriptor<T>: object

A descriptor for a graph vertex. Used when adding vertices to a graph.

PropertyType
dataT
Any user data to be associated with this vertex
idstring
The id that can be used to lookup this vertex in the graph

VertexIdDescriptor

VertexIdDescriptor: object

A descriptor for a graph vertex when no extra data will be associated with each vertex. Used when adding vertices to a graph.

PropertyType
idstring
The id that can be used to lookup this vertex in the graph

Enumerations

AStarStatus

AStarStatus: enum

The status of an A* search.

MemberValue
NO_END_VERTEX"astar.status.no_end"
The end vertex was not found in the graph.
NO_PATH"astar.status.no_path"
No path was found.
NO_START_VERTEX"astar.status.no_start"
The start vertex was not found in the graph.
SUCCESS"astar.status.success"
A path was found.
TIMEOUT"astar.status.timeout"
A path wasn't found in the time specified.

Methods

cloneGraph

cloneGraph(graph: Graph.IDirectedGraph<T>): Graph.IDirectedGraph<T>
Introduced 25.6.1

Clone a graph, creating new vertices and edges. Doesnt clone any of the vertices' .data.

const graph = mpSdk.Graph.createDirectedGraph();
// ... setup graph vertices and edges
const clone = sdk.Graph.cloneGraph(graph);
ParameterType
graphGraph.IDirectedGraph<T>
the directed graph to clone

Returns: Graph.IDirectedGraph<T>

createAStarRunner

createAStarRunner(graph: Graph.IDirectedGraph<T>, start: Graph.Vertex<T>, end: Graph.Vertex<T>, options?: Partial<Graph.SearchOptions<T>>): Graph.IAStarRunner<T>

Bundle Embed

Introduced 3.1.55.2-34-ga9934ccd93

Create a "runner" for the A* algorithm around a graph, and start and end vertices.

The runner encapsulates the details of the graph and search, caches the results of A*, and provides a way to subscribe to potential changes in the path signifying that the results of Graph.AStarRunner.exec may have changed.

const graph = mpSdk.Graph.createDirectedGraph();
// ... setup graph vertices and edges
const start = graph.vertex('start');
const end = graph.vertex('end');
const aStarRunner = mpSdk.Graph.createAStarRunner(graph, start, end);
const result = aStarRunner.exec();
ParameterType
graphGraph.IDirectedGraph<T>
The graph to traverse
startGraph.Vertex<T>
The start vertex.
endGraph.Vertex<T>
The end vertex.
options?Partial<Graph.SearchOptions<T>>
An optional heuristic function.

Returns: Graph.IAStarRunner<T>

A runner for A* that can execute the search or be subscribed to.

createDirectedGraph

createDirectedGraph(onDispose?: () => void): Graph.IDirectedGraph<T>

Bundle Embed

Introduced 3.1.55.2-34-ga9934ccd93

Create an empty graph data structure.

const graph = mpSdk.Graph.createDirectedGraph();
ParameterType
onDispose?() => void
An optional callback to be called when [`IDirectedGraph.dispose`](#IDirectedGraph.dispose) is called

Returns: Graph.IDirectedGraph<T>

findCycle

findCycle(graph: Graph.IDirectedGraph<T>): Iterable<Graph.Vertex<T>>

Bundle Embed

Introduced 25.6.1

Find a cycle in a graph.

const graph = mpSdk.Graph.createDirectedGraph();
// assuming graph has edges A -> B, B -> C, C -> D, D -> B
// should find the cycle [B, C, D]
const cycle = sdk.Graph.findCyle(graph);
ParameterType
graphGraph.IDirectedGraph<T>
the directed graph to search for a cycle

Returns: Iterable<Graph.Vertex<T>>

an Iterable of vertices that represent a found cycle or [] if none were found

findCycles

findCycles(graph: Graph.IDirectedGraph<T>): Iterable<Iterable<Graph.Vertex<T>>>

Bundle Embed

Introduced 25.6.1

Find multiple cycles in a graph. Note: If a vertex is in multiple cycles, only one will be reported.

const graph = mpSdk.Graph.createDirectedGraph();
// assuming graph has edges A -> B, B -> C, C -> A, D -> E, E -> D
// should find cycles [A, B, C], and [D, E]
const cycle = sdk.Graph.findCyle(graph);
ParameterType
graphGraph.IDirectedGraph<T>
the directed graph to search for cycles

Returns: Iterable<Iterable<Graph.Vertex<T>>>

an iterbale of iterables (like an array of arrays) of vertices