/// <seealso cref="Graph.getAllEdges(Object, Object)"> /// </seealso> public override System.Collections.IList getAllEdges(System.Object sourceVertex, System.Object targetVertex) { System.Collections.IList edges = null; if (Enclosing_Instance.containsVertex(sourceVertex) && Enclosing_Instance.containsVertex(targetVertex)) { edges = new System.Collections.ArrayList(); DirectedEdgeContainer ec = getEdgeContainer(sourceVertex); System.Collections.IEnumerator iter = ec.m_outgoing.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 (iter.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'" Edge e = (Edge)iter.Current; if (e.Target.Equals(targetVertex)) { edges.Add(e); } } } return(edges); }
/// <seealso cref="Graph.addEdge(Object, Object)"> /// </seealso> public override Edge addEdge(System.Object sourceVertex, System.Object targetVertex) { assertVertexExist(sourceVertex); assertVertexExist(targetVertex); if (!m_allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) { return(null); } if (!m_allowingLoops && sourceVertex.Equals(targetVertex)) { throw new System.ArgumentException(LOOPS_NOT_ALLOWED); } Edge e = m_edgeFactory.createEdge(sourceVertex, targetVertex); if (containsEdge(e)) { // this restriction should stay! return(null); } else { m_edgeSet.Add(e); m_specifics.addEdgeToTouchingVertices(e); return(e); } }
/// <seealso cref="Graph.getEdge(Object, Object)"> /// </seealso> public override Edge getEdge(System.Object sourceVertex, System.Object targetVertex) { if (Enclosing_Instance.containsVertex(sourceVertex) && Enclosing_Instance.containsVertex(targetVertex)) { System.Collections.IEnumerator iter = getEdgeContainer(sourceVertex).m_vertexEdges.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 (iter.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'" Edge e = (Edge)iter.Current; bool equalStraight = sourceVertex.Equals(e.Source) && targetVertex.Equals(e.Target); bool equalInverted = sourceVertex.Equals(e.Target) && targetVertex.Equals(e.Source); if (equalStraight || equalInverted) { return(e); } } } return(null); }
/// <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 }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { if (e == null) { throw new System.NullReferenceException(); } else if (containsEdge(e)) { return(false); } System.Object sourceVertex = e.Source; System.Object targetVertex = e.Target; assertVertexExist(sourceVertex); assertVertexExist(targetVertex); assertCompatibleWithEdgeFactory(e); if (!m_allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) { return(false); } if (!m_allowingLoops && sourceVertex.Equals(targetVertex)) { throw new System.ArgumentException(LOOPS_NOT_ALLOWED); } m_edgeSet.Add(e); m_specifics.addEdgeToTouchingVertices(e); return(true); }
/// <seealso cref="UndirectedGraph.degree(Object)"> /// </seealso> public override int degreeOf(System.Object vertex) { if (Enclosing_Instance.m_allowingLoops) { // then we must count, and add loops twice int degree = 0; System.Collections.IList edges = getEdgeContainer(vertex).m_vertexEdges; //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 iter = edges.GetEnumerator(); iter.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'" Edge e = (Edge)iter.Current; if (e.Source.Equals(e.Target)) { degree += 2; } else { degree += 1; } } return(degree); } else { return(getEdgeContainer(vertex).edgeCount()); } }
/// <seealso cref="AbstractBaseGraph.addEdgeToTouchingVertices(Edge)"> /// </seealso> public override void addEdgeToTouchingVertices(Edge e) { System.Object source = e.Source; System.Object target = e.Target; getEdgeContainer(source).addOutgoingEdge(e); getEdgeContainer(target).addIncomingEdge(e); }
/// <seealso cref="AbstractBaseGraph.removeEdgeFromTouchingVertices(Edge)"> /// </seealso> public override void removeEdgeFromTouchingVertices(Edge e) { System.Object source = e.Source; System.Object target = e.Target; getEdgeContainer(source).removeOutgoingEdge(e); getEdgeContainer(target).removeIncomingEdge(e); }
/// <seealso cref="Graph.removeEdge(Object, Object)"> /// </seealso> public override Edge removeEdge(System.Object sourceVertex, System.Object targetVertex) { Edge e = base.removeEdge(sourceVertex, targetVertex); if (e != null) { fireEdgeRemoved(e); } return(e); }
/// <summary> Notify listeners that the specified edge was removed. /// /// </summary> /// <param name="edge">the edge that was removed. /// </param> protected internal virtual void fireEdgeRemoved(Edge edge) { GraphEdgeChangeEvent e = createGraphEdgeChangeEvent(GraphEdgeChangeEvent.EDGE_REMOVED, edge); for (int i = 0; i < m_graphListeners.Count; i++) { GraphListener l = (GraphListener)m_graphListeners[i]; l.edgeRemoved(this, e); } }
/// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> public override bool removeEdge(Edge e) { bool modified = base.removeEdge(e); if (modified) { fireEdgeRemoved(e); } return(modified); }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { bool modified = base.addEdge(e); if (modified) { fireEdgeAdded(e); } return(modified); }
/// <seealso cref="org._3pq.jgrapht.Graph.getEdge(Object, Object)"> /// </seealso> public override Edge getEdge(System.Object sourceVertex, System.Object targetVertex) { Edge edge = base.getEdge(sourceVertex, targetVertex); if (edge != null) { return(edge); } // try the other direction return(base.getEdge(targetVertex, sourceVertex)); }
/// <seealso cref="Graph.removeEdge(Object, Object)"> /// </seealso> public override Edge removeEdge(System.Object sourceVertex, System.Object targetVertex) { Edge e = getEdge(sourceVertex, targetVertex); if (e != null) { m_specifics.removeEdgeFromTouchingVertices(e); m_edgeSet.Remove(e); } return(e); }
private bool assertCompatibleWithEdgeFactory(Edge e) { if (e == null) { throw new System.NullReferenceException(); } else if (!m_factoryEdgeClass.IsInstanceOfType(e)) { throw new System.InvalidCastException("incompatible edge class"); } return(true); }
/// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> public override bool removeEdge(Edge e) { if (containsEdge(e)) { m_specifics.removeEdgeFromTouchingVertices(e); m_edgeSet.Remove(e); return(true); } else { return(false); } }
private GraphEdgeChangeEvent createGraphEdgeChangeEvent(int eventType, Edge edge) { if (m_reuseEvents) { m_reuseableEdgeEvent.setType(eventType); m_reuseableEdgeEvent.setEdge(edge); return(m_reuseableEdgeEvent); } else { return(new GraphEdgeChangeEvent(this, eventType, edge)); } }
/// <seealso cref="AbstractBaseGraph.toString()"> /// </seealso> public override System.String ToString() { // take care to print edges using the undirected convention System.Collections.ICollection edgeSet = new System.Collections.ArrayList(); System.Collections.IEnumerator iter = edgeSet.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 (iter.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'" Edge edge = (Edge)iter.Current; SupportClass.ICollectionSupport.Add(edgeSet, new UndirectedEdge(edge.Source, edge.Target)); } return(base.toStringFromSets(vertexSet(), edgeSet)); }
//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'" private void exportEdge(System.IO.StreamWriter out_Renamed, Edge edge) { System.String sourceName = m_vertexNameProvider.getVertexName(edge.Source); System.String targetName = m_vertexNameProvider.getVertexName(edge.Target); out_Renamed.Write("Link,"); // create unique ShapeId for link out_Renamed.Write(sourceName); out_Renamed.Write("-->"); out_Renamed.Write(targetName); // MasterName and Text fields left blank out_Renamed.Write(",,,"); out_Renamed.Write(sourceName); out_Renamed.Write(","); out_Renamed.Write(targetName); out_Renamed.Write("\n"); }
/// <seealso cref="Graph.removeVertex(Object)"> /// </seealso> public override bool removeVertex(System.Object v) { if (containsVertex(v)) { System.Collections.IList touchingEdgesList = edgesOf(v); // cannot iterate over list - will cause ConcurrentModificationException Edge[] touchingEdges = new Edge[touchingEdgesList.Count]; SupportClass.ICollectionSupport.ToArray(touchingEdgesList, touchingEdges); removeAllEdges(touchingEdges); m_vertexMap.Remove(v); // remove the vertex itself return(true); } else { return(false); } }
/// <summary> Construct a new pseudograph. The pseudograph can either be directed or /// undirected, depending on the specified edge factory. A sample edge is /// created using the edge factory to see if the factory is compatible with /// this class of graph. For example, if this graph is a /// <code>DirectedGraph</code> the edge factory must produce /// <code>DirectedEdge</code>s. If this is not the case, an /// <code>IllegalArgumentException</code> is thrown. /// /// </summary> /// <param name="ef">the edge factory of the new graph. /// </param> /// <param name="allowMultipleEdges">whether to allow multiple edges or not. /// </param> /// <param name="allowLoops">whether to allow edges that are self-loops or not. /// /// </param> /// <throws> NullPointerException if the specified edge factory is </throws> /// <summary> <code>null</code>. /// </summary> public AbstractBaseGraph(EdgeFactory ef, bool allowMultipleEdges, bool allowLoops) { if (ef == null) { throw new System.NullReferenceException(); } m_vertexMap = new SupportClass.HashSetSupport(); m_edgeSet = new SupportClass.HashSetSupport(); m_edgeFactory = ef; m_allowingLoops = allowLoops; m_allowingMultipleEdges = allowMultipleEdges; m_specifics = createSpecifics(); Edge e = ef.createEdge(new System.Object(), new System.Object()); m_factoryEdgeClass = e.GetType(); m_edgeListFactory = new ArrayListFactory(); m_unmodifiableEdgeSet = null; m_unmodifiableVertexSet = null; }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { bool modified = base.addEdge(e); if (modified) { fireEdgeAdded(e); } return modified; }
/// <seealso cref="Graph.removeVertex(Object)"> /// </seealso> public override bool removeVertex(System.Object v) { if (containsVertex(v)) { System.Collections.IList touchingEdgesList = edgesOf(v); // cannot iterate over list - will cause ConcurrentModificationException Edge[] touchingEdges = new Edge[touchingEdgesList.Count]; SupportClass.ICollectionSupport.ToArray(touchingEdgesList, touchingEdges); removeAllEdges(touchingEdges); base.removeVertex(v); // remove the vertex itself fireVertexRemoved(v); return true; } else { return false; } }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { if (e == null) { throw new System.NullReferenceException(); } else if (containsEdge(e)) { return false; } System.Object sourceVertex = e.Source; System.Object targetVertex = e.Target; assertVertexExist(sourceVertex); assertVertexExist(targetVertex); assertCompatibleWithEdgeFactory(e); if (!m_allowingMultipleEdges && containsEdge(sourceVertex, targetVertex)) { return false; } if (!m_allowingLoops && sourceVertex.Equals(targetVertex)) { throw new System.ArgumentException(LOOPS_NOT_ALLOWED); } m_edgeSet.Add(e); m_specifics.addEdgeToTouchingVertices(e); return true; }
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void addEdge(Edge e) { m_vertexEdges.Add(e); }
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void addOutgoingEdge(Edge e) { m_outgoing.Add(e); }
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void removeOutgoingEdge(Edge e) { m_outgoing.Remove(e); }
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void removeIncomingEdge(Edge e) { m_incoming.Remove(e); }
/// <seealso cref="org._3pq.jgrapht.traverse.CrossComponentIterator.encounterVertex(java.lang.Object,"> /// org._3pq.jgrapht.Edge) /// </seealso> protected internal override void encounterVertex(System.Object vertex, Edge edge) { putSeenData(vertex, (System.Object) null); m_queue.Insert(m_queue.Count, vertex); }
/// <seealso cref="org._3pq.jgrapht.traverse.CrossComponentIterator.encounterVertexAgain(java.lang.Object,"> /// org._3pq.jgrapht.Edge) /// </seealso> protected internal override void encounterVertexAgain(System.Object vertex, Edge edge) { }
private GraphEdgeChangeEvent createGraphEdgeChangeEvent(int eventType, Edge edge) { if (m_reuseEvents) { m_reuseableEdgeEvent.setType(eventType); m_reuseableEdgeEvent.setEdge(edge); return m_reuseableEdgeEvent; } else { return new GraphEdgeChangeEvent(this, eventType, edge); } }
/// <seealso cref="Graph.containsEdge(Edge)"> /// </seealso> public override bool containsEdge(Edge e) { return m_delegate.containsEdge(e); }
/// <summary> Sets the edge of this event. /// /// </summary> /// <param name="e">the edge to be set. /// </param> protected internal virtual void setEdge(Edge e) { m_edge = e; }
/// <seealso cref="org._3pq.jgrapht.traverse.CrossComponentIterator.encounterVertex(java.lang.Object,"> /// org._3pq.jgrapht.Edge) /// </seealso> protected internal override void encounterVertex(System.Object vertex, Edge edge) { putSeenData(vertex, (System.Object) null); m_stack.Add(vertex); }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { throw new System.NotSupportedException(UNMODIFIABLE); }
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void addIncomingEdge(Edge e) { m_incoming.Add(e); }
/// <seealso cref="Graph.containsEdge(Edge)"> /// </seealso> public override bool containsEdge(Edge e) { return m_edgeSet.Contains(e); }
/// <summary> Removes the specified edge from the edge containers of its source /// and target vertices. /// /// </summary> /// <param name="e"> /// </param> public abstract void removeEdgeFromTouchingVertices(Edge e);
/// <summary> . /// /// </summary> /// <param name="e"> /// </param> public virtual void removeEdge(Edge e) { m_vertexEdges.Remove(e); }
/// <summary> Adds the specified edge to the edge containers of its source and /// target vertices. /// /// </summary> /// <param name="e"> /// </param> public abstract void addEdgeToTouchingVertices(Edge e);
private bool assertCompatibleWithEdgeFactory(Edge e) { if (e == null) { throw new System.NullReferenceException(); } else if (!m_factoryEdgeClass.IsInstanceOfType(e)) { throw new System.InvalidCastException("incompatible edge class"); } return true; }
/// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> public override bool removeEdge(Edge e) { bool modified = base.removeEdge(e); if (modified) { fireEdgeRemoved(e); } return modified; }
/// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> public override bool removeEdge(Edge e) { if (containsEdge(e)) { m_specifics.removeEdgeFromTouchingVertices(e); m_edgeSet.Remove(e); return true; } else { return false; } }
/// <summary> Notify listeners that the specified edge was removed. /// /// </summary> /// <param name="edge">the edge that was removed. /// </param> protected internal virtual void fireEdgeRemoved(Edge edge) { GraphEdgeChangeEvent e = createGraphEdgeChangeEvent(GraphEdgeChangeEvent.EDGE_REMOVED, edge); for (int i = 0; i < m_graphListeners.Count; i++) { GraphListener l = (GraphListener) m_graphListeners[i]; l.edgeRemoved(this, e); } }
/// <seealso cref="GraphEdgeChangeEvent.GraphEdgeChangeEvent(Object, int, Edge)"> /// </seealso> public FlyweightEdgeEvent(System.Object eventSource, int type, Edge e):base(eventSource, type, e) { }
/// <summary> {@inheritDoc}</summary> protected internal override void encounterVertexAgain(System.Object vertex, Edge edge) { base.encounterVertexAgain(vertex, edge); int i = m_path.IndexOf(vertex); if (i > -1) { if (m_cycleSet == null) { // we're doing yes/no cycle detection throw new CycleDetectedException(); } for (; i < m_path.Count; ++i) { m_cycleSet.Add(m_path[i]); } } }
/// <seealso cref="Graph.addEdge(Edge)"> /// </seealso> public override bool addEdge(Edge e) { return m_delegate.addEdge(e); }
/// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> public override bool removeEdge(Edge e) { return m_delegate.removeEdge(e); }
/// <summary> Removes all the edges in this graph that are also contained in the /// specified edge array. After this call returns, this graph will contain /// no edges in common with the specified edges. This method will invoke /// the {@link Graph#removeEdge(Edge)} method. /// /// </summary> /// <param name="edges">edges to be removed from this graph. /// /// </param> /// <returns> <tt>true</tt> if this graph changed as a result of the call. /// /// </returns> /// <seealso cref="Graph.removeEdge(Edge)"> /// </seealso> /// <seealso cref="Graph.containsEdge(Edge)"> /// </seealso> protected internal virtual bool removeAllEdges(Edge[] edges) { bool modified = false; for (int i = 0; i < edges.Length; i++) { modified |= removeEdge(edges[i]); } return modified; }