Пример #1
0
        private void createMinimumCycleBasis()
        {
            org._3pq.jgrapht.Graph subgraph = new Subgraph(graph, null, null);

            CSGraphT.SupportClass.SetSupport remainingEdges = new CSGraphT.SupportClass.HashSetSupport(graph.edgeSet());
            //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'"
            CSGraphT.SupportClass.SetSupport selectedEdges = new CSGraphT.SupportClass.HashSetSupport();

            while (!(remainingEdges.Count == 0))
            {
                //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)remainingEdges.GetEnumerator().Current;

                subgraph.removeEdge(edge);

                // Compute a shortest cycle through edge
                System.Collections.IList path = BFSShortestPath.findPathBetween(subgraph, edge.Source, edge.Target);
                path.Add(edge);
                SimpleCycle cycle = new SimpleCycle(graph, path);

                subgraph.addEdge(edge);

                selectedEdges.Add(edge);

                cycles_Renamed_Field.Insert(0, cycle);
                edgeList.Insert(0, edge);

                SupportClass.ICollectionSupport.RemoveAll(remainingEdges, path);
            }

            subgraph.removeAllEdges(selectedEdges);

            // The cycles just created are already minimal, so we can start minimizing at startIndex
            int startIndex = cycles_Renamed_Field.Count;

            // Now we perform a breadth first traversal and build a fundamental tree base
            // ("Kirchhoff base") of the remaining subgraph

            System.Object currentVertex = graph.vertexSet()[0];

            // We build a spanning tree as a directed graph to easily find the parent of a
            // vertex in the tree. This means however that we have to create new Edge objects
            // for the tree and can't just use the Edge objects of the graph, since the
            // the edge in the graph might have a wrong or no direction.

            DirectedGraph spanningTree = new SimpleDirectedGraph();

            //UPGRADE_TODO: Class 'java.util.HashSet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashSet'"
            CSGraphT.SupportClass.SetSupport visitedEdges = new CSGraphT.SupportClass.HashSetSupport();

            // FIFO for the BFS
            //UPGRADE_TODO: Class 'java.util.LinkedList' was converted to 'System.Collections.ArrayList' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilLinkedList'"
            System.Collections.ArrayList vertexQueue = new System.Collections.ArrayList();

            // currentVertex is the root of the spanning tree
            spanningTree.addVertex(currentVertex);

            vertexQueue.Insert(vertexQueue.Count, currentVertex);

            // We need to remember the tree edges so we can add them at once to the
            // index list for the incidence matrix

            System.Collections.IList treeEdges = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            while (!(vertexQueue.Count == 0))
            {
                System.Object tempObject;
                tempObject = vertexQueue[0];
                vertexQueue.RemoveAt(0);
                currentVertex = tempObject;

                System.Collections.IEnumerator edges = subgraph.edgesOf(currentVertex).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 (edges.MoveNext())
                {
                    // find a neighbour vertex of the current vertex 
                    //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)edges.Current;

                    if (!visitedEdges.Contains(edge))
                    {

                        // mark edge as visited
                        visitedEdges.Add(edge);

                        System.Object nextVertex = edge.oppositeVertex(currentVertex);

                        if (!spanningTree.containsVertex(nextVertex))
                        {
                            // tree edge

                            treeEdges.Add(edge);

                            spanningTree.addVertex(nextVertex);

                            // create a new (directed) Edge object (as explained above)
                            spanningTree.addEdge(currentVertex, nextVertex);

                            // add the next vertex to the BFS-FIFO
                            vertexQueue.Insert(vertexQueue.Count, nextVertex);
                        }
                        else
                        {
                            // non-tree edge

                            // This edge defines a cycle together with the edges of the spanning tree
                            // along the path to the root of the tree. We create a new cycle containing 
                            // these edges (not the tree edges, but the corresponding edges in the graph)

                            System.Collections.IList edgesOfCycle = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

                            // follow the path to the root of the tree

                            System.Object vertex = currentVertex;

                            // get parent of vertex
                            System.Collections.IList incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex);
                            System.Object parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex);

                            while (parent != null)
                            {
                                // add the corresponding edge to the cycle
                                edgesOfCycle.Add(subgraph.getEdge(vertex, parent));

                                // go up the tree
                                vertex = parent;

                                // get parent of vertex
                                incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex);
                                parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex);
                            }

                            // do the same thing for nextVertex
                            vertex = nextVertex;

                            // get parent of vertex
                            incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex);
                            parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex);

                            while (parent != null)
                            {
                                edgesOfCycle.Add(subgraph.getEdge(vertex, parent));
                                vertex = parent;

                                // get parent of vertex
                                incomingEdgesOfVertex = spanningTree.incomingEdgesOf(vertex);
                                parent = (incomingEdgesOfVertex.Count == 0) ? null : ((Edge)incomingEdgesOfVertex[0]).oppositeVertex(vertex);
                            }

                            // finally, add the non-tree edge to the cycle
                            edgesOfCycle.Add(edge);

                            // add the edge to the index list for the incidence matrix
                            edgeList.Add(edge);

                            SimpleCycle newCycle = new SimpleCycle(graph, edgesOfCycle);

                            cycles_Renamed_Field.Add(newCycle);
                        }
                    }
                }
            }

            // Add all the tree edges to the index list for the incidence matrix
            SupportClass.ICollectionSupport.AddAll(edgeList, treeEdges);

            edgeIndexMap = createEdgeIndexMap(edgeList);

            // Now the index list is ordered: first the non-tree edges, then the tree edge.
            // Moreover, since the cycles and the corresponding non-tree edge have been added
            // to their lists in the same order, the incidence matrix is in upper triangular form.

            // Now we can minimize the cycles created from the tree base
            minimize(startIndex);
        }
