Exemple #1
0
 void InitSolverVars(SolverShell solver)
 {
     for (int i = 0; i < LayerArrays.Y.Length; i++)
     {
         solver.AddVariableWithIdealPosition(i, 0);
     }
 }
Exemple #2
0
        void CalculateLabelsX()
        {
            int i;
            var solver = new SolverShell();

            for (i = 0; i < pairArray.Length; i++)
            {
                solver.AddVariableWithIdealPosition(i, labelCenters[i], GetLabelWeight(pairArray[i]));
            }

            //add non overlapping constraints between to neighbor labels
            double prevLabelWidth = GetMaxLabelWidth(pairArray[0]);

            for (i = 0; i < pairArray.Length - 1; i++)
            {
                solver.AddLeftRightSeparationConstraint(i, i + 1,
                                                        (prevLabelWidth +
                                                         (prevLabelWidth = GetMaxLabelWidth(pairArray[i + 1]))) / 2 +
                                                        settings.NodeSeparation);
            }

            for (i = 0; i < labelCenters.Length; i++)
            {
                double x = labelCenters[i] = solver.GetVariableResolvedPosition(i);
                foreach (Label label in PairLabels(pairArray[i]))
                {
                    label.Center = new Point(x, label.Center.Y);
                }
            }
        }
Exemple #3
0
        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));
        }
Exemple #4
0
        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));
            }
        }
Exemple #5
0
        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));
        }
        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));
        }
        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));
        }