ConstrainedOrderMeasure CreateMeasure()
 {
     return(new ConstrainedOrderMeasure(Ordering.GetCrossingsTotal(ProperLayeredGraph, LayerArrays)));
 }
        internal static void OrderLayers(ProperLayeredGraph graph,
                                         LayerArrays layerArrays,
                                         int startOfVirtualNodes,
                                         bool balanceVirtualAndOriginalNodes, 
                                         SugiyamaLayoutSettings settings, CancelToken cancelToken) {
            bool hasCrossWeight = false;
            foreach (LayerEdge le in graph.Edges)
                if (le.CrossingWeight != 1) {
                    hasCrossWeight = true;
                    break;
                }

            var o = new Ordering(graph, true, layerArrays, startOfVirtualNodes, balanceVirtualAndOriginalNodes, hasCrossWeight, settings);
            o.Run(cancelToken);
        }
예제 #3
0
        protected override void RunInternal()
        {
#if DEBUGORDERING
            if (graph.NumberOfVertices != layering.Length)
            {
                throw new System.Exception("the layering does not correspond to the graph");
            }
            foreach (IntEdge e in graph.Edges)
            {
                if (layering[e.Source] - layering[e.Target] != 1)
                {
                    throw new System.Exception("the edge in the graph does not span exactly one layer:" + e);
                }
            }
#endif

#if PPC // Parallel -- susanlwo
            LayerArrays secondLayers      = null;
            Ordering    revOrdering       = null;
            System.Threading.Tasks.Task t = null;

            if (/*orderingMeasure.x>0 &&*/ tryReverse)
            {
                secondLayers = layerArrays.ReversedClone();

                revOrdering = new Ordering(properLayeredGraph.ReversedClone(), false, secondLayers, startOfVirtNodes, balanceVirtAndOrigNodes, this.hasCrossWeights, settings);

                // note: below we need to pass the CancelToken from this thread into the new thread, to make sure a previous thread from the ThreadPool's
                // thread static token (that may be in a cancelled state) is picked up.
                t = System.Threading.Tasks.Task.Factory.StartNew(() => revOrdering.Run(this.CancelToken));
            }

            Calculate();

            if (/*orderingMeasure.x>0 &&*/ tryReverse)
            {
                t.Wait();

                if (revOrdering.measure < measure)
                {
                    for (int j = 0; j < nOfLayers; j++)
                    {
                        secondLayers.Layers[j].CopyTo(layerArrays.Layers[nOfLayers - 1 - j], 0);
                    }

                    layerArrays.UpdateXFromLayers();
                }
            }
#else
            Calculate();

            if (/*orderingMeasure.x>0 &&*/ tryReverse)
            {
                LayerArrays secondLayers = layerArrays.ReversedClone();

                var revOrdering = new Ordering(properLayeredGraph.ReversedClone(), false, secondLayers, startOfVirtNodes, balanceVirtAndOrigNodes,
                                               hasCrossWeights, settings);

                revOrdering.Run();

                if (revOrdering.measure < measure)
                {
                    for (int j = 0; j < nOfLayers; j++)
                    {
                        secondLayers.Layers[j].CopyTo(layerArrays.Layers[nOfLayers - 1 - j], 0);
                    }

                    layerArrays.UpdateXFromLayers();
                }
            }
#endif
        }
        protected override void RunInternal()
        {
#if DEBUGORDERING
      if (graph.NumberOfVertices != layering.Length)
        throw new System.Exception("the layering does not correspond to the graph");
      foreach (IntEdge e in graph.Edges)
        if (layering[e.Source] - layering[e.Target] != 1)
          throw new System.Exception("the edge in the graph does not span exactly one layer:" + e);
#endif

#if PPC // Parallel -- susanlwo
            LayerArrays secondLayers = null;
            Ordering revOrdering = null;
            System.Threading.Tasks.Task t = null;

            if (/*orderingMeasure.x>0 &&*/ tryReverse) {
                secondLayers = layerArrays.ReversedClone();

                revOrdering = new Ordering(properLayeredGraph.ReversedClone(), false, secondLayers, startOfVirtNodes, balanceVirtAndOrigNodes, this.hasCrossWeights, settings);

                // note: below we need to pass the CancelToken from this thread into the new thread, to make sure a previous thread from the ThreadPool's
                // thread static token (that may be in a cancelled state) is picked up.
                t = System.Threading.Tasks.Task.Factory.StartNew(() => revOrdering.Run(this.CancelToken));
            }

            Calculate();

            if (/*orderingMeasure.x>0 &&*/ tryReverse) {

                t.Wait();

                if (revOrdering.measure < measure) {
                    for (int j = 0; j < nOfLayers; j++)
                        secondLayers.Layers[j].CopyTo(layerArrays.Layers[nOfLayers - 1 - j], 0);

                    layerArrays.UpdateXFromLayers();
                }
            }
#else
            Calculate();

            if ( /*orderingMeasure.x>0 &&*/ tryReverse) {
                LayerArrays secondLayers = layerArrays.ReversedClone();

                var revOrdering = new Ordering(properLayeredGraph.ReversedClone(), false, secondLayers, startOfVirtNodes, balanceVirtAndOrigNodes,
                                               hasCrossWeights, settings);

                revOrdering.Run();

                if (revOrdering.measure < measure) {
                    for (int j = 0; j < nOfLayers; j++)
                        secondLayers.Layers[j].CopyTo(layerArrays.Layers[nOfLayers - 1 - j], 0);

                    layerArrays.UpdateXFromLayers();
                }
            }
#endif
        }