SCIP Optimization Solver compiled to WebAssembly - LP, MIP, and MINLP support
npm install @areb0s/scip.jsSCIP Optimization Solver compiled to WebAssembly
Solve Linear Programming (LP), Mixed Integer Programming (MIP), and Mixed Integer Nonlinear Programming (MINLP) problems directly in the browser or Node.js.
- LP: Linear Programming
- MIP: Mixed Integer Programming (binary, integer variables)
- MINLP: Mixed Integer Nonlinear Programming (quadratic, polynomial, nonlinear constraints)
- ZIMPL: Full ZIMPL modeling language support for complex problems
- Zero Dependencies: Pure WebAssembly, no native bindings
- Browser & Node.js: Works everywhere JavaScript runs
- Web Worker Support: Non-blocking solver for long computations
- TypeScript: Full type definitions included
``bash`
npm install scip.js
Or use via CDN:
`html`
`javascript
import SCIP from 'scip.js';
const result = await SCIP.solve(
Minimize
obj: 2 x + 3 y
Subject To
c1: x + y >= 4
c2: 2 x + y >= 5
Bounds
x >= 0
y >= 0
End);
console.log(result.status); // 'optimal'
console.log(result.objective); // 7.0
console.log(result.variables); // { x: 1, y: 3 }
`
For MINLP and nonlinear problems, use ZIMPL format:
`javascript
import SCIP from 'scip.js';
// Quadratic optimization: minimize x² + y²
const result = await SCIP.solve(
var x >= 0 <= 10;
var y >= 0 <= 10;
minimize cost: x x + y y;
subto c1: x + y >= 2;, { format: 'zpl' });
console.log(result.status); // 'optimal'
console.log(result.objective); // 2.0
console.log(result.variables); // { x: 1, y: 1 }
`
`javascript
// Portfolio optimization with risk (quadratic)
const result = await SCIP.solve(
set ASSETS := { "A", "B", "C" };
param return[ASSETS] := <"A"> 0.12, <"B"> 0.08, <"C"> 0.15;
param risk[ASSETS] := <"A"> 0.20, <"B"> 0.10, <"C"> 0.30;
var x[ASSETS] >= 0 <= 1;
maximize portfolio_return:
sum in ASSETS: return[a] * x[a]
- 0.5 sum in ASSETS: risk[a] x[a] * x[a];
subto budget: sum in ASSETS: x[a] == 1;, { format: 'zpl' });`
`javascript
// Facility location with economies of scale
const result = await SCIP.solve(
set FACILITIES := { 1 to 5 };
set CUSTOMERS := { 1 to 10 };
param demand[CUSTOMERS] := <1> 10, <2> 15, <3> 20, <4> 12, <5> 18,
<6> 8, <7> 25, <8> 14, <9> 16, <10> 11;
var open[FACILITIES] binary; # 1 if facility is open
var flow[FACILITIES * CUSTOMERS] >= 0; # amount shipped
var capacity[FACILITIES] >= 0 <= 100; # facility capacity
minimize total_cost:
sum
+ sum
+ sum
subto satisfy_demand:
forall
sum
subto capacity_limit:
forall
sum , { format: 'zpl' });`
`javascript
// Nonlinear constraints with polynomials
const result = await SCIP.solve(
var x >= -10 <= 10;
var y >= -10 <= 10;
minimize obj: x + y;
# Polynomial constraint: x³ + y³ >= 8
subto poly: x x x + y y y >= 8;
# Circle constraint: x² + y² <= 25
subto circle: x x + y y <= 25;, { format: 'zpl' });`
Solve an optimization problem.
Parameters:
- problem (string): Problem definitionoptions
- (object, optional):format
- : 'lp' | 'mps' | 'zpl' | 'cip' (default: 'lp')'lp'
- : LP format (linear problems only)'mps'
- : MPS format (linear problems only)'zpl'
- : ZIMPL format (supports MINLP, nonlinear)'cip'
- : CIP format (SCIP's native format)timeLimit
- : Time limit in seconds (default: 3600)gap
- : Relative MIP gap tolerance (e.g., 0.01 for 1%)verbose
- : Enable verbose output (default: false)parameters
- : Additional SCIP parameters
Returns: Promise
`typescript`
interface Solution {
status: 'optimal' | 'infeasible' | 'unbounded' | 'timelimit' | 'unknown' | 'error';
objective: number | null;
variables: Record
statistics: {
solvingTime: number | null;
nodes: number | null;
iterations: number | null;
gap: number | null;
};
}
Convenience wrapper that ensures the problem is minimized.
Convenience wrapper that ensures the problem is maximized.
Initialize the SCIP WASM module. Called automatically on first solve.
Get SCIP version information.
`
\ Comments start with backslash
Minimize (or Maximize)
obj: 2 x + 3 y - z
Subject To
constraint1: x + y >= 10
constraint2: x - y <= 5
Bounds
0 <= x <= 100
y >= 0
General (Integer variables)
x
Binary (0-1 variables)
y
End
`
`zimplSets
set ITEMS := { "apple", "banana", "orange" };
subto nonlinear_constraint:
y y + z z <= 50; # quadratic constraint
`
`javascript
const result = await SCIP.minimize(
obj: 100 x1 + 150 x2
Subject To
labor: 2 x1 + 3 x2 <= 120
materials: 4 x1 + 2 x2 <= 100
Bounds
x1 >= 0
x2 >= 0
End);`
`javascript
const result = await SCIP.maximize(
obj: 60 item1 + 100 item2 + 120 item3
Subject To
weight: 10 item1 + 20 item2 + 30 item3 <= 50
Binary
item1 item2 item3
End);
// result.variables = { item2: 1, item3: 1 }
// result.objective = 220
`
`javascript`
const result = await SCIP.solve(problem, {
format: 'zpl',
timeLimit: 60, // 60 seconds
gap: 0.01, // Stop when within 1% of optimal
verbose: true // Print solver output
});
For long-running optimizations, use the Web Worker API to avoid blocking the main thread:
`javascript
import { createWorkerSolver } from 'scip.js';
const solver = await createWorkerSolver();
// Solve MINLP in background
const result = await solver.solve(nonlinearProblem, {
format: 'zpl',
timeLimit: 300
});
// Clean up when done
solver.terminate();
`
- Docker
- Bash
`bashClone repository
git clone https://github.com/areb0s/scip.js
cd scip.js
The build process:
1. Downloads and compiles GMP (for ZIMPL support)
2. Downloads SCIP Optimization Suite with ZIMPL
3. Compiles with Emscripten to WebAssembly
4. Bundles JavaScript wrapper
| File | Size | Gzipped |
|------|------|---------|
| scip.wasm | ~8 MB | ~2.5 MB |
| scip.js | ~60 KB | ~18 KB |
- Single-threaded: WASM runs single-threaded (use Web Workers for parallelism at application level)
- Memory: Limited to ~2GB (WASM 32-bit limit)
- No callbacks: Progress callbacks not yet supported
Typical solving times in browser (varies by problem complexity):
| Problem Type | Variables | Constraints | Time |
|--------------|-----------|-------------|------|
| LP | 1,000 | 500 | <1s |
| LP | 10,000 | 5,000 | ~5s |
| MIP | 100 binary | 50 | ~1s |
| MIP | 1,000 binary | 500 | ~30s |
| MINLP (quadratic) | 50 | 20 | ~2s |
| MINLP (polynomial) | 100 | 50 | ~10s |
Apache 2.0 (same as SCIP)
- SCIP Optimization Suite - The underlying solver
- ZIMPL - Modeling language for MINLP
- Emscripten - C++ to WebAssembly compiler