示例#1
0
        private List <string> searchForNode(Graph g, MarkovNode <string> start, List <MarkovNode <string> > visited, string prefix2 = "", string prefix = "")
        {
            List <string> res = new List <string>();

            foreach (var f in start.GetNexts())
            {
                if (string.IsNullOrEmpty(f.Value))
                {
                    continue;
                }
                if (visited.Contains(f))
                {
                    continue;
                }

                if (start.State != MarkovState.Start)
                {
                    AddToGraph(g, start.Value, f.Value);
                }

                res.Add(prefix + f.Value);

                visited.Add(f);
                res.AddRange(searchForNode(g, f, new List <MarkovNode <string> >(visited), prefix2, prefix + prefix2));
                visited.Remove(f);
            }
            return(res);
        }
示例#2
0
        private double searchForNode(MarkovNode <T> start, MarkovNode <T> end, List <MarkovNode <T> > visited)
        {
            //
            // this method gave incorrect result
            // check it later
            //

            double pro = 0;

            foreach (var f in start.GetNexts())
            {
                if (visited.Contains(f))
                {
                    continue;
                }

                visited.Add(f);

                if (f == end)
                {
                    pro = 1;
                    for (int i = 0; i < visited.Count - 1; i++)
                    {
                        pro *= visited[i].ProbabilityOf(visited[i + 1]);
                    }
                    return(pro);
                }
                else
                {
                    pro += searchForNode(f, end, new List <MarkovNode <T> >(visited));
                }
                visited.Remove(f);
            }
            return(pro);
        }