minimization magic

This commit is contained in:
Val Erastov 2015-02-19 01:12:17 -08:00
parent 955bcbb6fc
commit 9aec197419
5 changed files with 19 additions and 9 deletions

2
.gitignore vendored
View file

@ -3,6 +3,8 @@
/out/
/.idea/
*.iml
*.ipr
*.iws
# Package Files #
*.jar

View file

@ -792,8 +792,8 @@ TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) {
&& this.obj.parent._class === 'TCAD.TWO.Arc') {
if (this.obj.id != this.obj.parent.c.id) {
locked.push(this.obj.parent.c._x);
locked.push(this.obj.parent.c._y);
// locked.push(this.obj.parent.c._x);
// locked.push(this.obj.parent.c._y);
}
}
} else {

View file

@ -200,16 +200,18 @@ TCAD.parametric.lock1 = function(constrs, locked) {
TCAD.parametric.lock2Equals2 = function(constrs, locked) {
var _locked = [];
for (var i = 0; i < locked.length; ++i) {
_locked.push(new TCAD.constraints.Weighted(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()), 0.1));
_locked.push(new TCAD.constraints.Weighted(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()), 1));
}
return _locked;
};
TCAD.parametric._alg = 5;
TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
this.lock1(constrs, aux);
var lockingConstrs = this.lock2Equals2(constrs, locked);
// Array.prototype.push.apply( constrs, lockingConstrs );
Array.prototype.push.apply( constrs, lockingConstrs );
var sys = new TCAD.parametric.System(constrs);
@ -231,7 +233,7 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
sys.setParams(point);
return sys.makeJacobian();
};
alg = 5;
alg = TCAD.parametric._alg;
function solve(fineLevel) {
if (constrs.length == 0) return;
@ -252,7 +254,10 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
TCAD.math.solve_UNCMIN(sys);
break;
case 5:
optim.dog_leg(sys);
if (optim.dog_leg(sys) !== 0) {
TCAD.parametric._alg = alg = -5;
solve(fineLevel);
}
break;
}
return sys;
@ -260,9 +265,10 @@ TCAD.parametric.prepare = function(constrs, locked, aux, alg) {
var opt = new LMOptimizer(sys.getParams(), arr(sys.constraints.length), model, jacobian);
var eps;
fineLevel = 1;
switch (fineLevel) {
case 1:
eps = 0.01;
eps = 0.001;
opt.init0(eps, eps, eps);
break;
case 2:

View file

@ -358,10 +358,10 @@ optim.dog_leg = function(subsys) {
var alpha=0.;
var nu=2.;
var iter=0, stop=0, reduce=0;
while (!stop) {
while (stop === 0) {
// check if finished
if (fx_inf <= tolf) // Success
if (fx_inf <= tolf || err <= tolf) // Success
stop = 1;
else if (g_inf <= tolg)
stop = 2;

View file

@ -746,6 +746,8 @@ TCAD.TWO.Constraints.RR = function(arc1, arc2) {
};
TCAD.TWO.Constraints.RR.prototype.NAME = 'RR';
TCAD.TWO.Constraints.RR.prototype.reducible = true;
TCAD.TWO.Constraints.RR.prototype.getSolveData = function() {
return [['equal', [this.arc1.r, this.arc2.r], []]];