Skip to content

Commit 589fea4

Browse files
Add fourth example.
This example is based on issue sloisel/numeric#43.
1 parent 608b323 commit 589fea4

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

test/fourth-test.R

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require(quadprog)
2+
3+
Dmat <- matrix(c(13,18,-6, 18,27,-9, -6,-9,4),3,3)
4+
dvec <- c(-4,0,-100)
5+
Amat <- matrix(c(0,0,-1),3,1)
6+
bvec <- c(-25)
7+
8+
solve.QP(Dmat,dvec,Amat,bvec=bvec,meq=1)

test/fourth-test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
3+
var vows = require("vows"),
4+
assert = require("assert"),
5+
t = require("./fourth");
6+
7+
vows.describe("Test 4").addBatch({
8+
"with the fourth test": {
9+
topic: t.fourth,
10+
11+
"we get the result": function (topic) {
12+
assert.equal("", topic.message);
13+
assert.equal(-4.000000000000016, topic.solution[1]);
14+
assert.equal(11.000000000000007, topic.solution[2]);
15+
assert.equal(25, topic.solution[3]);
16+
assert.equal(2804.500000000001, topic.value[1]);
17+
assert.equal(-3.999999999999967, topic.unconstrained_solution[1]);
18+
assert.equal(-30.666666666666707, topic.unconstrained_solution[2]);
19+
assert.equal(-100.00000000000006, topic.unconstrained_solution[3]);
20+
assert.equal(2, topic.iterations[1]);
21+
assert.equal(0, topic.iterations[2]);
22+
assert.equal(1, topic.iact[1]);
23+
assert.equal(125, topic.Lagrangian[1]);
24+
}
25+
}
26+
27+
}).export(module);

test/fourth.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"use strict";
2+
3+
var qp = require("../lib/quadprog");
4+
5+
function fourth() {
6+
var dmat = [], dvec = [], amat = [], bvec = [], meq;
7+
8+
dmat[1] = [];
9+
dmat[2] = [];
10+
dmat[3] = [];
11+
dmat[1][1] = 13;
12+
dmat[2][1] = 18;
13+
dmat[3][1] = -6;
14+
dmat[1][2] = 18;
15+
dmat[2][2] = 27;
16+
dmat[3][2] = -9;
17+
dmat[1][3] = -6;
18+
dmat[2][3] = -9;
19+
dmat[3][3] = 4;
20+
21+
dvec[1] = -4;
22+
dvec[2] = 0;
23+
dvec[3] = -100;
24+
25+
amat[1] = [];
26+
amat[2] = [];
27+
amat[3] = [];
28+
amat[1][1] = 0;
29+
amat[2][1] = 0;
30+
amat[3][1] = -1;
31+
32+
bvec[1] = -25;
33+
34+
meq = 1;
35+
36+
return qp.solveQP(dmat, dvec, amat, bvec, meq);
37+
}
38+
39+
module.exports = {
40+
name: "fourth test",
41+
fourth: fourth,
42+
tests: {
43+
"fourth": function () {
44+
fourth();
45+
}
46+
}
47+
};

0 commit comments

Comments
 (0)