npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-simplex

v1.0.1

Published

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

Downloads

85

Readme

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