UNPKG

maths.ts

Version:

Math utilities library for TypeScript, JavaScript and Node.js

79 lines (78 loc) 2.57 kB
/** * @author Hector J. Vasquez <ipi.vasquez@gmail.com> * * @licence * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import Edge from './Edge'; import Vertex from './Vertex'; export declare type weightFunc = (s: Vertex, d: Vertex) => number; /** * Represents a graph as an adjacency list. It provides methods for * adding/removing vertex and edges. */ export default class Graph { private directed; private _heuristic; /** * Builds a graph with or without vertex. * TODO: neighbor and graph function generators. * @param nVertexes The initial number of vertexes for this. * @param directed Indicates if the graph is going to be a directed * graph or not. */ constructor(nVertexes?: number, directed?: boolean); private _vertexes; /** * Gets the vertex in this graph. * @return The vertexes of this graph. */ readonly vertexes: Vertex[]; /** * Gets all edges from Graph. * @return The edges of this graph. */ readonly edges: Edge[]; /** * Adds a vertex to this graph. * @param name The name for the new vertex. * @param info Additional name about the vertex. */ addVertex(name?: string, info?: any): void; /** * Builds an edge, then adds it to the source vertex. * @param from * @param to * @param weight * @param info */ addEdge(from: number, to: number, weight?: number | weightFunc, info?: any): void; /** * Returns the value gotten from evaluating a given heuristic with given * source and destination. * @param s The source. * @param d The destination. * @return {number} The distance between them according to the heuristic * defined on this graph. */ heuristicValue(s: number, d: number): number; /** * Sets a heuristic for this graph. * @param h The new heuristic. */ setHeuristic(h: (s: Vertex, d: Vertex) => number): void; /** * Prints this graph vertex and adjacency list. */ toString(): string; }