void AddGoalsToKeepFlatEdgesShort(ISolverShell solver)
 {
     foreach (var layerInfo in layerInfos)
     {
         AddGoalToKeepFlatEdgesShortOnBlockLevel(layerInfo, solver);
     }
 }
 void SortLayers(ISolverShell solver)
 {
     for (int i = 0; i < LayerArrays.Layers.Length; i++)
     {
         SortLayerBasedOnSolution(LayerArrays.Layers[i], solver);
     }
 }
 void AddGoalsToKeepProperEdgesShort(ISolverShell solver)
 {
     foreach (var edge in ProperLayeredGraph.Edges)
     {
         solver.AddGoalTwoVariablesAreClose(edge.Source, edge.Target, PositionOverBaricenterWeight);
     }
 }
 void InitSolverVars(ISolverShell solver)
 {
     for (int i = 0; i < LayerArrays.Y.Length; i++)
     {
         solver.AddVariableWithIdealPosition(i, 0);
     }
 }
 void PutLeftRightConstraintsIntoSolver(ISolverShell solver)
 {
     foreach (var pair in horizontalConstraints.LeftRighInts)
     {
         solver.AddLeftRightSeparationConstraint(pair.Item1, pair.Item2, SimpleGapBetweenTwoNodes(pair.Item1, pair.Item2));
     }
 }
 void PutVerticalConstraintsIntoSolver(ISolverShell solver)
 {
     foreach (var pair in horizontalConstraints.VerticalInts)
     {
         solver.AddGoalTwoVariablesAreClose(pair.Item1, pair.Item2, ConstrainedVarWeight);
     }
 }
 void AddSeparationConstraintsForFlatEdges(LayerInfo layerInfo, ISolverShell solver)
 {
     if (layerInfo != null)
     {
         foreach (var p in layerInfo.flatEdges)
         {
             int left, right;
             if (LayerArrays.X[p.Item1] < LayerArrays.X[p.Item2])
             {
                 left  = p.Item1;
                 right = p.Item2;
             }
             else
             {
                 left  = p.Item2;
                 right = p.Item1;
             }
             if (left == right)
             {
                 continue;
             }
             double gap = GetGap(left, right);
             foreach (IntEdge edge in database.GetMultiedge(p.Item1, p.Item2))
             {
                 solver.AddLeftRightSeparationConstraint(left, right,
                                                         gap + NodeSeparation() +
                                                         (edge.Edge.Label != null ? edge.Edge.Label.Width : 0));
             }
         }
     }
 }
Пример #8
0
        void CalculateLabelsX()
        {
            int          i;
            ISolverShell solver = ConstrainedOrdering.CreateSolver();

            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);
                }
            }
        }
 void ExtractPositionsFromSolver(int[] layer, ISolverShell solver, double[] positions)
 {
     solver.Solve();
     for (int i = 0; i < layer.Length; i++)
     {
         database.Anchors[layer[i]].X = positions[i] = solver.GetVariableResolvedPosition(layer[i]);
     }
 }
 void PutLayerNodeSeparationsIntoSolver(ISolverShell 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));
         }
     }
 }
 static bool Solve(ISolverShell solver, ProjSolv.Parameters parameters) {
     bool executionLimitExceeded = false, retval = true;
     if (!solver.Solve(parameters, out executionLimitExceeded)) {
         System.Console.WriteLine("  Error - Solve failed");
         ++s_cExecutionFailed;
         retval = false;
     }
     if (executionLimitExceeded) {
         System.Console.WriteLine("  Warning - one or more execution limits were exceeded");
         ++s_cExecutionLimitExceeded;
     }
     return retval;
 }
        void SetXPositions()
        {
            ISolverShell 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);
            }
        }
        ISolverShell InitSolverWithoutOrder()
        {
            ISolverShell solver = CreateSolver();

            InitSolverVars(solver);

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

            AddGoalsToKeepFlatEdgesShort(solver);
            return(solver);
        }
 static void AddGoalToKeepFlatEdgesShortOnBlockLevel(LayerInfo layerInfo, ISolverShell 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);
             }
         }
     }
 }
