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;
 }
 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);
 }
 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]);
 }
        //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 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 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));
         }
     }
 }
 void PutLeftRightConstraintsIntoSolver(ISolverShell solver) {
     foreach (var pair in horizontalConstraints.LeftRighInts) {
         solver.AddLeftRightSeparationConstraint(pair.Item1, pair.Item2, SimpleGapBetweenTwoNodes(pair.Item1, pair.Item2));
     }
 }
 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 PutVerticalConstraintsIntoSolver(ISolverShell solver) {
     foreach (var pair in horizontalConstraints.VerticalInts) {
         solver.AddGoalTwoVariablesAreClose(pair.Item1, pair.Item2, ConstrainedVarWeight);
     }
 }
        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 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);
 }