nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
197 lines (196 loc) • 7.4 kB
TypeScript
import { NumericMatrix } from './index';
export declare type SimpleExpressionSideType = 'left' | 'right';
export declare type SimplexSolveType = 'maximize' | 'minimize' | string;
export interface SimplexDefinition {
Type: SimplexSolveType;
Objective: string;
Constraints: string[];
}
export declare class Simplex {
private problem;
private input;
private output;
private tableau;
private state;
constructor(problem: SimplexDefinition);
get Definition(): SimplexDefinition;
solve(): SimplexOutput;
static solve(problem: SimplexDefinition): SimplexOutput;
checkForErrors(obj: SimplexDefinition): void;
static getErrors(obj: SimplexDefinition): "An object must be passed to Simplex.solve()" | "The object must have the properties `type`, `objective` and `constraints`.";
private solveInternal;
}
export declare class SimplexMatrix extends NumericMatrix {
constructor(...rows: number[][]);
protected checkColumnIndex(col: number): void;
protected checkRowIndex(row: number): void;
protected checkIndexes(row: number, col: number): void;
get ColSize(): number;
get RowSize(): number;
getSize(): number[];
static scaleRow(scale: number, row: number[]): number[];
static addRows(rowA: number[], rowB: number[]): number[];
static scaleThenAddRows(scaleA: number, rowA: number[], scaleB: number, rowB: number[]): number[];
static inverseArray(arr: number[]): number[];
toString(): string;
setUniformedWidth(): this;
getGreatestValueFromLastRow(isPositive?: boolean): number;
getRowIndexWithPosMinColumnRatio(colI: number, excludeLastRow?: boolean): {
rowIndex: number;
minValue: number;
};
getUnitValueForColumn(colI: number): number;
getLastElementOnLastRow(): number;
static getGreatestElementInRow(arr: number[], excludeIndex: number, findPositive?: boolean): {
value: number;
index: number;
};
addRow(arr: number | number[]): this;
addToRow(iRow: number, els: number | number[]): this;
equals(obj: SimplexMatrix): boolean;
static getMaxArray(arrays: number[][]): {
index: number;
max: number;
};
scaleRow(scaleA: number, rowI: number): this;
pivot(rowI: number, colI: number): this;
}
export declare class SimplexExpression {
private terms;
constructor(str: string);
get Terms(): any;
static encodeE(str: string): string;
static decodeE(str: string): string;
static hasManyCompares(str: string): boolean;
static addSpaceBetweenTerms(str: string): string;
static hasExcludedOperations(str: string): boolean;
static hasIncompleteBinaryOperator(str: string): boolean;
static hasComparison(str: string): boolean;
static getErrorMessage(str: string): string;
static checkString(str: string): void;
static extractComponentsFromVariable(str: string): (string | number)[];
static splitStrByTerms(str: string): string[];
static convertExpressionToObject(str: string): any;
static termAtIndex(i: number, name: string, value: number): any;
getTermNames(excludeNumbers?: boolean, excludeSlack?: boolean): string[];
forEachTerm(fn: (prop: string, item: any, items: any) => void): void;
forEachConstant(fn: (prop: string, item: string, items: any) => void): void;
forEachVariable(fn: (prop: string, item: string, items: any) => void): void;
toString(): string;
inverse(): this;
addTerm(name: string, value: any): this;
setTerm(name: string, value: any): this;
addExpression(obj: string | SimplexExpression): this;
toTermValueArray(): any[][];
addTerms(arr: any[]): this;
removeTerm(name: string): this;
scale(factor: number): this;
hasTerm(name: string): boolean;
getTermValue(name: string): any;
getAllCoeffients(excludeNumbers?: boolean, excludeSlack?: boolean): number[];
getCoefficients(termNames: string[]): any[];
clon(): SimplexExpression;
}
export declare class SimplexConstraint {
private comparison;
private leftSide;
private rightSide;
private specialTerms;
static readonly EPSILON = 0.000001;
constructor(str?: string);
equals(obj: any): boolean;
get LeftSide(): SimplexExpression;
get RightSide(): SimplexExpression;
get Comparison(): string;
static hasManyCompares(str: string): boolean;
static hasIncompleteBinaryOperator(str: string): boolean;
static getErrorMessage(str: string): string;
static checkInput(str: string): void;
static switchSides(sideA: any, sideB: any, forEachTermFunc: any): void;
getTermNames(excludeNumbers?: boolean): any;
static parseToObject(str: string): {
lhs: SimplexExpression;
rhs: SimplexExpression;
comparison: string;
};
static parse(str: string): SimplexConstraint;
toString(): string;
getSwappedSides(doSwap?: boolean): {
a: SimplexExpression;
b: SimplexExpression;
};
moveTypeToOneSide(varSide: SimpleExpressionSideType, numSide: SimpleExpressionSideType): this;
inverse(): this;
removeStrictInequality(): this;
normalize(): this;
addSlack(val: any): this;
setSpecialTerm(obj: any): this;
addArtificalVariable(val: any): this;
hasSpecialTerm(name: string): boolean;
renameSlack(name: string): this;
renameArtificial(name: string): this;
convertToEquation(): this;
getSpecialTermNames(): any[];
getSpecialTermValue(name: string): any;
getArtificalName(): any;
scale(factor: number): this;
varSwitchSide(name: string, moveTo: string): this;
getCoefficients(termNames: string[]): any[];
getTermValuesFromLeftSide(termNames: string[]): any[];
}
export declare class SimplexTableau {
private input;
private colNames;
private matrix;
private limit;
private cycles;
constructor(input: SimplexInput);
private static getErrorMessage;
private checkForError;
private addZToMatrix;
addConstraintsToMatrix(termNames: string[]): void;
private getSortedTermNames;
private setMatrixFromInput;
solve(isMin?: boolean): this;
getPivotPoint(matrix: SimplexMatrix, isMin: boolean): {
column: number;
row: number;
};
getOutput(): SimplexOutput;
toString(): string;
}
export declare class SimplexInput {
private z;
private type;
private terms;
private constraints;
private isStandardMode;
constructor(type: string, z: string, constraints: string[]);
private getZTermNotInAnyOfTheConstraints;
private checkConstraints;
private getArrOfConstraints;
private computeType;
private doAnyConstrainsHaveRelation;
private doAllConstrainsHaveRelation;
private anyConstraints;
private allConstraints;
private getAllArtificalNames;
private forEachConstraint;
private addNumbersToSpecialTerms;
getTermNames(onlyVariables?: boolean): string[];
getAllSpecialTermNames(): string[];
private setTermNames;
get Constraints(): SimplexConstraint[];
get Z(): SimplexExpression;
toString(): string;
convertConstraintsToMaxForm(): void;
convertToStandardForm(): this;
}
export declare class SimplexOutput {
private result;
constructor(obj: any);
static getErrorMessage(obj: any): string;
checkForError(): void;
toString(): string;
get Result(): any;
}