jsxgraph 1.4.4 → 1.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/distrib/README.md +24 -0
- package/distrib/geogebra.min.js +1 -1
- package/distrib/geonext.min.js +1 -1
- package/distrib/index.d.ts +27 -7
- package/distrib/intergeo.min.js +1 -1
- package/distrib/jsxgraphcore.js +3 -3
- package/distrib/jsxgraphsrc.js +464 -273
- package/distrib/sketch.min.js +1 -1
- package/package.json +1 -1
- package/src/3d/point3d.js +38 -0
- package/src/3d/view3d.js +1 -1
- package/src/base/board.js +134 -65
- package/src/base/constants.js +1 -1
- package/src/base/text.js +42 -13
- package/src/base/ticks.js +1 -1
- package/src/jsxgraph.js +2 -1
- package/src/math/nlp.js +205 -173
- package/src/options.js +27 -5
- package/src/parser/jessiecode.js +1 -1
- package/src/utils/env.js +10 -10
package/src/math/nlp.js
CHANGED
|
@@ -33,43 +33,43 @@
|
|
|
33
33
|
*/
|
|
34
34
|
/*
|
|
35
35
|
* jcobyla
|
|
36
|
-
*
|
|
36
|
+
*
|
|
37
37
|
* The MIT License
|
|
38
38
|
*
|
|
39
39
|
* Copyright (c) 2012 Anders Gustafsson, Cureos AB.
|
|
40
40
|
*
|
|
41
41
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
|
|
42
|
-
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
43
|
-
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
42
|
+
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
|
|
43
|
+
* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
44
44
|
* subject to the following conditions:
|
|
45
45
|
*
|
|
46
46
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
47
47
|
*
|
|
48
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
49
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
50
|
-
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
48
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
49
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
|
50
|
+
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
51
51
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
52
|
-
*
|
|
52
|
+
*
|
|
53
53
|
* Remarks:
|
|
54
|
-
*
|
|
54
|
+
*
|
|
55
55
|
* The original Fortran 77 version of this code was by Michael Powell (M.J.D.Powell @ damtp.cam.ac.uk)
|
|
56
56
|
* The Fortran 90 version was by Alan Miller (Alan.Miller @ vic.cmis.csiro.au). Latest revision - 30 October 1998
|
|
57
57
|
*/
|
|
58
58
|
|
|
59
59
|
/**
|
|
60
60
|
* Constrained Optimization BY Linear Approximation in Java.
|
|
61
|
-
*
|
|
61
|
+
*
|
|
62
62
|
* COBYLA2 is an implementation of Powell's nonlinear derivative free constrained optimization that uses
|
|
63
63
|
* a linear approximation approach. The algorithm is a sequential trust region algorithm that employs linear
|
|
64
64
|
* approximations to the objective and constraint functions, where the approximations are formed by linear
|
|
65
65
|
* interpolation at n + 1 points in the space of the variables and tries to maintain a regular shaped simplex
|
|
66
66
|
* over iterations.
|
|
67
|
-
*
|
|
67
|
+
*
|
|
68
68
|
* It solves nonsmooth NLP with a moderate number of variables (about 100). Inequality constraints only.
|
|
69
|
-
*
|
|
69
|
+
*
|
|
70
70
|
* The initial point X is taken as one vertex of the initial simplex with zero being another, so, X should
|
|
71
71
|
* not be entered as the zero vector.
|
|
72
|
-
*
|
|
72
|
+
*
|
|
73
73
|
* @author Anders Gustafsson, Cureos AB. Translation to Javascript by Reinhard Oldenburg, Goethe-University
|
|
74
74
|
*/
|
|
75
75
|
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
utils/type
|
|
83
83
|
*/
|
|
84
84
|
|
|
85
|
-
define(['jxg'], function (JXG) {
|
|
85
|
+
define(['jxg', 'utils/type'], function (JXG, Type) {
|
|
86
86
|
|
|
87
87
|
"use strict";
|
|
88
88
|
|
|
@@ -90,20 +90,29 @@ define(['jxg'], function (JXG) {
|
|
|
90
90
|
* The JXG.Math.Nlp namespace holds numerical algorithms for non-linear optimization.
|
|
91
91
|
* @name JXG.Math.Nlp
|
|
92
92
|
* @namespace
|
|
93
|
-
*
|
|
93
|
+
*
|
|
94
94
|
*/
|
|
95
|
-
JXG.Math.Nlp =
|
|
95
|
+
JXG.Math.Nlp = {
|
|
96
96
|
|
|
97
|
-
arr: function(n) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
arr: function (n) {
|
|
98
|
+
// Is 0 initialized
|
|
99
|
+
return new Float64Array(n);
|
|
100
|
+
|
|
101
|
+
// var a = new Array(n),
|
|
102
|
+
// i;
|
|
103
|
+
|
|
104
|
+
// if (Type.exists(a.fill)) {
|
|
105
|
+
// a.fill(0.0, 0, n);
|
|
106
|
+
// } else {
|
|
107
|
+
// for (i = 0; i < n; i++) {
|
|
108
|
+
// a[i] = 0.0;
|
|
109
|
+
// }
|
|
110
|
+
// }
|
|
111
|
+
|
|
112
|
+
// return a;
|
|
104
113
|
},
|
|
105
114
|
|
|
106
|
-
arr2: function(n, m) {
|
|
115
|
+
arr2: function (n, m) {
|
|
107
116
|
var i = 0,
|
|
108
117
|
a = new Array(n);
|
|
109
118
|
|
|
@@ -114,7 +123,7 @@ define(['jxg'], function (JXG) {
|
|
|
114
123
|
return a;
|
|
115
124
|
},
|
|
116
125
|
|
|
117
|
-
arraycopy: function(x, a, iox, b, n) {
|
|
126
|
+
arraycopy: function (x, a, iox, b, n) {
|
|
118
127
|
var i = 0;
|
|
119
128
|
while (i < n) {
|
|
120
129
|
iox[i + b] = x[i + a];
|
|
@@ -144,7 +153,7 @@ define(['jxg'], function (JXG) {
|
|
|
144
153
|
* @param maxfun Maximum number of function evaluations before terminating.
|
|
145
154
|
* @returns {Number} Exit status of the COBYLA2 optimization.
|
|
146
155
|
*/
|
|
147
|
-
FindMinimum: function(calcfc, n,
|
|
156
|
+
FindMinimum: function (calcfc, n, m, x, rhobeg, rhoend, iprint, maxfun) {
|
|
148
157
|
// CobylaExitStatus FindMinimum(final Calcfc calcfc, int n, int m, double[] x, double rhobeg, double rhoend, int iprint, int maxfun)
|
|
149
158
|
// This subroutine minimizes an objective function F(X) subject to M
|
|
150
159
|
// inequality constraints on X, where X is a vector of variables that has
|
|
@@ -208,16 +217,16 @@ define(['jxg'], function (JXG) {
|
|
|
208
217
|
|
|
209
218
|
// Internal representation of the objective and constraints calculation method,
|
|
210
219
|
// accounting for that X and CON arrays in the cobylb method are base-1 arrays.
|
|
211
|
-
fcalcfc = function(n, m, thisx, con) { // int n, int m, double[] x, double[] con
|
|
212
|
-
|
|
213
|
-
|
|
220
|
+
fcalcfc = function (n, m, thisx, con) { // int n, int m, double[] x, double[] con
|
|
221
|
+
var ix = that.arr(n),
|
|
222
|
+
ocon, f;
|
|
214
223
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
224
|
+
that.arraycopy(thisx, 1, ix, 0, n);
|
|
225
|
+
ocon = that.arr(m);
|
|
226
|
+
f = calcfc(n, m, ix, ocon);
|
|
227
|
+
that.arraycopy(ocon, 0, con, 1, m);
|
|
228
|
+
return f;
|
|
229
|
+
};
|
|
221
230
|
|
|
222
231
|
status = this.cobylb(fcalcfc, n, m, mpp, iox, rhobeg, rhoend, iprint, maxfun);
|
|
223
232
|
this.arraycopy(iox, 1, x, 0, n);
|
|
@@ -229,18 +238,18 @@ define(['jxg'], function (JXG) {
|
|
|
229
238
|
// double rhobeg, double rhoend, int iprint, int maxfun)
|
|
230
239
|
/**
|
|
231
240
|
* JavaScript implementation of the non-linear optimization method COBYLA.
|
|
232
|
-
* @param {Function} calcfc
|
|
233
|
-
* @param {Number} n
|
|
234
|
-
* @param {Number} m
|
|
235
|
-
* @param {Number} mpp
|
|
236
|
-
* @param {Number} x
|
|
237
|
-
* @param {Number} rhobeg
|
|
238
|
-
* @param {Number} rhoend
|
|
239
|
-
* @param {Number} iprint
|
|
240
|
-
* @param {Number} maxfun
|
|
241
|
+
* @param {Function} calcfc
|
|
242
|
+
* @param {Number} n
|
|
243
|
+
* @param {Number} m
|
|
244
|
+
* @param {Number} mpp
|
|
245
|
+
* @param {Number} x
|
|
246
|
+
* @param {Number} rhobeg
|
|
247
|
+
* @param {Number} rhoend
|
|
248
|
+
* @param {Number} iprint
|
|
249
|
+
* @param {Number} maxfun
|
|
241
250
|
* @returns {Number} Exit status of the COBYLA2 optimization
|
|
242
251
|
*/
|
|
243
|
-
cobylb: function (calcfc, n,
|
|
252
|
+
cobylb: function (calcfc, n, m, mpp, x, rhobeg, rhoend, iprint, maxfun) {
|
|
244
253
|
// calcf ist funktion die aufgerufen wird wie calcfc(n, m, ix, ocon)
|
|
245
254
|
// N.B. Arguments CON, SIM, SIMI, DATMAT, A, VSIG, VETA, SIGBAR, DX, W & IACT
|
|
246
255
|
// have been removed.
|
|
@@ -416,8 +425,7 @@ define(['jxg'], function (JXG) {
|
|
|
416
425
|
sim[i][np] += temp;
|
|
417
426
|
|
|
418
427
|
tempa = 0.0;
|
|
419
|
-
for (k = 1; k <= n; ++k)
|
|
420
|
-
{
|
|
428
|
+
for (k = 1; k <= n; ++k) {
|
|
421
429
|
sim[i][k] -= temp;
|
|
422
430
|
tempa -= simi[k][i];
|
|
423
431
|
}
|
|
@@ -428,13 +436,17 @@ define(['jxg'], function (JXG) {
|
|
|
428
436
|
// Make an error return if SIGI is a poor approximation to the inverse of
|
|
429
437
|
// the leading N by N submatrix of SIG.
|
|
430
438
|
error = 0.0;
|
|
431
|
-
|
|
432
|
-
for (
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
439
|
+
if (false) {
|
|
440
|
+
for (i = 1; i <= n; ++i) {
|
|
441
|
+
for (j = 1; j <= n; ++j) {
|
|
442
|
+
temp = this.DOT_PRODUCT_ROW_COL(simi, i, sim, j, 1, n) - (i === j ? 1.0 : 0.0);
|
|
443
|
+
// temp = this.DOT_PRODUCT(
|
|
444
|
+
// this.PART(this.ROW(simi, i), 1, n),
|
|
445
|
+
// this.PART(this.COL(sim, j), 1, n)
|
|
446
|
+
// ) - (i === j ? 1.0 : 0.0);
|
|
447
|
+
|
|
448
|
+
error = Math.max(error, Math.abs(temp));
|
|
449
|
+
}
|
|
438
450
|
}
|
|
439
451
|
}
|
|
440
452
|
if (error > 0.1) {
|
|
@@ -453,8 +465,9 @@ define(['jxg'], function (JXG) {
|
|
|
453
465
|
}
|
|
454
466
|
|
|
455
467
|
for (i = 1; i <= n; ++i) {
|
|
456
|
-
a[i][k] = (k === mp ? -1.0 : 1.0) *
|
|
457
|
-
this.
|
|
468
|
+
a[i][k] = (k === mp ? -1.0 : 1.0) *
|
|
469
|
+
this.DOT_PRODUCT_ROW_COL(w, -1, simi, i, 1, n);
|
|
470
|
+
// this.DOT_PRODUCT(this.PART(w, 1, n), this.PART(this.COL(simi, i), 1, n));
|
|
458
471
|
}
|
|
459
472
|
}
|
|
460
473
|
|
|
@@ -466,11 +479,9 @@ define(['jxg'], function (JXG) {
|
|
|
466
479
|
|
|
467
480
|
for (j = 1; j <= n; ++j) {
|
|
468
481
|
wsig = 0.0;
|
|
469
|
-
for (k = 1; k <= n; ++k) {
|
|
470
|
-
wsig += simi[j][k] * simi[j][k];
|
|
471
|
-
}
|
|
472
482
|
weta = 0.0;
|
|
473
483
|
for (k = 1; k <= n; ++k) {
|
|
484
|
+
wsig += simi[j][k] * simi[j][k];
|
|
474
485
|
weta += sim[k][j] * sim[k][j];
|
|
475
486
|
}
|
|
476
487
|
vsig[j] = 1.0 / Math.sqrt(wsig);
|
|
@@ -507,10 +518,8 @@ define(['jxg'], function (JXG) {
|
|
|
507
518
|
cvmaxm = 0.0;
|
|
508
519
|
total = 0.0;
|
|
509
520
|
for (k = 1; k <= mp; ++k) {
|
|
510
|
-
total = this.DOT_PRODUCT(
|
|
511
|
-
|
|
512
|
-
this.PART(dx, 1, n)
|
|
513
|
-
);
|
|
521
|
+
// total = this.DOT_PRODUCT(this.PART(this.COL(a, k), 1, n), this.PART(dx, 1, n));
|
|
522
|
+
total = this.DOT_PRODUCT_ROW_COL(dx, -1, a, k, 1, n);
|
|
514
523
|
if (k < mp) {
|
|
515
524
|
temp = datmat[k][np];
|
|
516
525
|
cvmaxp = Math.max(cvmaxp, -total - temp);
|
|
@@ -532,10 +541,8 @@ define(['jxg'], function (JXG) {
|
|
|
532
541
|
|
|
533
542
|
for (j = 1; j <= n; ++j) {
|
|
534
543
|
if (j !== jdrop) {
|
|
535
|
-
temp = this.DOT_PRODUCT(
|
|
536
|
-
|
|
537
|
-
this.PART(dx, 1, n)
|
|
538
|
-
);
|
|
544
|
+
// temp = this.DOT_PRODUCT(this.PART(this.ROW(simi, j), 1, n), this.PART(dx, 1, n));
|
|
545
|
+
temp = this.DOT_PRODUCT_ROW_COL(simi, j, dx, -1, 1, n);
|
|
539
546
|
for (k = 1; k <= n; ++k) {
|
|
540
547
|
simi[j][k] -= temp * simi[jdrop][k];
|
|
541
548
|
}
|
|
@@ -565,7 +572,8 @@ define(['jxg'], function (JXG) {
|
|
|
565
572
|
resnew = 0.0;
|
|
566
573
|
con[mp] = 0.0;
|
|
567
574
|
for (k = 1; k <= mp; ++k) {
|
|
568
|
-
total = con[k] - this.DOT_PRODUCT(this.PART(this.COL(a, k), 1, n), this.PART(dx, 1, n));
|
|
575
|
+
//total = con[k] - this.DOT_PRODUCT(this.PART(this.COL(a, k), 1, n), this.PART(dx, 1, n));
|
|
576
|
+
total = con[k] - this.DOT_PRODUCT_ROW_COL(dx, -1, a, k, 1, n);
|
|
569
577
|
if (k < mp) { resnew = Math.max(resnew, total); }
|
|
570
578
|
}
|
|
571
579
|
|
|
@@ -613,7 +621,8 @@ define(['jxg'], function (JXG) {
|
|
|
613
621
|
ratio = trured <= 0.0 ? 1.0 : 0.0;
|
|
614
622
|
jdrop = 0;
|
|
615
623
|
for (j = 1; j <= n; ++j) {
|
|
616
|
-
temp = Math.abs(this.DOT_PRODUCT(this.PART(this.ROW(simi, j), 1, n), this.PART(dx, 1, n)));
|
|
624
|
+
// temp = Math.abs(this.DOT_PRODUCT(this.PART(this.ROW(simi, j), 1, n), this.PART(dx, 1, n)));
|
|
625
|
+
temp = Math.abs(this.DOT_PRODUCT_ROW_COL(simi, j, dx, -1, 1, n));
|
|
617
626
|
if (temp > ratio) {
|
|
618
627
|
jdrop = j;
|
|
619
628
|
ratio = temp;
|
|
@@ -653,7 +662,8 @@ define(['jxg'], function (JXG) {
|
|
|
653
662
|
for (k = 1; k <= n; ++k) { simi[jdrop][k] /= temp; }
|
|
654
663
|
for (j = 1; j <= n; ++j) {
|
|
655
664
|
if (j !== jdrop) {
|
|
656
|
-
temp = this.DOT_PRODUCT(this.PART(this.ROW(simi, j), 1, n), this.PART(dx, 1, n));
|
|
665
|
+
// temp = this.DOT_PRODUCT(this.PART(this.ROW(simi, j), 1, n), this.PART(dx, 1, n));
|
|
666
|
+
temp = this.DOT_PRODUCT_ROW_COL(simi, j, dx, -1, 1, n);
|
|
657
667
|
for (k = 1; k <= n; ++k) {
|
|
658
668
|
simi[j][k] -= temp * simi[jdrop][k];
|
|
659
669
|
}
|
|
@@ -706,7 +716,7 @@ define(['jxg'], function (JXG) {
|
|
|
706
716
|
}
|
|
707
717
|
}
|
|
708
718
|
if (iprint >= 2) {
|
|
709
|
-
console.log("Reduction in RHO to "+rho+" and PARMU = "+parmu);
|
|
719
|
+
console.log("Reduction in RHO to " + rho + " and PARMU = " + parmu);
|
|
710
720
|
}
|
|
711
721
|
if (iprint === 2) {
|
|
712
722
|
this.PrintIterationResult(nfvals, datmat[mp][np], datmat[mpp][np], this.COL(sim, np), n, iprint);
|
|
@@ -742,7 +752,7 @@ define(['jxg'], function (JXG) {
|
|
|
742
752
|
return status;
|
|
743
753
|
},
|
|
744
754
|
|
|
745
|
-
trstlp: function(n,
|
|
755
|
+
trstlp: function (n, m, a, b, rho, dx) { //(int n, int m, double[][] a, double[] b, double rho, double[] dx)
|
|
746
756
|
// N.B. Arguments Z, ZDOTA, VMULTC, SDIRN, DXNEW, VMULTD & IACT have been removed.
|
|
747
757
|
|
|
748
758
|
// This subroutine calculates an N-component vector DX by applying the
|
|
@@ -856,9 +866,8 @@ define(['jxg'], function (JXG) {
|
|
|
856
866
|
|
|
857
867
|
L_70:
|
|
858
868
|
do {
|
|
859
|
-
optnew = (mcon === m) ? resmax : -this.DOT_PRODUCT(
|
|
860
|
-
|
|
861
|
-
);
|
|
869
|
+
// optnew = (mcon === m) ? resmax : -this.DOT_PRODUCT(this.PART(dx, 1, n), this.PART(this.COL(a, mcon), 1, n));
|
|
870
|
+
optnew = (mcon === m) ? resmax : -this.DOT_PRODUCT_ROW_COL(dx, -1, a, mcon, 1, n);
|
|
862
871
|
|
|
863
872
|
if (icount === 0 || optnew < optold) {
|
|
864
873
|
optold = optnew;
|
|
@@ -889,9 +898,9 @@ define(['jxg'], function (JXG) {
|
|
|
889
898
|
kp = k + 1;
|
|
890
899
|
kk = iact[kp];
|
|
891
900
|
sp = this.DOT_PRODUCT(
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
901
|
+
this.PART(this.COL(z, k), 1, n),
|
|
902
|
+
this.PART(this.COL(a, kk), 1, n)
|
|
903
|
+
);
|
|
895
904
|
temp = Math.sqrt(sp * sp + zdota[kp] * zdota[kp]);
|
|
896
905
|
alpha = zdota[kp] / temp;
|
|
897
906
|
beta = sp / temp;
|
|
@@ -919,9 +928,8 @@ define(['jxg'], function (JXG) {
|
|
|
919
928
|
temp = 1.0 / zdota[nact];
|
|
920
929
|
for (k = 1; k <= n; ++k) { sdirn[k] = temp * z[k][nact]; }
|
|
921
930
|
} else {
|
|
922
|
-
temp = this.DOT_PRODUCT(
|
|
923
|
-
|
|
924
|
-
);
|
|
931
|
+
// temp = this.DOT_PRODUCT(this.PART(sdirn, 1, n), this.PART(this.COL(z, nact + 1), 1, n));
|
|
932
|
+
temp = this.DOT_PRODUCT_ROW_COL(sdirn, -1, z, nact + 1, 1, n);
|
|
925
933
|
for (k = 1; k <= n; ++k) { sdirn[k] -= temp * z[k][nact + 1]; }
|
|
926
934
|
}
|
|
927
935
|
} else {
|
|
@@ -930,34 +938,34 @@ define(['jxg'], function (JXG) {
|
|
|
930
938
|
tot = 0.0;
|
|
931
939
|
|
|
932
940
|
// {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
941
|
+
k = n;
|
|
942
|
+
while (k > nact) {
|
|
943
|
+
sp = 0.0;
|
|
944
|
+
spabs = 0.0;
|
|
945
|
+
for (i = 1; i <= n; ++i) {
|
|
946
|
+
temp = z[i][k] * dxnew[i];
|
|
947
|
+
sp += temp;
|
|
948
|
+
spabs += Math.abs(temp);
|
|
949
|
+
}
|
|
950
|
+
acca = spabs + 0.1 * Math.abs(sp);
|
|
951
|
+
accb = spabs + 0.2 * Math.abs(sp);
|
|
952
|
+
if (spabs >= acca || acca >= accb) { sp = 0.0; }
|
|
953
|
+
if (tot === 0.0) {
|
|
954
|
+
tot = sp;
|
|
955
|
+
} else {
|
|
956
|
+
kp = k + 1;
|
|
957
|
+
temp = Math.sqrt(sp * sp + tot * tot);
|
|
958
|
+
alpha = sp / temp;
|
|
959
|
+
beta = tot / temp;
|
|
960
|
+
tot = temp;
|
|
937
961
|
for (i = 1; i <= n; ++i) {
|
|
938
|
-
temp = z[i][k] *
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
}
|
|
942
|
-
acca = spabs + 0.1 * Math.abs(sp);
|
|
943
|
-
accb = spabs + 0.2 * Math.abs(sp);
|
|
944
|
-
if (spabs >= acca || acca >= accb) { sp = 0.0; }
|
|
945
|
-
if (tot === 0.0) {
|
|
946
|
-
tot = sp;
|
|
947
|
-
} else {
|
|
948
|
-
kp = k + 1;
|
|
949
|
-
temp = Math.sqrt(sp * sp + tot * tot);
|
|
950
|
-
alpha = sp / temp;
|
|
951
|
-
beta = tot / temp;
|
|
952
|
-
tot = temp;
|
|
953
|
-
for (i = 1; i <= n; ++i) {
|
|
954
|
-
temp = alpha * z[i][k] + beta * z[i][kp];
|
|
955
|
-
z[i][kp] = alpha * z[i][kp] - beta * z[i][k];
|
|
956
|
-
z[i][k] = temp;
|
|
957
|
-
}
|
|
962
|
+
temp = alpha * z[i][k] + beta * z[i][kp];
|
|
963
|
+
z[i][kp] = alpha * z[i][kp] - beta * z[i][k];
|
|
964
|
+
z[i][k] = temp;
|
|
958
965
|
}
|
|
959
|
-
--k;
|
|
960
966
|
}
|
|
967
|
+
--k;
|
|
968
|
+
}
|
|
961
969
|
// }
|
|
962
970
|
|
|
963
971
|
if (tot === 0.0) {
|
|
@@ -970,34 +978,34 @@ define(['jxg'], function (JXG) {
|
|
|
970
978
|
|
|
971
979
|
ratio = -1.0;
|
|
972
980
|
//{
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
981
|
+
k = nact;
|
|
982
|
+
do {
|
|
983
|
+
zdotv = 0.0;
|
|
984
|
+
zdvabs = 0.0;
|
|
977
985
|
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
986
|
+
for (i = 1; i <= n; ++i) {
|
|
987
|
+
temp = z[i][k] * dxnew[i];
|
|
988
|
+
zdotv += temp;
|
|
989
|
+
zdvabs += Math.abs(temp);
|
|
990
|
+
}
|
|
991
|
+
acca = zdvabs + 0.1 * Math.abs(zdotv);
|
|
992
|
+
accb = zdvabs + 0.2 * Math.abs(zdotv);
|
|
993
|
+
if (zdvabs < acca && acca < accb) {
|
|
994
|
+
temp = zdotv / zdota[k];
|
|
995
|
+
if (temp > 0.0 && iact[k] <= m) {
|
|
996
|
+
tempa = vmultc[k] / temp;
|
|
997
|
+
if (ratio < 0.0 || tempa < ratio) { ratio = tempa; }
|
|
982
998
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
if (temp > 0.0 && iact[k] <= m) {
|
|
988
|
-
tempa = vmultc[k] / temp;
|
|
989
|
-
if (ratio < 0.0 || tempa < ratio) { ratio = tempa; }
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
if (k >= 2) {
|
|
993
|
-
kw = iact[k];
|
|
994
|
-
for (i = 1; i <= n; ++i) { dxnew[i] -= temp * a[i][kw]; }
|
|
995
|
-
}
|
|
996
|
-
vmultd[k] = temp;
|
|
997
|
-
} else {
|
|
998
|
-
vmultd[k] = 0.0;
|
|
999
|
+
|
|
1000
|
+
if (k >= 2) {
|
|
1001
|
+
kw = iact[k];
|
|
1002
|
+
for (i = 1; i <= n; ++i) { dxnew[i] -= temp * a[i][kw]; }
|
|
999
1003
|
}
|
|
1000
|
-
|
|
1004
|
+
vmultd[k] = temp;
|
|
1005
|
+
} else {
|
|
1006
|
+
vmultd[k] = 0.0;
|
|
1007
|
+
}
|
|
1008
|
+
} while (--k > 0);
|
|
1001
1009
|
//}
|
|
1002
1010
|
if (ratio < 0.0) { break L_60; }
|
|
1003
1011
|
|
|
@@ -1016,9 +1024,9 @@ define(['jxg'], function (JXG) {
|
|
|
1016
1024
|
kp = k + 1;
|
|
1017
1025
|
kw = iact[kp];
|
|
1018
1026
|
sp = this.DOT_PRODUCT(
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1027
|
+
this.PART(this.COL(z, k), 1, n),
|
|
1028
|
+
this.PART(this.COL(a, kw), 1, n)
|
|
1029
|
+
);
|
|
1022
1030
|
temp = Math.sqrt(sp * sp + zdota[kp] * zdota[kp]);
|
|
1023
1031
|
alpha = zdota[kp] / temp;
|
|
1024
1032
|
beta = sp / temp;
|
|
@@ -1037,9 +1045,9 @@ define(['jxg'], function (JXG) {
|
|
|
1037
1045
|
vmultc[k] = vsave;
|
|
1038
1046
|
}
|
|
1039
1047
|
temp = this.DOT_PRODUCT(
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1048
|
+
this.PART(this.COL(z, nact), 1, n),
|
|
1049
|
+
this.PART(this.COL(a, kk), 1, n)
|
|
1050
|
+
);
|
|
1043
1051
|
if (temp === 0.0) { break L_60; }
|
|
1044
1052
|
zdota[nact] = temp;
|
|
1045
1053
|
vmultc[icon] = 0.0;
|
|
@@ -1062,9 +1070,9 @@ define(['jxg'], function (JXG) {
|
|
|
1062
1070
|
if (mcon > m && kk !== mcon) {
|
|
1063
1071
|
k = nact - 1;
|
|
1064
1072
|
sp = this.DOT_PRODUCT(
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1073
|
+
this.PART(this.COL(z, k), 1, n),
|
|
1074
|
+
this.PART(this.COL(a, kk), 1, n)
|
|
1075
|
+
);
|
|
1068
1076
|
temp = Math.sqrt(sp * sp + zdota[nact] * zdota[nact]);
|
|
1069
1077
|
alpha = zdota[nact] / temp;
|
|
1070
1078
|
beta = sp / temp;
|
|
@@ -1090,10 +1098,8 @@ define(['jxg'], function (JXG) {
|
|
|
1090
1098
|
for (k = 1; k <= n; ++k) { sdirn[k] = temp * z[k][nact]; }
|
|
1091
1099
|
} else {
|
|
1092
1100
|
kk = iact[nact];
|
|
1093
|
-
temp = (this.DOT_PRODUCT(
|
|
1094
|
-
|
|
1095
|
-
this.PART(this.COL(a, kk), 1, n)
|
|
1096
|
-
) - 1.0) / zdota[nact];
|
|
1101
|
+
// temp = (this.DOT_PRODUCT(this.PART(sdirn, 1, n),this.PART(this.COL(a, kk), 1, n)) - 1.0) / zdota[nact];
|
|
1102
|
+
temp = (this.DOT_PRODUCT_ROW_COL(sdirn, -1, a, kk, 1, n) - 1.0) / zdota[nact];
|
|
1097
1103
|
for (k = 1; k <= n; ++k) { sdirn[k] -= temp * z[k][nact]; }
|
|
1098
1104
|
}
|
|
1099
1105
|
}
|
|
@@ -1133,9 +1139,8 @@ define(['jxg'], function (JXG) {
|
|
|
1133
1139
|
resmax = 0.0;
|
|
1134
1140
|
for (k = 1; k <= nact; ++k) {
|
|
1135
1141
|
kk = iact[k];
|
|
1136
|
-
temp = b[kk] - this.DOT_PRODUCT(
|
|
1137
|
-
|
|
1138
|
-
);
|
|
1142
|
+
// temp = b[kk] - this.DOT_PRODUCT(this.PART(this.COL(a, kk), 1, n), this.PART(dxnew, 1, n));
|
|
1143
|
+
temp = b[kk] - this.DOT_PRODUCT_ROW_COL(dxnew, -1, a, kk, 1, n);
|
|
1139
1144
|
resmax = Math.max(resmax, temp);
|
|
1140
1145
|
}
|
|
1141
1146
|
}
|
|
@@ -1145,25 +1150,25 @@ define(['jxg'], function (JXG) {
|
|
|
1145
1150
|
// can be attributed to computer rounding errors. First calculate the new
|
|
1146
1151
|
// Lagrange multipliers.
|
|
1147
1152
|
//{
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1153
|
+
k = nact;
|
|
1154
|
+
do {
|
|
1155
|
+
zdotw = 0.0;
|
|
1156
|
+
zdwabs = 0.0;
|
|
1157
|
+
for (i = 1; i <= n; ++i) {
|
|
1158
|
+
temp = z[i][k] * dxnew[i];
|
|
1159
|
+
zdotw += temp;
|
|
1160
|
+
zdwabs += Math.abs(temp);
|
|
1161
|
+
}
|
|
1162
|
+
acca = zdwabs + 0.1 * Math.abs(zdotw);
|
|
1163
|
+
accb = zdwabs + 0.2 * Math.abs(zdotw);
|
|
1164
|
+
if (zdwabs >= acca || acca >= accb) { zdotw = 0.0; }
|
|
1165
|
+
vmultd[k] = zdotw / zdota[k];
|
|
1166
|
+
if (k >= 2) {
|
|
1167
|
+
kk = iact[k];
|
|
1168
|
+
for (i = 1; i <= n; ++i) { dxnew[i] -= vmultd[k] * a[i][kk]; }
|
|
1169
|
+
}
|
|
1170
|
+
} while (k-- >= 2);
|
|
1171
|
+
if (mcon > m) { vmultd[nact] = Math.max(0.0, vmultd[nact]); }
|
|
1167
1172
|
//}
|
|
1168
1173
|
|
|
1169
1174
|
// Complete VMULTC by finding the new constraint residuals.
|
|
@@ -1228,12 +1233,12 @@ define(['jxg'], function (JXG) {
|
|
|
1228
1233
|
return false;
|
|
1229
1234
|
},
|
|
1230
1235
|
|
|
1231
|
-
PrintIterationResult: function(nfvals, f, resmax,
|
|
1232
|
-
if (iprint > 1) { console.log("NFVALS = "+nfvals+" F = "+f+" MAXCV = "+resmax); }
|
|
1236
|
+
PrintIterationResult: function (nfvals, f, resmax, x, n, iprint) {
|
|
1237
|
+
if (iprint > 1) { console.log("NFVALS = " + nfvals + " F = " + f + " MAXCV = " + resmax); }
|
|
1233
1238
|
if (iprint > 1) { console.log("X = " + this.PART(x, 1, n)); }
|
|
1234
1239
|
},
|
|
1235
1240
|
|
|
1236
|
-
ROW: function(src, rowidx) {
|
|
1241
|
+
ROW: function (src, rowidx) {
|
|
1237
1242
|
return src[rowidx].slice();
|
|
1238
1243
|
// var col,
|
|
1239
1244
|
// cols = src[0].length,
|
|
@@ -1245,17 +1250,18 @@ define(['jxg'], function (JXG) {
|
|
|
1245
1250
|
// return dest;
|
|
1246
1251
|
},
|
|
1247
1252
|
|
|
1248
|
-
COL: function(src, colidx) {
|
|
1253
|
+
COL: function (src, colidx) {
|
|
1249
1254
|
var row,
|
|
1250
1255
|
rows = src.length,
|
|
1251
|
-
dest = this.arr(rows);
|
|
1256
|
+
dest = []; // this.arr(rows);
|
|
1257
|
+
|
|
1252
1258
|
for (row = 0; row < rows; ++row) {
|
|
1253
1259
|
dest[row] = src[row][colidx];
|
|
1254
1260
|
}
|
|
1255
1261
|
return dest;
|
|
1256
1262
|
},
|
|
1257
1263
|
|
|
1258
|
-
PART: function(src, from, to) {
|
|
1264
|
+
PART: function (src, from, to) {
|
|
1259
1265
|
return src.slice(from, to + 1);
|
|
1260
1266
|
// var srcidx,
|
|
1261
1267
|
// dest = this.arr(to - from + 1),
|
|
@@ -1266,7 +1272,7 @@ define(['jxg'], function (JXG) {
|
|
|
1266
1272
|
// return dest;
|
|
1267
1273
|
},
|
|
1268
1274
|
|
|
1269
|
-
FORMAT: function(x) {
|
|
1275
|
+
FORMAT: function (x) {
|
|
1270
1276
|
return x.join(',');
|
|
1271
1277
|
// var i, fmt = "";
|
|
1272
1278
|
// for (i = 0; i < x.length; ++i) {
|
|
@@ -1275,12 +1281,38 @@ define(['jxg'], function (JXG) {
|
|
|
1275
1281
|
// return fmt;
|
|
1276
1282
|
},
|
|
1277
1283
|
|
|
1278
|
-
DOT_PRODUCT: function(lhs,
|
|
1284
|
+
DOT_PRODUCT: function (lhs, rhs) {
|
|
1279
1285
|
var i, sum = 0.0,
|
|
1280
1286
|
len = lhs.length;
|
|
1281
1287
|
for (i = 0; i < len; ++i) {
|
|
1282
1288
|
sum += lhs[i] * rhs[i];
|
|
1283
1289
|
}
|
|
1290
|
+
return sum;
|
|
1291
|
+
},
|
|
1292
|
+
|
|
1293
|
+
DOT_PRODUCT_ROW_COL: function (lhs, row, rhs, col, start, end) {
|
|
1294
|
+
var i, sum = 0.0;
|
|
1295
|
+
|
|
1296
|
+
if (row === -1) {
|
|
1297
|
+
// lhs is vector
|
|
1298
|
+
for (i = start; i <= end; ++i) {
|
|
1299
|
+
sum += lhs[i] * rhs[i][col];
|
|
1300
|
+
}
|
|
1301
|
+
} else {
|
|
1302
|
+
// lhs is row of matrix
|
|
1303
|
+
if (col === -1) {
|
|
1304
|
+
// rhs is vector
|
|
1305
|
+
for (i = start; i <= end; ++i) {
|
|
1306
|
+
sum += lhs[row][i] * rhs[i];
|
|
1307
|
+
}
|
|
1308
|
+
} else {
|
|
1309
|
+
// rhs is column of matrix
|
|
1310
|
+
for (i = start; i <= end; ++i) {
|
|
1311
|
+
sum += lhs[row][i] * rhs[i][col];
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1284
1316
|
return sum;
|
|
1285
1317
|
}
|
|
1286
1318
|
|