mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-06 08:25:19 +01:00
minimization magic
This commit is contained in:
parent
955bcbb6fc
commit
9aec197419
5 changed files with 19 additions and 9 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -3,6 +3,8 @@
|
|||
/out/
|
||||
/.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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], []]];
|
||||
|
|
|
|||
Loading…
Reference in a new issue