/// <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 }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { System.Object lastVertex = null; for (int i = 0; i < m_size; ++i) { System.Object newVertex = vertexFactory.createVertex(); target.addVertex(newVertex); if (lastVertex == null) { if (resultMap != null) { resultMap[START_VERTEX] = newVertex; } } else { target.addEdge(lastVertex, newVertex); } lastVertex = newVertex; } if ((resultMap != null) && (lastVertex != null)) { resultMap[END_VERTEX] = lastVertex; } }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { for (int i = 0; i < m_size; ++i) { target.addVertex(vertexFactory.createVertex()); } }
/// <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 }
/// <summary> Constructor for GraphDelegator. /// /// </summary> /// <param name="g">the backing graph (the delegate). /// /// </param> /// <throws> NullPointerException </throws> public GraphDelegator(Graph g) : base() { if (g == null) { throw new System.NullReferenceException(); } m_delegate = g; }
/// <summary> Creates a new listenable graph. If the <code>reuseEvents</code> flag is /// set to <code>true</code> this class will reuse previously fired events /// and will not create a new object for each event. This option increases /// performance but should be used with care, especially in multithreaded /// environment. /// /// </summary> /// <param name="g">the backing graph. /// </param> /// <param name="reuseEvents">whether to reuse previously fired event objects /// instead of creating a new event object for each event. /// /// </param> /// <throws> IllegalArgumentException if the backing graph is already a </throws> /// <summary> listenable graph. /// </summary> public DefaultListenableGraph(Graph g, bool reuseEvents) : base(g) { m_reuseEvents = reuseEvents; m_reuseableEdgeEvent = new FlyweightEdgeEvent(this, -1, null); m_reuseableVertexEvent = new FlyweightVertexEvent(this, -1, (System.Object)null); // the following restriction could be probably relaxed in the future. if (g is ListenableGraph) { throw new System.ArgumentException("base graph cannot be listenable"); } }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { if (m_size < 1) { return ; } LinearGraphGenerator linearGenerator = new LinearGraphGenerator(m_size); //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" System.Collections.IDictionary privateMap = new System.Collections.Hashtable(); linearGenerator.generateGraph(target, vertexFactory, privateMap); System.Object startVertex = privateMap[LinearGraphGenerator.START_VERTEX]; System.Object endVertex = privateMap[LinearGraphGenerator.END_VERTEX]; target.addEdge(endVertex, startVertex); }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { if (m_size < 1) { return; } LinearGraphGenerator linearGenerator = new LinearGraphGenerator(m_size); //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'" System.Collections.IDictionary privateMap = new System.Collections.Hashtable(); linearGenerator.generateGraph(target, vertexFactory, privateMap); System.Object startVertex = privateMap[LinearGraphGenerator.START_VERTEX]; System.Object endVertex = privateMap[LinearGraphGenerator.END_VERTEX]; target.addEdge(endVertex, startVertex); }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { if (m_size < 1) { return; } // A little trickery to intercept the rim generation. This is // necessary since target may be initially non-empty, meaning we can't // rely on its vertex set after the rim is generated. //UPGRADE_NOTE: Final was removed from the declaration of 'rim '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.Collections.ICollection rim = new System.Collections.ArrayList(); VertexFactory rimVertexFactory = new AnonymousClassVertexFactory(vertexFactory, rim, this); RingGraphGenerator ringGenerator = new RingGraphGenerator(m_size - 1); ringGenerator.generateGraph(target, rimVertexFactory, resultMap); System.Object hubVertex = vertexFactory.createVertex(); target.addVertex(hubVertex); if (resultMap != null) { resultMap[HUB_VERTEX] = hubVertex; } System.Collections.IEnumerator rimIter = rim.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (rimIter.MoveNext()) { //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'" System.Object rimVertex = rimIter.Current; if (m_inwardSpokes) { target.addEdge(rimVertex, hubVertex); } else { target.addEdge(hubVertex, rimVertex); } } }
/// <summary> Exports the specified graph into a Visio csv file format. /// /// </summary> /// <param name="output">the print stream to which the graph to be exported. /// </param> /// <param name="g">the graph to be exported. /// </param> public virtual void export(System.IO.Stream output, Graph g) { //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.PrintStream' and 'System.IO.StreamWriter' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'" System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(output); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator i = g.vertexSet().GetEnumerator(); i.MoveNext();) { //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'" exportVertex(out_Renamed, i.Current); } //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator i = g.edgeSet().GetEnumerator(); i.MoveNext();) { //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'" exportEdge(out_Renamed, (Edge)i.Current); } out_Renamed.Flush(); }
/// <summary> Constructs a new JGraph model adapter for the specified JGraphT graph. /// /// </summary> /// <param name="jGraphTGraph">the JGraphT graph for which JGraph model adapter to /// be created. <code>null</code> is NOT permitted. /// </param> public JGraphModelAdapter(Graph jGraphTGraph):this(jGraphTGraph, createDefaultVertexAttributes(), createDefaultEdgeAttributes(jGraphTGraph)) { }
/// <summary> Creates a new breadth-first iterator for the specified graph. Iteration /// will start at the specified start vertex and will be limited to the /// connected component that includes that vertex. If the specified start /// vertex is <code>null</code>, iteration will start at an arbitrary /// vertex and will not be limited, that is, will be able to traverse all /// the graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> /// <param name="startVertex">the vertex iteration to be started. /// </param> public BreadthFirstIterator(Graph g, System.Object startVertex):base(g, startVertex) { }
/// <summary> Creates a new breadth-first iterator for the specified graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> public BreadthFirstIterator(Graph g):this(g, null) { }
/// <summary> Constructs a new JGraph model adapter for the specified JGraphT graph. /// /// </summary> /// <param name="jGraphTGraph">the JGraphT graph for which JGraph model adapter to /// be created. <code>null</code> is NOT permitted. /// </param> /// <param name="defaultVertexAttributes">a default map of JGraph attributes to /// format vertices. <code>null</code> is NOT permitted. /// </param> /// <param name="defaultEdgeAttributes">a default map of JGraph attributes to /// format edges. <code>null</code> is NOT permitted. /// </param> public JGraphModelAdapter(Graph jGraphTGraph, AttributeMap defaultVertexAttributes, AttributeMap defaultEdgeAttributes):this(jGraphTGraph, defaultVertexAttributes, defaultEdgeAttributes, new DefaultCellFactory()) { }
/// <summary> Creates a new unmodifiable 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 UnmodifiableGraph(Graph g) : base(g) { }
/// <summary> Creates a new listenable graph. /// /// </summary> /// <param name="g">the backing graph. /// </param> public DefaultListenableGraph(Graph g) : this(g, false) { }
internal ShieldedGraph(JGraphModelAdapter enclosingInstance, Graph graph) { InitBlock(enclosingInstance); m_graph = graph; }
/// <summary> Constructs a new JGraph model adapter for the specified JGraphT graph. /// /// </summary> /// <param name="jGraphTGraph">the JGraphT graph for which JGraph model adapter to /// be created. <code>null</code> is NOT permitted. /// </param> /// <param name="defaultVertexAttributes">a default map of JGraph attributes to /// format vertices. <code>null</code> is NOT permitted. /// </param> /// <param name="defaultEdgeAttributes">a default map of JGraph attributes to /// format edges. <code>null</code> is NOT permitted. /// </param> /// <param name="cellFactory">a {@link CellFactory} to be used to create the JGraph /// cells. <code>null</code> is NOT permitted. /// /// </param> /// <throws> IllegalArgumentException </throws> public JGraphModelAdapter(Graph jGraphTGraph, AttributeMap defaultVertexAttributes, AttributeMap defaultEdgeAttributes, JGraphModelAdapter.CellFactory cellFactory):base() { if (jGraphTGraph == null || defaultVertexAttributes == null || defaultEdgeAttributes == null || cellFactory == null) { throw new System.ArgumentException("null is NOT permitted"); } m_jtGraph = new ShieldedGraph(this, jGraphTGraph); DefaultVertexAttributes = defaultVertexAttributes; DefaultEdgeAttributes = defaultEdgeAttributes; m_cellFactory = cellFactory; if (jGraphTGraph is ListenableGraph) { ListenableGraph g = (ListenableGraph) jGraphTGraph; g.GraphListenerDelegateVar += new org._3pq.jgrapht.event.GraphListenerDelegate(new JGraphTListener(this).edgeAdded);
/// <summary> Creates a new listenable graph. /// /// </summary> /// <param name="g">the backing graph. /// </param> public DefaultListenableGraph(Graph g):this(g, false) { }
/// <summary> Creates a new depth-first iterator for the specified graph. Iteration /// will start at the specified start vertex and will be limited to the /// connected component that includes that vertex. If the specified start /// vertex is <code>null</code>, iteration will start at an arbitrary /// vertex and will not be limited, that is, will be able to traverse all /// the graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> /// <param name="startVertex">the vertex iteration to be started. /// </param> public DepthFirstIterator(Graph g, System.Object startVertex) : base(g, startVertex) { }
/// <summary> Creates a new depth-first iterator for the specified graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> public DepthFirstIterator(Graph g) : this(g, null) { }
/// <summary> Creates a new breadth-first iterator for the specified graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> public BreadthFirstIterator(Graph g) : this(g, null) { }
/// <summary> Creates a new depth-first iterator for the specified graph. /// /// </summary> /// <param name="g">the graph to be iterated. /// </param> public DepthFirstIterator(Graph g):this(g, null) { }
/// <summary> Creates a new listenable graph. If the <code>reuseEvents</code> flag is /// set to <code>true</code> this class will reuse previously fired events /// and will not create a new object for each event. This option increases /// performance but should be used with care, especially in multithreaded /// environment. /// /// </summary> /// <param name="g">the backing graph. /// </param> /// <param name="reuseEvents">whether to reuse previously fired event objects /// instead of creating a new event object for each event. /// /// </param> /// <throws> IllegalArgumentException if the backing graph is already a </throws> /// <summary> listenable graph. /// </summary> public DefaultListenableGraph(Graph g, bool reuseEvents):base(g) { m_reuseEvents = reuseEvents; m_reuseableEdgeEvent = new FlyweightEdgeEvent(this, - 1, null); m_reuseableVertexEvent = new FlyweightVertexEvent(this, - 1, (System.Object) null); // the following restriction could be probably relaxed in the future. if (g is ListenableGraph) { throw new System.ArgumentException("base graph cannot be listenable"); } }
/// <summary> {@inheritDoc}</summary> public virtual void generateGraph(Graph target, VertexFactory vertexFactory, System.Collections.IDictionary resultMap) { if (m_size < 1) { return ; } // A little trickery to intercept the rim generation. This is // necessary since target may be initially non-empty, meaning we can't // rely on its vertex set after the rim is generated. //UPGRADE_NOTE: Final was removed from the declaration of 'rim '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" System.Collections.ICollection rim = new System.Collections.ArrayList(); VertexFactory rimVertexFactory = new AnonymousClassVertexFactory(vertexFactory, rim, this); RingGraphGenerator ringGenerator = new RingGraphGenerator(m_size - 1); ringGenerator.generateGraph(target, rimVertexFactory, resultMap); System.Object hubVertex = vertexFactory.createVertex(); target.addVertex(hubVertex); if (resultMap != null) { resultMap[HUB_VERTEX] = hubVertex; } System.Collections.IEnumerator rimIter = rim.GetEnumerator(); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" while (rimIter.MoveNext()) { //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'" System.Object rimVertex = rimIter.Current; if (m_inwardSpokes) { target.addEdge(rimVertex, hubVertex); } else { target.addEdge(hubVertex, rimVertex); } } }
/// <summary> Creates a cycle detector for the specified graph. Currently only /// directed graphs are supported. /// /// </summary> /// <param name="graph">the DirectedGraph in which to detect cycles /// </param> public CycleDetector(DirectedGraph graph) { m_graph = graph; }
/// <summary> Creates a new unmodifiable 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 UnmodifiableGraph(Graph g):base(g) { }
/// <summary> Constructor for GraphDelegator. /// /// </summary> /// <param name="g">the backing graph (the delegate). /// /// </param> /// <throws> NullPointerException </throws> public GraphDelegator(Graph g):base() { if (g == null) { throw new System.NullReferenceException(); } m_delegate = g; }
/// <summary> Exports the specified graph into a Visio csv file format. /// /// </summary> /// <param name="output">the print stream to which the graph to be exported. /// </param> /// <param name="g">the graph to be exported. /// </param> public virtual void export(System.IO.Stream output, Graph g) { //UPGRADE_ISSUE: Class hierarchy differences between 'java.io.PrintStream' and 'System.IO.StreamWriter' may cause compilation errors. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1186'" System.IO.StreamWriter out_Renamed = new System.IO.StreamWriter(output); //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator i = g.vertexSet().GetEnumerator(); i.MoveNext(); ) { //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'" exportVertex(out_Renamed, i.Current); } //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'" for (System.Collections.IEnumerator i = g.edgeSet().GetEnumerator(); i.MoveNext(); ) { //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'" exportEdge(out_Renamed, (Edge) i.Current); } out_Renamed.Flush(); }