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

clp-wasm

v0.0.20

Published

A CLP wrapper for WASM

Downloads

185

Readme

CLP Linear Programming solver ported to WebAssembly

This project brings linear programming library CLP to the browser and node.js via WebAssembly. Given the limited precision of standard double arithmetics when dealing with values over 2^53, the library is compiled with custom floating point precision mapped to boost::multiprecision::number<mp::cpp_dec_float<100>, mp::et_off> (i.e. floating point with 100 decimal values). The interface supports a high level method solve(problem: string, precision?: number): string, where problem is a string specifyign the linear programming input in LP format and precision is just the numeric precision of the values printed as strings when returning the result object. However a low-level API also exist for finer grain control.

Live demo

You can try the solver here

Building from source

You'll need docker installed in your system. Simply run:

npm install
npm run build
npm run test # Optionally run the test suite

Usage

For a browser-based example, please look at the live demo. When running in a browser CLP code will run in a web worker to avoid blocking the UI thread.

To install from NPM

npm install clp-wasm

Then import the library in Javasript and use it:

require("clp-wasm/clp-wasm").then(async (clp) => {
  const lp = `Maximize
   obj: + 0.6 x1 + 0.5 x2
   Subject To
   cons1: + x1 + 2 x2 <= 1
   cons2: + 3 x1 + x2 <= 2
   End`;
  console.log(await clp.solve(lp)); // Prints a result object with solution values, objective, etc.
});

If you don't want to deal with the clp-wasm.wasm asset content and don't mind the extra size and Base64 conversion, clp-wasm.all.js includes the wasm blob as a Base64 string can be used without any extra dependencies.

Diving into the code

ClpWrapper is the main class to look at. It wraps an instance of ClpSimplex, which is the main class in the Clp library. in solver/bindings.cc you can see what methods of the class are exposed to Javascript.

The user guide of Clp itself can be found here and a description of the methods that allows the user to load/set the problem, control algorithm paramters and get at the solution can be found here. Only some methods are exposed to Javascript at the moment.

Clp code comes with a relative large number of verbose messages that are printed to standard output (console when compiled to webasembly) by default. Because of that, we suppressed when creating the javascript glue code that ultimately executes WebAssembly. If you want/need to see Clp native output, you can rebuild the module after commenting out the line Module['print'] = (x) => { }; in common/pre.js with npm run build.