1
0
Fork
You've already forked highs-js
0
Javscript linear programming library https://lovasoa.github.io/highs-js/
  • JavaScript 84.2%
  • Dockerfile 9.6%
  • Shell 6.2%
2022年05月22日 19:23:42 +00:00
.devcontainer add a dirty hotpatch for #14 2022年05月07日 17:42:43 +00:00
.github/workflows deploy in release 2022年05月07日 17:27:33 +00:00
.vscode Add a dev container for vscode 2021年11月17日 11:42:10 +00:00
demo demo: pass errors as strings 2021年05月03日 17:36:54 +02:00
HiGHS @81947249d6 update highs 2022年05月22日 19:23:42 +00:00
src Avoid treating loadModel warnings as errors ( #18 ) 2022年05月22日 20:16:11 +02:00
tests add row names 2022年05月22日 19:20:41 +00:00
.gitignore Implement model passing and solution parsing 2021年03月17日 16:50:20 +01:00
.gitmodules Add HiGHS 2021年03月16日 21:35:31 +01:00
.npmignore ignore demo on npm 2021年03月18日 11:32:21 +01:00
build.sh allow dynamic memory allocation 2021年12月19日 20:39:07 +00:00
example.js add runKit 2021年03月18日 11:54:44 +01:00
exported_functions.json add support for options of type double 2021年12月02日 14:03:34 +00:00
package-lock.json update highs 2022年05月22日 19:23:42 +00:00
package.json update highs 2022年05月22日 19:23:42 +00:00
README.md add row names 2022年05月22日 19:20:41 +00:00
types.d.ts add row names 2022年05月22日 19:20:41 +00:00

highs-js

npm version CI status package size

This is a javascript mixed integer linear programming library. It is built by compiling a high-performance C++ solver developed by the University of Edinburgh, (HiGHS), to WebAssembly using emscripten.

Demo

See the online demo at: https://lovasoa.github.io/highs-js/

Usage

const highs_settings = {
 // In node, locateFile is not needed
 // In the browser, point locateFile to the URL of the wasm file (see below)
 locateFile: (file) => "https://lovasoa.github.io/highs-js/" + file
};
const highs_promise = require("highs")(highs_settings);
const PROBLEM = `Maximize
 obj:
 x1 + 2 x2 + 4 x3 + x4
Subject To
 c1: - x1 + x2 + x3 + 10 x4 <= 20
 c2: x1 - 4 x2 + x3 <= 30
 c3: x2 - 0.5 x4 = 0
Bounds
 0 <= x1 <= 40
 2 <= x4 <= 3
End`;
const EXPECTED_SOLUTION = {
 IsLinear: true,
 IsQuadratic: false,
 Status: 'Optimal',
 ObjectiveValue: 87.5,
 Columns: {
 x1: {
 Index: 0,
 Status: 'BS',
 Lower: 0,
 Upper: 40,
 Primal: 17.5,
 Dual: -0,
 Name: 'x1'
 },
 x2: {
 Index: 1,
 Status: 'BS',
 Lower: 0,
 Upper: Infinity,
 Primal: 1,
 Dual: -0,
 Name: 'x2'
 },
 x3: {
 Index: 2,
 Status: 'BS',
 Lower: 0,
 Upper: Infinity,
 Primal: 16.5,
 Dual: -0,
 Name: 'x3'
 },
 x4: {
 Index: 3,
 Status: 'LB',
 Lower: 2,
 Upper: 3,
 Primal: 2,
 Dual: -8.75,
 Name: 'x4'
 }
 },
 Rows: [
 {
 Index: 0,
 Name: 'c1',
 Status: 'UB',
 Lower: -Infinity,
 Upper: 20,
 Primal: 20,
 Dual: 1.5
 },
 {
 Index: 1,
 Name: 'c2',
 Status: 'UB',
 Lower: -Infinity,
 Upper: 30,
 Primal: 30,
 Dual: 2.5
 },
 {
 Index: 2,
 Name: 'c3',
 Status: 'UB',
 Lower: 0,
 Upper: 0,
 Primal: 0,
 Dual: 10.5
 }
 ]
};
async function test() {
 const highs = await highs_promise;
 const sol = highs.solve(PROBLEM);
 require("assert").deepEqual(sol, EXPECTED_SOLUTION);
}

The problem has to be passed in the CPLEX .lp file format.

For a more complete example, see the demo folder.

Loading the wasm file

This package requires a wasm file. You can find it in node_modules/highs/build/highs.wasm inside the NPM package, or download it from the release page. By default, it will be loaded from the same path as the javascript file, which means you have to add the wasm file to your assets.

Alternatively, if you don't want to bother with that, if you are running highs-js in a web browser (and not in node), you can load the file directly from github:

const highs_loader = require("highs");
const highs = await highs_loader({
 // In a browser, one can load the wasm file from github
 locateFile: (file) => "https://lovasoa.github.io/highs-js/" + file
});

Passing custom options

HiGHS is configurable through a large number of options.

You can pass options as the second parameter to solve :

const highs_promise = require("highs")(highs_settings);
const highs = await highs_promise;
const sol = highs.solve(PROBLEM, {
 "allowed_cost_scale_factor": 2,
 "run_crossover": true,
 "presolve": "on",
});