UNPKG

maths.ts

Version:

Math utilities library for TypeScript, JavaScript and Node.js

77 lines (76 loc) 2.6 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 { Coordinate } from '../../plotter/index'; export declare const K = 100; /** * Edges are symmetrical, that is AB == BA. They have pheromones, a distance * saved in order to avoid constant recalculation. */ export interface Edge { pheromones: number; distance: number; } /** * Towns are defined by a location expressed as a coordinate, an array of * neighbors (which are every town in the world) ordered from the closest * neighbor to the furthest and a list of edges that connect to every other * town. */ export interface Town { location: Coordinate; neighbors: number[]; edges: Edge[]; } export declare class World { private debug; /** * Initializes this world with towns and edges from one town to another. * @param townsCoordinates The list of towns on this world. */ constructor(townsCoordinates: Coordinate[]); private _towns; /** * Returns the list of towns in this world with his (x, y) locations. * @returns The towns in this world. */ readonly towns: Town[]; /** * Updates the quantity of pheromones per path by multiplying the current * amount of pheromones times evaporationRate. * @param evaporationRate Determines how fast the pheromones will evaporate. */ evaporate(evaporationRate: number): void; /** * Resets the initial amount of pheromones on each edge between towns. */ reset(): void; /** * Returns the requested path. * @param a The origin. * @param b The destination. * @returns Information about the path from a to b. */ getEdge(a: number, b: number): Edge; /** * Calculates the euclidean distance between point a and point b; a & b * must be numbers within the limits of the towns array. * @param a The first town. * @param b The second town. * @returns The distance between a town and b town. */ getDistance(a: number, b: number): number; }