예제 #1
0
 void PutLeftRightConstraintsIntoSolver(SolverShell solver)
 {
     foreach (var pair in horizontalConstraints.LeftRighInts)
     {
         solver.AddLeftRightSeparationConstraint(pair.Item1, pair.Item2, SimpleGapBetweenTwoNodes(pair.Item1, pair.Item2));
     }
 }
예제 #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);
                }
            }
        }
예제 #3
0
 void PutLayerNodeSeparationsIntoSolver(SolverShell solver)
 {
     foreach (var layer in LayerArrays.Layers)
     {
         for (int i = 0; i < layer.Length - 1; i++)
         {
             int l = layer[i];
             int r = layer[i + 1];
             solver.AddLeftRightSeparationConstraint(l, r, SimpleGapBetweenTwoNodes(l, r));
         }
     }
 }
예제 #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));
            }
        }
예제 #5
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));
        }
        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_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));
        }