mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-26 10:23:05 +01:00
multi solve
This commit is contained in:
parent
57f9fcdf9b
commit
6d1afc62cb
2 changed files with 37 additions and 25 deletions
|
|
@ -20,6 +20,7 @@ import org.apache.commons.math3.analysis.MultivariateVectorFunction;
|
|||
import org.apache.commons.math3.optim.InitialGuess;
|
||||
import org.apache.commons.math3.optim.MaxEval;
|
||||
import org.apache.commons.math3.optim.MaxIter;
|
||||
import org.apache.commons.math3.optim.PointVectorValuePair;
|
||||
import org.apache.commons.math3.optim.nonlinear.vector.ModelFunction;
|
||||
import org.apache.commons.math3.optim.nonlinear.vector.ModelFunctionJacobian;
|
||||
import org.apache.commons.math3.optim.nonlinear.vector.Target;
|
||||
|
|
@ -45,10 +46,11 @@ public class App2DCtrl implements Initializable {
|
|||
public Pane viewer;
|
||||
public Button solve;
|
||||
public Button square;
|
||||
private Group content;
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
Group content = new Group();
|
||||
content = new Group();
|
||||
setInitObject(content);
|
||||
viewer.getChildren().setAll(content);
|
||||
|
||||
|
|
@ -208,9 +210,12 @@ public class App2DCtrl implements Initializable {
|
|||
fxLine.setStartY(line[1].get());
|
||||
fxLine.setEndX(line[2].get());
|
||||
fxLine.setEndY(line[3].get());
|
||||
|
||||
lines.add(fxLine);
|
||||
}
|
||||
|
||||
content.getChildren().addAll(lines);
|
||||
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
executor.execute(() -> {
|
||||
globalSolve(subSystem, () -> Platform.runLater(() -> {
|
||||
|
|
@ -239,7 +244,7 @@ public class App2DCtrl implements Initializable {
|
|||
Solver.SubSystem worse = new Solver.SubSystem(asList(subSystem.constraints.get(worseId)));
|
||||
solveLM_COMMONS(worse);
|
||||
// Solver.solve_LM(worse);
|
||||
System.out.println("WORSE FIXED ERROR:" + worse.error());
|
||||
System.out.println("WORSE FIXED ERROR:" + Math.sqrt(worse.error()));
|
||||
}
|
||||
linearSolvedCallback.run();
|
||||
}
|
||||
|
|
@ -266,25 +271,27 @@ public class App2DCtrl implements Initializable {
|
|||
|
||||
double[] wieght = new double[subSystem.cSize()];
|
||||
Arrays.fill(wieght, 1);
|
||||
optimizer.optimize(
|
||||
new MaxEval(10000),
|
||||
new MaxIter(10000),
|
||||
new InitialGuess(subSystem.getParams().toArray()),
|
||||
new Target(new double[subSystem.cSize()]),
|
||||
new Weight(wieght),
|
||||
new ModelFunctionJacobian(point -> {
|
||||
subSystem.setParams(point);
|
||||
return subSystem.makeJacobi().getData();
|
||||
}),
|
||||
new ModelFunction(new MultivariateVectorFunction() {
|
||||
@Override
|
||||
public double[] value(double[] point) throws IllegalArgumentException {
|
||||
subSystem.setParams(point);
|
||||
return subSystem.getValues().toArray();
|
||||
}
|
||||
})
|
||||
PointVectorValuePair result = optimizer.optimize(
|
||||
new MaxEval(10000),
|
||||
new MaxIter(10000),
|
||||
new InitialGuess(subSystem.getParams().toArray()),
|
||||
new Target(new double[subSystem.cSize()]),
|
||||
new Weight(wieght),
|
||||
new ModelFunctionJacobian(point -> {
|
||||
subSystem.setParams(point);
|
||||
return subSystem.makeJacobi().getData();
|
||||
}),
|
||||
new ModelFunction(new MultivariateVectorFunction() {
|
||||
@Override
|
||||
public double[] value(double[] point) throws IllegalArgumentException {
|
||||
subSystem.setParams(point);
|
||||
return subSystem.getValues().toArray();
|
||||
}
|
||||
})
|
||||
|
||||
);
|
||||
|
||||
subSystem.setParams(result.getPoint());
|
||||
}
|
||||
|
||||
private void solve(ActionEvent e) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package cad.gcs;
|
||||
|
||||
import cad.gcs.constr.Equals;
|
||||
import cad.gcs.constr.P2LDistance;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -31,18 +32,22 @@ public class Figures {
|
|||
constrs.add(new Equals(l2[Y1], l1[Y2]));
|
||||
constrs.add(new Equals(l3[X1], l2[X2]));
|
||||
constrs.add(new Equals(l3[Y1], l2[Y2]));
|
||||
constrs.add(new Equals(l4[X1], l4[X2]));
|
||||
constrs.add(new Equals(l4[Y1], l4[Y2]));
|
||||
constrs.add(new Equals(l4[X1], l3[X2]));
|
||||
constrs.add(new Equals(l4[Y1], l3[Y2]));
|
||||
|
||||
constrs.add(new Equals(l1[Y1], l1[Y2]));
|
||||
constrs.add(new Equals(l3[Y1], l1[Y2]));
|
||||
constrs.add(new Equals(l2[X1], l1[X2]));
|
||||
constrs.add(new Equals(l4[X1], l1[X2]));
|
||||
constrs.add(new Equals(l3[Y1], l3[Y2]));
|
||||
constrs.add(new Equals(l2[X1], l2[X2]));
|
||||
constrs.add(new Equals(l4[X1], l4[X2]));
|
||||
|
||||
constrs.add(new P2LDistance(100, l1[X1], l1[Y1], l2[X1], l2[Y1], l2[X2], l2[Y2]));
|
||||
constrs.add(new P2LDistance(100, l1[X1], l1[Y1], l3[X1], l3[Y1], l3[X2], l3[Y2]));
|
||||
|
||||
return new Figure(new Param[][]{l1, l2, l3, l4}, constrs);
|
||||
}
|
||||
|
||||
private static Param[] line() {
|
||||
return new Param[]{new Param(10), new Param(10), new Param(100), new Param(100)};
|
||||
return new Param[]{new Param(200), new Param(200), new Param(500), new Param(500)};
|
||||
}
|
||||
|
||||
public static class Figure {
|
||||
|
|
|
|||
Loading…
Reference in a new issue