Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Returns a strategy to reach targets from a vertex.
        /// </summary>
        /// <param name="vertex"></param>
        /// <returns></returns>
        internal Strategy[] GetStrategyReachableFromVertex(int vertex)
        {
            Strategy [] strategies = this.GetStrategies();



            if (VertIsNondet(vertex))
            {
                throw new ArgumentException("vertex is a choice point");
            }

            //ArrayList links=new ArrayList();


            HSet linkSet = new HSet();

            foreach (Strategy s in strategies)
            {
                if (s.edge != null)
                {
                    linkSet.Insert(s.edge);

                    if (VertIsNondet(s.edge.target))
                    {
                        foreach (Edge l in graph.EdgesAtVertex(s.edge.target))
                        {
                            linkSet.Insert(l);
                        }
                    }
                }
            }



            BasicGraph bg = new BasicGraph(0, linkSet.ToArray(typeof(Edge)));

            bool [] reachables = bg.GetReachableArray(vertex);

            for (int i = 0; i < reachables.Length; i++)
            {
                if (reachables[i] == false)
                {
                    strategies[i].edge = null;
                }
            }


            return(strategies);
        }