Beispiel #1
0
        public static ProbablisticStateWrapper GetNextState(this IProbabilisticState probabilisticState)
        {
            var sumOfAllPossibilities = probabilisticState.GetNeighbors().Select(t => t.Item1).Sum();
            var num = GetRandomNumberUpTo(sumOfAllPossibilities);
            var sum = 0.0;

            foreach (var neighbor in probabilisticState.GetNeighbors())
            {
                sum += neighbor.Item1;
                if (sum >= num)
                {
                    return(new ProbablisticStateWrapper(neighbor.Item2, probabilisticState));
                }
            }

            return(null);
        }
Beispiel #2
0
        public SearchResult EvaluateChildren(IProbabilisticState startState, SearchContext searchContext)
        {
            var neighbors = startState.GetNeighbors().ToArray();

            if (!neighbors.Any())
            {
                var evaluation = startState.Evaluate(searchContext.CurrentDepth, searchContext.StatesUpTillNow, searchOptions);
                return(new SearchResult(evaluation, startState));
            }

            var storedStates = new ConcurrentDictionary <IState, double>();
            var results      = new List <Tuple <double, Task <SearchResult> > >();

            foreach (var neighbor in neighbors)
            {
                var wrappedState = new ProbablisticStateWrapper(neighbor.Item2, startState);
                var searchResult = threadManager.Invoke(() =>
                                                        deterministicSearchUtils.EvaluateChildren(wrappedState, searchContext.CloneWithMaxAlphaAndBeta(), storedStates), searchContext.CurrentDepth);
                results.Add(new Tuple <double, Task <SearchResult> >(neighbor.Item1, searchResult));
            }

            return(Reduce(results, startState));
        }
Beispiel #3
0
 public static void SetAsEndState(this IProbabilisticState state) =>
 A.CallTo(() => state.GetNeighbors()).Returns(new List <Tuple <double, IEnumerable <IState> > >());
Beispiel #4
0
 public ProbablisticStateWrapper(IEnumerable <IState> neighbors, IProbabilisticState innerState)
 {
     this.neighbors = neighbors;
     InnerState     = innerState;
 }