Пример #15
0
        static bool Solve(ISolverShell solver, ProjSolv.Parameters parameters)
        {
            bool executionLimitExceeded = false, retval = true;

            if (!solver.Solve(parameters, out executionLimitExceeded))
            {
                System.Console.WriteLine("  Error - Solve failed");
                ++s_cExecutionFailed;
                retval = false;
            }
            if (executionLimitExceeded)
            {
                System.Console.WriteLine("  Warning - one or more execution limits were exceeded");
                ++s_cExecutionLimitExceeded;
            }
            return(retval);
        }
        void SortLayerBasedOnSolution(int[] layer, ISolverShell 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++;
            }
        }
 void SortLayers(ISolverShell solver) {
     for (int i = 0; i < LayerArrays.Layers.Length; i++)
         SortLayerBasedOnSolution(LayerArrays.Layers[i], solver);
 }
        //at the moment we only are looking for the order of nodes in the layer
        void FillSolverWithoutKnowingLayerOrder(IEnumerable <int> layer, LayerInfo layerInfo, ISolverShell solver,
                                                SweepMode sweepMode)
        {
            foreach (int v in layer)
            {
                if (layerInfo.neigBlocks.ContainsKey(v))
                {
                    //v is a block root
                    int blockNode = GetFixedBlockNode(v, layerInfo, sweepMode);
                    if (blockNode != -1)
                    {
                        solver.AddVariableWithIdealPosition(v, FixedNodePosition(blockNode, sweepMode),
                                                            ConstrainedVarWeight);
                    }
                    else
                    {
                        IEnumerable <int> t = from u in layerInfo.neigBlocks[v].Concat(new[] { v })
                                              where IsConnectedToPrevLayer(u, sweepMode)
                                              select u;
                        if (t.Any())
                        {
                            blockNode = t.First();
                            solver.AddVariableWithIdealPosition(v, GetBaricenterOnPrevLayer(blockNode, sweepMode));
                        }
                    }
                }
                else if (!BelongsToNeighbBlock(v, layerInfo))
                {
                    if (NodeIsConstrained(v, sweepMode, layerInfo))
                    {
                        solver.AddVariableWithIdealPosition(v, FixedNodePosition(v, sweepMode), ConstrainedVarWeight);
                    }
                    else if (IsConnectedToPrevLayer(v, sweepMode))
                    {
                        solver.AddVariableWithIdealPosition(v, GetBaricenterOnPrevLayer(v, sweepMode));
                    }
                }
            }

            AddGoalToKeepFlatEdgesShortOnBlockLevel(layerInfo, solver);

            foreach (var p in layerInfo.leftRight)
            {
                solver.AddLeftRightSeparationConstraint(p.Item1, p.Item2, GetGapBetweenBlockRoots(p.Item1, p.Item2));
            }
        }
 void InitSolverVars(ISolverShell solver) {
     for (int i = 0; i < LayerArrays.Y.Length; i++)
         solver.AddVariableWithIdealPosition(i, 0);
 }
        void AddGoalsToKeepProperEdgesShort(ISolverShell solver) {
            foreach (var edge in ProperLayeredGraph.Edges)
                solver.AddGoalTwoVariablesAreClose(edge.Source, edge.Target, PositionOverBaricenterWeight);

        }
 void PutLeftRightConstraintsIntoSolver(ISolverShell solver) {
     foreach (var pair in horizontalConstraints.LeftRighInts) {
         solver.AddLeftRightSeparationConstraint(pair.Item1, pair.Item2, SimpleGapBetweenTwoNodes(pair.Item1, pair.Item2));
     }
 }
 void PutVerticalConstraintsIntoSolver(ISolverShell solver) {
     foreach (var pair in horizontalConstraints.VerticalInts) {
         solver.AddGoalTwoVariablesAreClose(pair.Item1, pair.Item2, ConstrainedVarWeight);
     }
 }
        void SortLayerBasedOnSolution(int[] layer, ISolverShell 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++;
        }
 void PutLayerNodeSeparationsIntoSolver(ISolverShell 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));
         }
     }
 }
 void ExtractPositionsFromSolver(int[] layer, ISolverShell solver, double[] positions) {
     solver.Solve();
     for (int i = 0; i < layer.Length; i++)
         database.Anchors[layer[i]].X = positions[i] = solver.GetVariableResolvedPosition(layer[i]);
 }
 void AddSeparationConstraintsForFlatEdges(LayerInfo layerInfo, ISolverShell solver) {
     if (layerInfo != null) {
         foreach (var p in layerInfo.flatEdges) {
             int left, right;
             if (LayerArrays.X[p.Item1] < LayerArrays.X[p.Item2]) {
                 left = p.Item1;
                 right = p.Item2;
             } else {
                 left = p.Item2;
                 right = p.Item1;
             }
             if (left == right) continue;
             double gap = GetGap(left, right);
             foreach (IntEdge edge in database.GetMultiedge(p.Item1, p.Item2))
                 solver.AddLeftRightSeparationConstraint(left, right,
                                                         gap + NodeSeparation() +
                                                         (edge.Edge.Label != null ? edge.Edge.Label.Width : 0));
         }
     }
 }
        //at the moment we only are looking for the order of nodes in the layer
        void FillSolverWithoutKnowingLayerOrder(IEnumerable<int> layer, LayerInfo layerInfo, ISolverShell solver,
                                                       SweepMode sweepMode) {
            foreach (int v in layer)
                if (layerInfo.neigBlocks.ContainsKey(v)) {
                    //v is a block root
                    int blockNode = GetFixedBlockNode(v, layerInfo, sweepMode);
                    if (blockNode != -1)
                        solver.AddVariableWithIdealPosition(v, FixedNodePosition(blockNode, sweepMode),
                                                            ConstrainedVarWeight);
                    else {
                        IEnumerable<int> t = from u in layerInfo.neigBlocks[v].Concat(new[] { v })
                                             where IsConnectedToPrevLayer(u, sweepMode)
                                             select u;
                        if (t.Any()) {
                            blockNode = t.First();
                            solver.AddVariableWithIdealPosition(v, GetBaricenterOnPrevLayer(blockNode, sweepMode));
                        }
                    }
                } else if (!BelongsToNeighbBlock(v, layerInfo)) {
                    if (NodeIsConstrained(v, sweepMode, layerInfo))
                        solver.AddVariableWithIdealPosition(v, FixedNodePosition(v, sweepMode), ConstrainedVarWeight);
                    else if (IsConnectedToPrevLayer(v, sweepMode))
                        solver.AddVariableWithIdealPosition(v, GetBaricenterOnPrevLayer(v, sweepMode));
                }

            AddGoalToKeepFlatEdgesShortOnBlockLevel(layerInfo, solver);

            foreach (var p in layerInfo.leftRight)
                solver.AddLeftRightSeparationConstraint(p.Item1, p.Item2, GetGapBetweenBlockRoots(p.Item1, p.Item2));
        }
 static void AddGoalToKeepFlatEdgesShortOnBlockLevel(LayerInfo layerInfo, ISolverShell 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);
         }
 }
 static bool Solve(ISolverShell solver) {
     return Solve(solver, null);
 }
Пример #30
0
 static bool Solve(ISolverShell solver)
 {
     return(Solve(solver, null));
 }
 void AddGoalsToKeepFlatEdgesShort(ISolverShell solver) {
     foreach (var layerInfo in layerInfos)
         AddGoalToKeepFlatEdgesShortOnBlockLevel(layerInfo, solver);
 }