Пример #2
0
 private void  InitBlock(Subgraph enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
Пример #3
0
 public BaseGraphListener(Subgraph enclosingInstance)
 {
     InitBlock(enclosingInstance);
 }
Пример #4
0
			private void  InitBlock(Subgraph enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}
Пример #5
0
			public BaseGraphListener(Subgraph enclosingInstance)
			{
				InitBlock(enclosingInstance);
			}
		private System.Collections.IList lazyFindBiconnectedSets()
		{
			if (biconnectedSets_Renamed_Field == null)
			{
				biconnectedSets_Renamed_Field = new System.Collections.ArrayList();
				
                IList inspector = new ConnectivityInspector(graph).connectedSets();
                System.Collections.IEnumerator connectedSets = inspector.GetEnumerator();
				
				while (connectedSets.MoveNext())
				{
                    object obj = ((DictionaryEntry)connectedSets.Current).Value;
                    if (!(obj is CSGraphT.SupportClass.HashSetSupport))
                        continue;
					CSGraphT.SupportClass.SetSupport connectedSet = (CSGraphT.SupportClass.SetSupport)obj;
					if (connectedSet.Count == 1)
					{
						continue;
					}
					
					org._3pq.jgrapht.Graph subgraph = new Subgraph(graph, connectedSet, null);
					
					// do DFS
					
					// Stack for the DFS
					System.Collections.ArrayList vertexStack = new System.Collections.ArrayList();
					
					CSGraphT.SupportClass.SetSupport visitedVertices = new CSGraphT.SupportClass.HashSetSupport();
					IDictionary parent = new System.Collections.Hashtable();
					IList dfsVertices = new System.Collections.ArrayList();
					
					CSGraphT.SupportClass.SetSupport treeEdges = new CSGraphT.SupportClass.HashSetSupport();

                    System.Object currentVertex = subgraph.vertexSet()[0];//.ToArray()[0];

					vertexStack.Add(currentVertex);
					visitedVertices.Add(currentVertex);
					
					while (!(vertexStack.Count == 0))
					{
						currentVertex = SupportClass.StackSupport.Pop(vertexStack);
						
						System.Object parentVertex = parent[currentVertex];
						
						if (parentVertex != null)
						{
							Edge edge = subgraph.getEdge(parentVertex, currentVertex);
							
							// tree edge
							treeEdges.Add(edge);
						}
						
						visitedVertices.Add(currentVertex);
						
						dfsVertices.Add(currentVertex);
						
						System.Collections.IEnumerator edges = subgraph.edgesOf(currentVertex).GetEnumerator();
						while (edges.MoveNext())
						{
							// find a neighbour vertex of the current vertex 
							Edge edge = (Edge)edges.Current;
							
							if (!treeEdges.Contains(edge))
							{
								System.Object nextVertex = edge.oppositeVertex(currentVertex);
								
								if (!visitedVertices.Contains(nextVertex))
								{
									vertexStack.Add(nextVertex);
									
									parent[nextVertex] = currentVertex;
								}
								else
								{
									// non-tree edge
								}
							}
						}
					}
					
					// DFS is finished. Now create the auxiliary graph h
					// Add all the tree edges as vertices in h
					SimpleGraph h = new SimpleGraph();
					
					h.addAllVertices(treeEdges);
					
					visitedVertices.Clear();
					
					CSGraphT.SupportClass.SetSupport connected = new CSGraphT.SupportClass.HashSetSupport();
					
					for (System.Collections.IEnumerator it = dfsVertices.GetEnumerator(); it.MoveNext(); )
					{
						System.Object v = it.Current;
						
						visitedVertices.Add(v);
						
						// find all adjacent non-tree edges
						for (System.Collections.IEnumerator adjacentEdges = subgraph.edgesOf(v).GetEnumerator(); adjacentEdges.MoveNext();)
						{
							Edge l = (Edge)adjacentEdges.Current;
							if (!treeEdges.Contains(l))
							{
								h.addVertex(l);
								System.Object u = l.oppositeVertex(v);
								
								// we need to check if (u,v) is a back-edge
								if (!visitedVertices.Contains(u))
								{
									while (u != v)
									{
										System.Object pu = parent[u];
										Edge f = subgraph.getEdge(u, pu);
										
										h.addEdge(f, l);
										
										if (!connected.Contains(f))
										{
											connected.Add(f);
											u = pu;
										}
										else
										{
											u = v;
										}
									}
								}
							}
						}
					}
					
					ConnectivityInspector connectivityInspector = new ConnectivityInspector(h);
					
					biconnectedSets_Renamed_Field.Add(connectivityInspector.connectedSets());
				}
			}
			
			return biconnectedSets_Renamed_Field;
		}