model

Provides functions to parse the input objective and constraints and build a tableau for processing.

Source:

Methods

(inner) parseModel(objective, constraints) → {Array}

Source:

Parses the objective function and the array of constraints into a tableau suitable for processing.

Parameters:
Name Type Description
objective string

The objective function in the form of 'Maximize Z = 1x + 5y'.

constraints Array

A two-dimensional array of strings detailing the constraints in the form of ['x + y <= 4', '2x - y <= 7', ...].

Returns:

An array containing the model in the form of a tableau (an n x m array of coefficients), the variable names (an array of strings), and the type (string) ['max' | 'min'].

Type
Array

(inner) parseEquation(equation) → {Array}

Source:

Parses each constraint equation separably into their coefficients and variables.

Parameters:
Name Type Description
equation string

An individual constraint equation in the form of 'x + y <= 4'.

Returns:

An array consisting of two arrays: an array of coefficients (strings) and an array of variables (strings).

Type
Array

(inner) buildTableau(variables, coefficients, constraints, equalities, objectiveVariable, type) → {Array}

Source:

Builds a tableau suitable for executing the simplex method.

Parameters:
Name Type Description
variables Array

An array of strings representing the variables (eg., ['x1, 'y1', ...]).

coefficients Array

A two-dimensional array of numbers representing the coefficients of the variables on the left hand side of the constraint equations and the right hand side of the objective function (e.g., [[3, 4.5, 7, ...], [1, 17, 8, ...], [12, 11, 2.2, ...]]).

constraints Array

An array of numbers representing the constraint values on the right hand side of the constraint equation (e.g., [8, 2.1, 45, ...]).

equalities Array

An array of strings representing the constraint operators (e.g., ['=', '<=', '>=', ...]).

objectiveVariable string

A string representing the objective variable name for the left hand side of the objective function.

type string

The type of optimization ['min' | 'max'].

Returns:

A two-dimensional array containing the simplex tableau (a two-dimensional array of numbers) and the model variables. For a model with a <= type a positive slack variable is added. For a >= type a negative extra and positive artificial variables are added. For an = type model a positive artificial variable is added.

Type
Array