maths.ts
Version:
Math utilities library for TypeScript, JavaScript and Node.js
95 lines (94 loc) • 3.1 kB
TypeScript
/**
* @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';
import { Town, World } from './world';
export interface Solution {
distance: number;
path: number[];
}
/**
* Contains collective information retrieved by the ants of this colony.
* Furthermore, it determines when to move ants and how they must behave.
*/
export declare class AntColony {
private debug;
private ants;
private world;
/**
* Creates a new colony of ants (antFactor*towns.length ants).
* @param towns An array holding the coordinates of each town.
*/
constructor(towns: Coordinate[]);
/**
* Performs the Ant Colony Optimization by putting each ant to find a
* solution.
* @param iterations The number of times to reach a new solution per ant.
* @param antFactor This value multiplied by the number of towns
* delivers the number of ants to be used.
* @param evaporationRate The rules of how fast old pheromones evaporate.
* @param alpha The pheromone preference.
* @param beta The greedy preference.
*/
optimize(iterations?: number, antFactor?: number, evaporationRate?: number, alpha?: number, beta?: number): Promise<Solution>;
}
export declare class Ant {
private id;
private world;
private alpha;
private beta;
private path;
private distanceTraveled;
private debug;
private townsVisited;
/**
* Creates a new ant.
* @param id The id for this ant.
* @param world The world where this ant is.
* @param alpha Preference given to ...
* @param beta Preference given to ...
*/
constructor(id: number, world: World, alpha: number, beta: number);
/**
* Gets the towns on this ant's world.
* @returns The towns on this ant's world.
*/
readonly towns: Town[];
/**
* Gets the current town where the ant is.
* @returns The town where this ant is.
*/
readonly town: number;
/**
* Returns the current path.
*/
readonly curSolution: Solution;
/**
* Finds a probabilistic route executing next town.
* @returns {Promise<Solution>}
*/
tour(): Promise<Solution>;
/**
* Visits next town.
*/
tourNext(): void;
/**
* Finds the nearest available towns from this ant location.
* @param limit The max number of neighbors wanted.
* @returns The nearest towns from this ant location.
*/
findNearest(limit?: number): number[];
}