void PutVerticalConstraintsIntoSolver(SolverShell solver) { foreach (var pair in horizontalConstraints.VerticalInts) { solver.AddGoalTwoVariablesAreClose(pair.Item1, pair.Item2, ConstrainedVarWeight); } }
void AddGoalsToKeepProperEdgesShort(SolverShell solver) { foreach (var edge in ProperLayeredGraph.Edges) { solver.AddGoalTwoVariablesAreClose(edge.Source, edge.Target, PositionOverBaricenterWeight); } }
static void AddGoalToKeepFlatEdgesShortOnBlockLevel(LayerInfo layerInfo, SolverShell solver) { if (layerInfo != null) { foreach (var couple in layerInfo.flatEdges) { int sourceBlockRoot = NodeToBlockRootSoftOnLayerInfo(layerInfo, couple.Item1); int targetBlockRoot = NodeToBlockRootSoftOnLayerInfo(layerInfo, couple.Item2); if (sourceBlockRoot != targetBlockRoot) { solver.AddGoalTwoVariablesAreClose(sourceBlockRoot, targetBlockRoot); } } } }
private static void Test_zero_g() { // Tests the 'g' vector becoming zero'd. ISolverShell solver = new SolverShell(); solver.AddVariableWithIdealPosition(0, 236.5, 2.0); solver.AddVariableWithIdealPosition(1, 255.58133348304591, 2.0); solver.AddFixedVariable(2, 102.68749237060547); solver.AddGoalTwoVariablesAreClose(0, 1, 1.0); solver.AddLeftRightSeparationConstraint(2, 0, 0); Solve(solver); System.Console.WriteLine(solver.GetVariableResolvedPosition(0)); System.Console.WriteLine(solver.GetVariableResolvedPosition(1)); }
public static void Test_random() { Random random = new Random(123); // Notes: // Iteration 0 has a high negative alpha. // Iteration 52 terminates due to QpscConvergenceQuotient, not QpscConvergenceEpsilon, // with the default Parameters. for (int ntest = 0; ntest < 100; ntest++) { System.Console.WriteLine("Executing test " + ntest + "..."); ISolverShell solver = new SolverShell(); solver.AddVariableWithIdealPosition(1, GetRandomDouble(random), 2.0); solver.AddVariableWithIdealPosition(0, GetRandomDouble(random), 2.0); solver.AddGoalTwoVariablesAreClose(0, 1, 1.0); double lS = GetRandomDouble(random); double rS = lS + GetRandomDouble(random); double lT = GetRandomDouble(random); double rT = lT + GetRandomDouble(random); solver.AddFixedVariable(2, lS); solver.AddFixedVariable(3, rS); solver.AddFixedVariable(4, lT); solver.AddFixedVariable(5, rT); solver.AddLeftRightSeparationConstraint(2, 0, 0.01); solver.AddLeftRightSeparationConstraint(0, 3, 0.01); solver.AddLeftRightSeparationConstraint(4, 1, 0.01); solver.AddLeftRightSeparationConstraint(1, 5, 0.01); Solve(solver); System.Console.WriteLine(solver.GetVariableResolvedPosition(0)); System.Console.WriteLine(solver.GetVariableResolvedPosition(1)); } }
private static void Test_dummy_ideal_position() { //just test for equation (x-500)^2 -> min ISolverShell solver = new SolverShell(); solver.AddVariableWithIdealPosition(0, 10, 0.000001); solver.AddFixedVariable(1, 500); solver.AddGoalTwoVariablesAreClose(0, 1, 100000.0); // The default parameters have too large a QpscConvergenceQuotient and too // small an OuterProjectIterationsLimit (we don't add constraints here so the // inner iterations do nothing and all movement is done by the QPSC step adjustments // in the outer iterations). ProjSolv.Parameters parameters = new ProjSolv.Parameters(); parameters.QpscConvergenceQuotient = 1e-14; parameters.OuterProjectIterationsLimit = 0; // no limit Solve(solver, parameters); System.Console.WriteLine(solver.GetVariableResolvedPosition(0)); System.Console.WriteLine(solver.GetVariableResolvedPosition(1)); }