-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
65 lines (53 loc) · 2.58 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<title>lp-model package demo page</title>
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css">
</head>
<body style="font-size: 1rem;">
<main>
<h1 style="margin: 1rem 0;">lp-model</h1>
<p>
<a href="https://github.com/DominikPeters/lp-model">GitHub</a>
|
<a href="https://www.npmjs.com/package/lp-model">npm</a>.
</p>
<p>This is a demo page for <code>lp-model</code>, a lightweight JS package for specifying LPs and ILPs using a
convenient syntax, used together with the <code>highs-js</code> and <code>glpk.js</code> solvers using
WebAssembly.
</p>
<pre id="output" style="font-size: 0.85rem;">Loading...</pre>
<p>If you see an ILP written in the CPLEX LP format, and the solution <code>x = 1</code>, <code>y = 2</code> returned by HiGHS, GLPK, and jsLPSolver, it worked!</p>
<p><a href="https://github.com/DominikPeters/lp-model/blob/master/index.html">HTML source code</a> of this demo page.</p>
</main>
<!-- <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/lp-model.min.js"></script> -->
<script src="https://cdn.jsdelivr.net/npm/highs/build/highs.js"></script>
<script src="https://unpkg.com/javascript-lp-solver/prod/solver.js"></script>
<script type="module">
import { Model } from "https://cdn.jsdelivr.net/npm/[email protected]/dist/lp-model.es.min.js";
import GLPK from "https://cdn.jsdelivr.net/npm/glpk.js";
async function main() {
const pre = document.getElementById("output");
const m = new Model();
window.m = m;
const x = m.addVar({ name: "x", lb: 0, vtype: "BINARY" });
const y = m.addVar({ name: "y", lb: 0 });
m.setObjective([[4, x], [5, y]], "MAXIMIZE");
m.addConstr([x, [2, y], 3], "<=", 8);
m.addConstr([[3, x], [4, y]], ">=", [12, [-1, x]]);
pre.textContent = m.toLPFormat();
const highs = await Module();
await m.solve(highs);
pre.textContent += `\nHiGHS solution:\n x = ${x.value}\n y = ${y.value}`;
const glpk = await GLPK();
await m.solve(glpk);
pre.textContent += `\n\nGLPK solution:\n x = ${x.value}\n y = ${y.value}`;
const jsLPSolver = window.solver;
await m.solve(jsLPSolver);
pre.textContent += `\n\njsLPSolver solution:\n x = ${x.value}\n y = ${y.value}`;
}
window.main = main;
main();
</script>
</body>
</html>