/// <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; }
public UndirectedSubgraph(UndirectedGraph base_Renamed, SupportClass.SetSupport vertexSubset) : base(base_Renamed, vertexSubset) { }
/// <summary> Creates a comparator for comparing the degrees of vertices in the /// specified graph. /// /// </summary> /// <param name="g">graph with respect to which the degree is calculated. /// </param> /// <param name="ascendingOrder">true - compares in ascending order of degrees /// (lowest first), false - compares in descending order of degrees /// (highest first). /// </param> public VertexDegreeComparator(UndirectedGraph g, bool ascendingOrder) { m_graph = g; m_ascendingOrder = ascendingOrder; }
/// <summary> Creates a comparator for comparing the degrees of vertices in the /// specified graph. The comparator compares in ascending order of degrees /// (lowest first). /// /// </summary> /// <param name="g">graph with respect to which the degree is calculated. /// </param> public VertexDegreeComparator(UndirectedGraph g) : this(g, true) { }
/// <summary> Creates a new listenable undirected graph. /// /// </summary> /// <param name="base">the backing graph. /// </param> public ListenableUndirectedGraph(UndirectedGraph base_Renamed) : base(base_Renamed) { }
/// <summary> Creates a new unmodifiable undirected graph based on the specified /// backing graph. /// /// </summary> /// <param name="g">the backing graph on which an unmodifiable graph is to be /// created. /// </param> public UnmodifiableUndirectedGraph(UndirectedGraph g):base(g) { }
/// <summary> Creates a new unmodifiable undirected graph based on the specified /// backing graph. /// /// </summary> /// <param name="g">the backing graph on which an unmodifiable graph is to be /// created. /// </param> public UnmodifiableUndirectedGraph(UndirectedGraph g) : base(g) { }
/// <summary> Creates a comparator for comparing the degrees of vertices in the /// specified graph. The comparator compares in ascending order of degrees /// (lowest first). /// /// </summary> /// <param name="g">graph with respect to which the degree is calculated. /// </param> public VertexDegreeComparator(UndirectedGraph g):this(g, true) { }