-
Notifications
You must be signed in to change notification settings - Fork 19
/
lp.html
67 lines (59 loc) · 2.1 KB
/
lp.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
66
67
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta content="">
<style></style>
</head>
<body>
<script type="module">
import GLPK from '../dist/index.js';
(async () => {
const glpk = await GLPK();
function print(res) {
const el = window.document.getElementById('out');
el.innerHTML = `Solution: LP \n\n ${JSON.stringify(res, null, 2)}`;
};
const lp = {
name: 'LP',
objective: {
direction: glpk.GLP_MAX,
name: 'obj',
vars: [
{ name: 'x1', coef: 0.6 },
{ name: 'x2', coef: 0.5 }
]
},
subjectTo: [
{
name: 'cons1',
vars: [
{ name: 'x1', coef: 1.0 },
{ name: 'x2', coef: 2.0 }
],
bnds: { type: glpk.GLP_UP, ub: 1.0, lb: 0.0 }
},
{
name: 'cons2',
vars: [
{ name: 'x1', coef: 3.0 },
{ name: 'x2', coef: 1.0 }
],
bnds: { type: glpk.GLP_UP, ub: 2.0, lb: 0.0 }
}
]
};
const opt = {
msglev: glpk.GLP_MSG_OFF
};
glpk.solve(lp, opt)
.then(res => print(res))
.catch(err => console.log(err));
console.log(await glpk.solve(lp, glpk.GLP_MSG_DBG));
window.document.getElementById('cplex').innerHTML = await glpk.write(lp);
})();
</script>
<pre id='cplex'></pre>
<pre id='out'></pre>
</body>
</html>