/// <summary> Finds a greedy approximation for a minimal vertex cover of a specified /// graph. At each iteration, the algorithm picks the vertex with the /// highest degree and adds it to the cover, until all edges are covered. /// /// <p> /// The algorithm works on undirected graphs, but can also work on directed /// graphs when their edge-directions are ignored. To ignore edge /// directions you can use {@link /// org._3pq.jgrapht.GraphHelper#undirectedGraph(Graph)} or {@link /// org._3pq.jgrapht.graph.AsUndirectedGraph}. /// </p> /// /// </summary> /// <param name="g">the graph for which vertex cover approximation is to be found. /// /// </param> /// <returns> a set of vertices which is a vertex cover for the specified /// graph. /// </returns> public virtual SupportClass.SetSupport findGreedyCover(UndirectedGraph g) { // C <-- {} //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'" SupportClass.SetSupport cover = new SupportClass.HashSetSupport(); // G' <-- G UndirectedGraph sg = new UndirectedSubgraph(g, null, null); // compare vertices in descending order of degree VertexDegreeComparator comp = new VertexDegreeComparator(sg); // while G' != {} while (sg.edgeSet().Count > 0) { // v <-- vertex with maximum degree in G' System.Object v = SupportClass.CollectionsSupport.Max(sg.vertexSet(), comp); // C <-- C U {v} cover.Add(v); // remove from G' every edge incident on v, and v itself sg.removeVertex(v); } return(cover); }
/// <summary> Finds a greedy approximation for a minimal vertex cover of a specified /// graph. At each iteration, the algorithm picks the vertex with the /// highest degree and adds it to the cover, until all edges are covered. /// /// <p> /// The algorithm works on undirected graphs, but can also work on directed /// graphs when their edge-directions are ignored. To ignore edge /// directions you can use {@link /// org._3pq.jgrapht.GraphHelper#undirectedGraph(Graph)} or {@link /// org._3pq.jgrapht.graph.AsUndirectedGraph}. /// </p> /// /// </summary> /// <param name="g">the graph for which vertex cover approximation is to be found. /// /// </param> /// <returns> a set of vertices which is a vertex cover for the specified /// graph. /// </returns> public virtual SupportClass.SetSupport findGreedyCover(UndirectedGraph g) { // C <-- {} //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'" SupportClass.SetSupport cover = new SupportClass.HashSetSupport(); // G' <-- G UndirectedGraph sg = new UndirectedSubgraph(g, null, null); // compare vertices in descending order of degree VertexDegreeComparator comp = new VertexDegreeComparator(sg); // while G' != {} while (sg.edgeSet().Count > 0) { // v <-- vertex with maximum degree in G' System.Object v = SupportClass.CollectionsSupport.Max(sg.vertexSet(), comp); // C <-- C U {v} cover.Add(v); // remove from G' every edge incident on v, and v itself sg.removeVertex(v); } return cover; }