示例#1
0
 void AddGoalsToKeepProperEdgesShort(SolverShell solver)
 {
     foreach (var edge in ProperLayeredGraph.Edges)
     {
         solver.AddGoalTwoVariablesAreClose(edge.Source, edge.Target, PositionOverBaricenterWeight);
     }
 }
示例#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 PutLeftRightConstraintsIntoSolver(SolverShell solver)
 {
     foreach (var pair in horizontalConstraints.LeftRighInts)
     {
         solver.AddLeftRightSeparationConstraint(pair.Item1, pair.Item2, SimpleGapBetweenTwoNodes(pair.Item1, pair.Item2));
     }
 }
示例#4
0
 void AddGoalsToKeepFlatEdgesShort(SolverShell solver)
 {
     foreach (var layerInfo in layerInfos)
     {
         AddGoalToKeepFlatEdgesShortOnBlockLevel(layerInfo, solver);
     }
 }
示例#5
0
 void PutVerticalConstraintsIntoSolver(SolverShell solver)
 {
     foreach (var pair in horizontalConstraints.VerticalInts)
     {
         solver.AddGoalTwoVariablesAreClose(pair.Item1, pair.Item2, ConstrainedVarWeight);
     }
 }
示例#6
0
 void InitSolverVars(SolverShell solver)
 {
     for (int i = 0; i < LayerArrays.Y.Length; i++)
     {
         solver.AddVariableWithIdealPosition(i, 0);
     }
 }
示例#7
0
 void SortLayers(SolverShell solver)
 {
     for (int i = 0; i < LayerArrays.Layers.Length; i++)
     {
         SortLayerBasedOnSolution(LayerArrays.Layers[i], solver);
     }
 }
示例#8
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));
         }
     }
 }
示例#9
0
        SolverShell InitSolverWithoutOrder()
        {
            var solver = new SolverShell();

            InitSolverVars(solver);

            PutLeftRightConstraintsIntoSolver(solver);
            PutVerticalConstraintsIntoSolver(solver);
            AddGoalsToKeepProperEdgesShort(solver);

            AddGoalsToKeepFlatEdgesShort(solver);
            return(solver);
        }
示例#10
0
        void SetXPositions()
        {
            SolverShell solver = InitSolverWithoutOrder();

            ImproveWithAdjacentSwaps();
            PutLayerNodeSeparationsIntoSolver(solver);
            solver.Solve();
            SortLayers(solver);
            for (int i = 0; i < LayerArrays.Y.Length; i++)
            {
                database.Anchors[i].X = solver.GetVariableResolvedPosition(i);
            }
        }
示例#11
0
 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);
             }
         }
     }
 }
示例#12
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));
        }
示例#13
0
        void SortLayerBasedOnSolution(int[] layer, SolverShell solver)
        {
            int length    = layer.Length;
            var positions = new double[length];
            int k         = 0;

            foreach (int v in layer)
            {
                positions[k++] = solver.GetVariableResolvedPosition(v);
            }

            Array.Sort(positions, layer);
            int i = 0;

            foreach (int v in layer)
            {
                LayerArrays.X[v] = i++;
            }
        }
示例#14
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));
            }
        }
示例#15
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));
        }
        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));
        }