Exemple #1
0
        //internal double[] GetDistancesToAcceptingStates(int[] sources,int[] acceptingStates)
        internal double[] GetDistancesToAcceptingStates(int[] acceptingStates)
        {
            if (MustEdges == null)
            {
                return(null);
            }


            //calculate distances from accepting states
            //by running shortest paths on the reversed graph
            Edge[] reversedEdges = new Edge[MustEdges.Length];

            for (int i = 0; i < reversedEdges.Length; i++)
            {
                Edge l = MustEdges[i];
                reversedEdges[i] = new Edge(l.target, l.source, l.label, l.weight);
            }

            BasicGraph basicGraph = new BasicGraph(0, reversedEdges);

            MultipleSourcesShortestPaths mssp = new MultipleSourcesShortestPaths(basicGraph, acceptingStates);

            mssp.Calculate();
            double[] exps = new double[NumberOfVertices];
            for (int i = 0; i < NumberOfVertices; i++)
            {
                exps[i] = mssp.GetDistTo(i);
            }


            return(exps);
        }
Exemple #2
0
        /// <summary>
        /// Calculates distances from graph vertices to some selected set of vertices; accepting states.
        /// </summary>
        /// <param name="acceptingStates"></param>
        /// <returns></returns>
        internal int[] GetDistanceToAcceptingStates(int[] acceptingStates)
        {
            if(MustEdges==null)
            return new int[0];

              //calculate distances from accepting states
              //by running shortest paths on the reversed graph
              Edge[] reversedEdges=new Edge[MustEdges.Length];

              for(int i=0;i<reversedEdges.Length;i++){
            Edge l=MustEdges[i];
            reversedEdges[i]=new Edge(l.target,l.source,l.label,l.weight);
              }

              BasicGraph basicGraph=new BasicGraph(0, reversedEdges);

              MultipleSourcesShortestPaths mssp=new MultipleSourcesShortestPaths(basicGraph,acceptingStates);

              mssp.Calculate();

              //now we have the distance from acceptingStates to any state in mssp.GetDistTo(state)

              int[] ret=new int[NumberOfVertices];

              for(int i=0;i<NumberOfVertices;i++)
                ret[i]=mssp.GetDistTo(i);

            return ret;
        }
Exemple #3
0
        //internal double[] GetDistancesToAcceptingStates(int[] sources,int[] acceptingStates)
        internal double[] GetDistancesToAcceptingStates(int[] acceptingStates)
        {
            if(MustEdges==null)
              return null;

              //calculate distances from accepting states
              //by running shortest paths on the reversed graph
              Edge[] reversedEdges=new Edge[MustEdges.Length];

              for(int i=0;i<reversedEdges.Length;i++){
            Edge l=MustEdges[i];
            reversedEdges[i]=new Edge(l.target,l.source,l.label,l.weight);
              }

              BasicGraph basicGraph=new BasicGraph(0, reversedEdges);

              MultipleSourcesShortestPaths mssp=new MultipleSourcesShortestPaths(basicGraph,acceptingStates);

              mssp.Calculate();
              double[] exps=new double[NumberOfVertices];
              for(int i=0;i<NumberOfVertices;i++)
              exps[i]=mssp.GetDistTo(i);

              return exps;
        }