public int[] GetLayers() { List<IEnumerable<int>> comps = new List<IEnumerable<int>>(ConnectedComponentCalculator<IntEdge>.GetComponents(graph)); if (comps.Count == 1) { NetworkSimplex ns = new NetworkSimplex(graph, this.Cancel); return ns.GetLayers(); } List<Dictionary<int, int>> mapToComponenents = GetMapsToComponent(comps); int[][] layerings = new int[comps.Count][]; for (int i = 0; i < comps.Count; i++) { BasicGraph<Node, IntEdge> shrunkedComp = ShrunkComponent(mapToComponenents[i]); NetworkSimplex ns = new NetworkSimplex(shrunkedComp, Cancel); layerings[i] = ns.GetLayers(); } return UniteLayerings(layerings, mapToComponenents); }
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); }