import BaseEdge from "@specs-feup/flow/graph/BaseEdge"; import BaseNode from "@specs-feup/flow/graph/BaseNode"; import Node from "@specs-feup/flow/graph/Node"; /** * Represents a visit to a node during Dijkstra's algorithm. */ export interface DijkstraSearchVisit extends Node.SearchVisit { /** * The minimum weight from the root node to the current node. */ distance: number; } /** * Performs Dijsktra's algorithm lazily, yielding one node visit at a time. * * Can have a custom propagation function to determine which edges to follow, * effectively pruning the search tree. * * Can be set to be undirected, in which case it will also use incoming edges * to traverse the graph, disregarding edge direction. * * Weights must be non-negative. * * @privateRemarks * TODO This implementation uses an array, which is not efficient. A better * data structure should be used instead. */ export default class DijkstraSearch implements Node.Search { /** * A function that returns the weight of an edge. Must not return negative values. */ weight: (edge: BaseEdge.Class) => number; /** * A function that determines whether to propagate a given edge. */ propagate: (edge: BaseEdge.Class) => boolean; /** * Whether the search is to be considered directed or undirected. */ directed: boolean; /** * Creates a new Dijsktra's algorithm. * * @param weight A function that returns the weight of an edge. Must not return negative values. * By default, all edges have a weight of 1. * @param propagate A function that determines whether to propagate a given edge. */ constructor(weight?: (edge: BaseEdge.Class) => number, propagate?: (edge: BaseEdge.Class) => boolean); /** * Sets the weight function for the edges. * The weight function should return a number that represents the weight of the edge. * * @param weight The weight function to set. Must not return negative values. * @returns This search instance, for chaining. */ setWeight(weight: (edge: BaseEdge.Class) => number): this; /** * Sets the propagation function for the edges. * The propagation function should return a boolean that determines whether to propagate the edge. * * @param propagate The propagation function to set. * @returns This search instance, for chaining. */ setPropagate(propagate: (edge: BaseEdge.Class) => boolean): this; /** * Sets the search to be undirected. * An undirected search may travel through edges in both directions, * so it can also use incoming edges. * * @returns This search instance, for chaining. */ undirected(): this; search(root: BaseNode.Class): Generator; } //# sourceMappingURL=DijkstraSearch.d.ts.map