simple-simplex

1.0.1 • Public • Published

simple-simplex

A JavaScript implementation of the simplex algorithm for the Linear Programming problem

Table of Contents

Background

Linear programming is a class of problems of the following form: Optimize an objective function, subject to a set of linear constraints.

Example: Minimize 5a + 4b - 2c, subject to a + b + c <= 1200 and 2b + 4c >= 250.

When we have 3 dimensional vectors and a low number of linear constraints, the problem is relatively easy to solve. However, linear programming problems usually involve thousands of dimensions and constraints. With such problems, it becomes quickly infeasible to use naive solutions.

There are many solutions to the Linear Programming problem, all with their pros and cons. This project uses the Simplex Method, invented by George Bernard Dantzig in 1945.

Acknowledgements

Special thanks to Steven R. Costenoble PhD and Stefan Waner PhD. When we were searching for a robust open source JavaScript implementation of the simplex method, we were mostly disappointed. We then stumbled upon their excellent old-school applied maths website: http://zweigmedia.com. After contacting them, they kindly gave us permission to build on their simplex implementation. This project is a complete overhaul, so no code was copied from their implementation. However, our solution was influenced by their website, and also their book: Finite Mathematics.

Install

npm install simple-simplex

Usage

Let's solve the following problem:

Maximize 70a + 210b + 140c, subject to the following constraints:

  • a + b + c <= 100
  • 5a + 4b + 4c <= 480
  • 40a + 20b + 30c <= 3200

In order to solve this problem, we need to convert it to a language that our algorithm can understand.

Once the problem is converted, we initialize a solver instance.

We then call solver.solve with the solution method we want. There are many different methods that can solve the Linear Programming problem. We will update the readme once we implement new methods. For now, use the following way to call the solver.solve function.

Finally, once the solver returns a result, we can see a solution and some meta data, such as isOptimal and allTableaus, as well as solution.

const SimpleSimplex = require('simple-simplex');
 
// initialize a solver
const solver = new SimpleSimplex({
  objective: {
    a: 70,
    b: 210,
    c: 140,
  },
  constraints: [
    {
      namedVector: { a: 1, b: 1, c: 1 },
      constraint: '<=',
      constant: 100,
    },
    {
      namedVector: { a: 5, b: 4, c: 4 },
      constraint: '<=',
      constant: 480,
    },
    {
      namedVector: { a: 40, b: 20, c: 30 },
      constraint: '<=',
      constant: 3200,
    },
  ],
  optimizationType: 'max',
});
 
// call the solve method with a method name
const result = solver.solve({
  methodName: 'simplex',
});
 
// see the solution and meta data
console.log({
  solution: result.solution,
  isOptimal: result.details.isOptimal,
});

Maintainers

@mechanical-turk

PRs accepted.

License

MIT © 2017 Kerem Kazan

Package Sidebar

Install

npm i simple-simplex

Weekly Downloads

8

Version

1.0.1

License

MIT

Last publish

Collaborators

  • mechanical-turk