Esempio n. 1
0
        public bool JonhsonFATSPAlgorithm()
        {
            AuxiliaryGraph.AddNode(new Node(AuxiliaryGraph.QuantityOfNodes, "Temporary"));

            for (int Index = 0; Index < AuxiliaryGraph.QuantityOfNodes - 1; Index++)
            {
                AuxiliaryGraph.AddTwoWayEdge(new Edge(0, AuxiliaryGraph.SetOfNodes[AuxiliaryGraph.QuantityOfNodes - 1], AuxiliaryGraph.SetOfNodes[Index]));
            }

            BellmanFordPathSearch = new BellmanFordAlgorithm(AuxiliaryGraph);

            if (BellmanFordPathSearch.BellmanFordShortestPathSearchAlgorithm(AuxiliaryGraph.SetOfNodes[AuxiliaryGraph.QuantityOfNodes - 1]))
            {
                for (int FirstIndex = 0; FirstIndex < InnerGraph.QuantityOfNodes; FirstIndex++)
                {
                    DijkstraPathSearch = new DijkstraAlgorithm(InnerGraph);

                    DijkstraPathSearch.DijkstraSWSAlgorithm(InnerGraph.SetOfNodes[FirstIndex]);

                    for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                    {
                        MatrixOfTheShortesPathes[FirstIndex, SecondIndex] = DijkstraPathSearch.ShortestPath[SecondIndex].Weight;
                    }
                }

                return(true);
            }
            else
            {
                for (int Index = 0; Index < InnerGraph.QuantityOfEdges; Index++)
                {
                    InnerGraph.SetOfEdges[Index].Weight =
                        InnerGraph.SetOfEdges[Index].Weight +
                        BellmanFordPathSearch.ShortestPath[InnerGraph.SetOfEdges[Index][0].Index].Weight -
                        BellmanFordPathSearch.ShortestPath[InnerGraph.SetOfEdges[Index][1].Index].Weight;
                }

                for (int FirstIndex = 0; FirstIndex < InnerGraph.QuantityOfNodes; FirstIndex++)
                {
                    DijkstraPathSearch = new DijkstraAlgorithm(InnerGraph);

                    DijkstraPathSearch.DijkstraSWSAlgorithm(InnerGraph.SetOfNodes[FirstIndex]);

                    for (int SecondIndex = 0; SecondIndex < InnerGraph.QuantityOfNodes; SecondIndex++)
                    {
                        MatrixOfTheShortesPathes[FirstIndex, SecondIndex] = DijkstraPathSearch.ShortestPath[SecondIndex].Weight;
                    }
                }
            }

            return(true);
        }
        public virtual System.Collections.IDictionary relevantCycles()
        {
            //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 result = new System.Collections.Hashtable();

            bool[][] a = getCycleEdgeIncidenceMatrix();

            bool[][] ai = inverseBinaryMatrix(a, cycles_Renamed_Field.Count);

            for (int i = 0; i < cycles_Renamed_Field.Count; i++)
            {

                // Construct kernel vector u from a column of the inverse of a
                bool[] u = new bool[edgeList.Count];
                for (int j = 0; j < cycles_Renamed_Field.Count; j++)
                {
                    u[j] = ai[j][i];
                }

                // Construct auxiliary graph gu
                AuxiliaryGraph gu = new AuxiliaryGraph(this, graph, u);

                System.Collections.IEnumerator vertexIterator = graph.vertexSet().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 (vertexIterator.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 vertex = vertexIterator.Current;

                    System.Collections.ICollection incidentEdges = graph.edgesOf(vertex);

                    // check if the vertex is incident to an edge with u[edge] == 1
                    bool shouldSearchCycle = false;

                    //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 it = incidentEdges.GetEnumerator(); it.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)it.Current;
                        int index = getEdgeIndex(edge);
                        if (u[index])
                        {
                            shouldSearchCycle = true;
                            break;
                        }
                    }

                    if (shouldSearchCycle)
                    {

                        System.Object auxVertex0 = gu.auxVertex0(vertex);
                        System.Object auxVertex1 = gu.auxVertex1(vertex);

                        // Search for shortest paths

                        //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 minPaths = new MinimalPathIterator(gu, auxVertex0, auxVertex1); minPaths.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.Collections.IList auxPath = (System.Collections.IList)minPaths.Current;
                            System.Collections.IList edgesOfNewCycle = new System.Collections.ArrayList(auxPath.Count);

                            System.Collections.IEnumerator edgeIterator = auxPath.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 (edgeIterator.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 auxEdge = (Edge)edgeIterator.Current;

                                // Get the edge corresponding to the aux. edge
                                Edge e = (Edge)gu.edge(auxEdge);

                                edgesOfNewCycle.Add(e);
                            }


                            SimpleCycle cycle = new SimpleCycle(graph, edgesOfNewCycle);

                            if (cycle.weight() > ((SimpleCycle)cycles_Renamed_Field[i]).weight())
                            {
                                break;
                            }

                            result[cycle] = (SimpleCycle)cycles_Renamed_Field[i];
                        }
                    }
                }
            }

            return result;
        }
        //	private void minimize() {
        //		
        //		if (isMinimized) 
        //			return;
        //		
        //		if (cycles.size()==0) 
        //			return;
        //		else 
        //			minimize(0);
        //		
        //		isMinimized = true;
        //	}

        private void minimize(int startIndex)
        {

            if (isMinimized)
                return;

            // Implementation of "Algorithm 1" from [BGdV04]

            bool[][] a = getCycleEdgeIncidenceMatrix();

            for (int i = startIndex; i < cycles_Renamed_Field.Count; i++)
            {
                // "Subroutine 2"

                // Construct kernel vector u
                bool[] u = constructKernelVector(edgeList.Count, a, i);

                // Construct auxiliary graph gu
                AuxiliaryGraph gu = new AuxiliaryGraph(this, graph, u);

                SimpleCycle shortestCycle = (SimpleCycle)cycles_Renamed_Field[i];

                System.Collections.IEnumerator vertexIterator = graph.vertexSet().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 (vertexIterator.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 vertex = vertexIterator.Current;

                    // check if the vertex is incident to an edge with u[edge] == 1
                    bool shouldSearchCycle = false;

                    System.Collections.ICollection incidentEdges = graph.edgesOf(vertex);

                    System.Collections.IEnumerator edgeIterator = incidentEdges.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 (edgeIterator.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)edgeIterator.Current;
                        int index = getEdgeIndex(edge);
                        if (u[index])
                        {
                            shouldSearchCycle = true;
                            break;
                        }
                    }

                    if (shouldSearchCycle)
                    {

                        System.Object auxVertex0 = gu.auxVertex0(vertex);
                        System.Object auxVertex1 = gu.auxVertex1(vertex);

                        // Search for shortest path

                        System.Collections.IList auxPath = BFSShortestPath.findPathBetween(gu, auxVertex0, auxVertex1);

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

                        System.Object v = vertex;

                        edgeIterator = auxPath.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 (edgeIterator.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 auxEdge = (Edge)edgeIterator.Current;

                            // Get the edge corresponding to the aux. edge
                            Edge e = (Edge)gu.edge(auxEdge);

                            edgesOfNewCycle.Add(e);

                            // Get next vertex on path
                            v = e.oppositeVertex(v);
                        }

                        SimpleCycle newCycle = new SimpleCycle(graph, edgesOfNewCycle);

                        if (newCycle.weight() < shortestCycle.weight())
                        {
                            shortestCycle = newCycle;
                        }
                    }
                }

                cycles_Renamed_Field[i] = shortestCycle;

                // insert the new cycle into the matrix
                for (int j = 1; j < edgeList.Count; j++)
                {
                    a[i][j] = shortestCycle.containsEdge((Edge)edgeList[j]);
                }

                // perform gaussian elimination on the inserted row
                for (int j = 0; j < i; j++)
                {
                    if (a[i][j])
                    {
                        for (int k = 0; k < edgeList.Count; k++)
                        {
                            a[i][k] = (a[i][k] != a[j][k]);
                        }
                    }
                }
            }

            isMinimized = true;
        }