コード例 #1
0
        static private int GetSource(int i, PolyIntEdge edge, ref int virtualNode)
        {
            if (i > 0)
            {
                return(virtualNode++);
            }

            return(edge.Source);
        }
コード例 #2
0
        static private int GetTarget(int i, int span, PolyIntEdge edge, int virtualNode)
        {
            if (i < span - 1)
            {
                return(virtualNode);
            }

            return(edge.Target);
        }
コード例 #3
0
        private void InsertLayerEdgesForEdge(PolyIntEdge edge, int[] layering, ref int virtualNode, List <int>[] layers)
        {
            int span = OriginalNodeLayer(edge.Source) - OriginalNodeLayer(edge.Target);

            edge.LayerEdges = new LayerEdge[span];
            for (int i = 0; i < span; i++)
            {
                edge.LayerEdges[i] = new LayerEdge(GetSource(i, edge, ref virtualNode), GetTarget(i, span, edge, virtualNode), edge.CrossingWeight);
            }

            int l = OriginalNodeLayer(edge.Source) - 1;

            for (int i = 0; i < span; i++)
            {
                int node = edge.LayerEdges[i].Target;
                layering[node] = l;
                layers[l--].Add(node);
            }

            WalkTreeAndInsertLayerEdges(layering, layers, edge.Target, ref virtualNode);
        }
コード例 #4
0
        public void SmallGraph()
        {
            // (ab)(bc)(cd)(dh)(af)(fg)(ae)(eg)(gh)
            int a = 0;
            int b = 1;
            int c = 2;
            int d = 3;
            int e = 4;
            int f = 5;
            int g = 6;
            int h = 7;
            Func <int, int, PolyIntEdge> edge = (int x, int y) => new PolyIntEdge(x, y, null)
            {
                Separation = 1
            };

            var edges = new PolyIntEdge[] { edge(a, b), edge(b, c), edge(c, d), edge(d, h), edge(a, f), edge(f, g), edge(a, e), edge(e, g), edge(g, h) };
            var graph = new BasicGraphOnEdges <PolyIntEdge>(edges);
            var ns    = new NetworkSimplex(graph, new CancelToken());

            ns.Run();
            Assert.AreEqual(ns.Weight, 10);
        }
コード例 #5
0
 private int NumberOfVirtualNodesOnEdge(PolyIntEdge edge)
 {
     return(OriginalNodeLayer(edge.Source) - OriginalNodeLayer(edge.Target) - 1);
 }