コード例 #1
0
ファイル: VertexCovers.cs プロジェクト: carlhuth/GenXSource
        /// <summary> Finds a 2-approximation for a minimal vertex cover of the specified
        /// graph. The algorithm promises a cover that is at most double the size
        /// of a minimal cover. The algorithm takes O(|E|) time.
        ///
        /// <p>
        /// For more details see Jenny Walter, CMPU-240: Lecture notes for Language
        /// Theory and Computation, Fall 2002, Vassar College, <a
        /// href="http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf">
        ///
        /// http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf</a>.
        /// </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 find2ApproximationCover(Graph 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'=(V',E') <-- G(V,E)
            Subgraph sg = new Subgraph(g, null, null);

            // while E' is non-empty
            while (sg.edgeSet().Count > 0)
            {
                // let (u,v) be an arbitrary edge of E'
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                Edge e = (Edge)sg.edgeSet().GetEnumerator().Current;

                // C <-- C U {u,v}
                System.Object u = e.Source;
                System.Object v = e.Target;
                cover.Add(u);
                cover.Add(v);

                // remove from E' every edge incident on either u or v
                sg.removeVertex(u);
                sg.removeVertex(v);
            }

            return(cover);            // return C
        }
コード例 #2
0
		/// <summary> Finds a 2-approximation for a minimal vertex cover of the specified
		/// graph. The algorithm promises a cover that is at most double the size
		/// of a minimal cover. The algorithm takes O(|E|) time.
		/// 
		/// <p>
		/// For more details see Jenny Walter, CMPU-240: Lecture notes for Language
		/// Theory and Computation, Fall 2002, Vassar College, <a
		/// href="http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf">
		/// 
		/// http://www.cs.vassar.edu/~walter/cs241index/lectures/PDF/approx.pdf</a>.
		/// </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 find2ApproximationCover(Graph 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'=(V',E') <-- G(V,E)
			Subgraph sg = new Subgraph(g, null, null);
			
			// while E' is non-empty
			while (sg.edgeSet().Count > 0)
			{
				// let (u,v) be an arbitrary edge of E'
				//UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
				Edge e = (Edge) sg.edgeSet().GetEnumerator().Current;
				
				// C <-- C U {u,v}
				System.Object u = e.Source;
				System.Object v = e.Target;
				cover.Add(u);
				cover.Add(v);
				
				// remove from E' every edge incident on either u or v
				sg.removeVertex(u);
				sg.removeVertex(v);
			}
			
			return cover; // return C
		}