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

lp_solve

v0.2.18

Published

A Node.js binding for lp_solve

Downloads

638

Readme

node-lp_solve

A NodeJS module for createing and solving simple Linear Programs using lp_solve.

Example:


// solve http://people.brunel.ac.uk/~mastjjb/jeb/or/morelp.html

var lpsolve = require('lp_solve');
var Row = lpsolve.Row;

var lp = new lpsolve.LinearProgram();

var x = lp.addColumn('x'); // lp.addColumn('x', true) for integer variable
var y = lp.addColumn('y'); // lp.addColumn('y', false, true) for binary variable


var objective = new Row().Add(x, 1).Add(y, 1);

lp.setObjective(objective);

var machineatime = new Row().Add(x, 50).Add(y, 24);
lp.addConstraint(machineatime, 'LE', 2400, 'machine a time')

var machinebtime = new Row().Add(x, 30).Add(y, 33);
lp.addConstraint(machinebtime, 'LE', 2100, 'machine b time')

lp.addConstraint(new Row().Add(x, 1), 'GE', 75 - 30, 'meet demand of x')
lp.addConstraint(new Row().Add(y, 1), 'GE', 95 - 90, 'meet demand of y')

console.log(lp.dumpProgram());
console.log(lp.solve());
console.log('objective =', lp.getObjectiveValue())
console.log('x =', lp.get(x));
console.log('y =', lp.get(y));
console.log('machineatime =', lp.calculate(machineatime));
console.log('machinebtime =', lp.calculate(machinebtime));

Output

minimize: +1 x +1 y
subject to
machine a time:  +50 x +24 y <= 2400
machine b time:  +30 x +33 y <= 2100
meet demand of x:  +1 x >= 45
meet demand of y:  +1 y >= 5

Model name:  '' - run #1
Objective:   Minimize(R0)

SUBMITTED
Model size:        4 constraints,       2 variables,            6 non-zeros.
Sets:                                   0 GUB,                  0 SOS.

Using DUAL simplex for phase 1 and PRIMAL simplex for phase 2.
The primal and dual simplex pricing strategy set to 'Devex'.


Optimal solution                  50 after          2 iter.

Excellent numeric accuracy ||*|| = 0

 MEMO: lp_solve version 5.5.2.0 for 64 bit OS, with 64 bit REAL variables.
      In the total iteration count 2, 0 (0.0%) were bound flips.
      There were 0 refactorizations, 0 triggered by time and 0 by density.
       ... on average 2.0 major pivots per refactorization.
      The largest [LUSOL v2.2.1.0] fact(B) had 5 NZ entries, 1.0x largest basis.
      The constraint matrix inf-norm is 50, with a dynamic range of 50.
      Time to load data was 0.001 seconds, presolve used 0.004 seconds,
       ... 0.003 seconds in simplex solver, in total 0.008 seconds.

{ code: 0, description: 'OPTIMAL' }
objective = 50
x = 45
y = 5
machineatime = 2370
machinebtime = 1515

Access to the full lp_solve api is available through lp.lprec - some functions have not been checked and may not work as expected.

e.g.:

var lpsolve = require('lp_solve');

var lp = new lpsolve.LinearProgram();

lp.lprec.set_presolve(/* PRESOLVE_NONE */ 0, 0);