Beispiel #1
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));
        }
        public void Search_CheckThatRecordPassThroughStatesIsWorking(int degreeOfParallelism, ParallelismMode parallelismMode)
        {
            A.CallTo(() => evaluation2State.Evaluate(A <int> ._, A <List <IState> > .That.IsEmpty()))
            .Throws(new Exception("passedStats list should have been empty"));
            A.CallTo(() => evaluationNagitive2State.Evaluate(A <int> ._, A <List <IState> > ._))
            .Invokes((int i, List <IState> l) =>
            {
                Assert.AreEqual(2, l.Count, "passThroughStates should have two states in it (startState and probabilisticState1)");
                Assert.IsTrue(l.Contains(probabilisticState1), "passThroughStates should contain" + nameof(probabilisticState1));
            });

            startState.SetNeigbor(probabilisticState1);
            A.CallTo(() => probabilisticState1.GetNeighbors()).Returns(new List <Tuple <double, IEnumerable <IState> > >()
            {
                new Tuple <double, IEnumerable <IState> >(1, new List <IState> {
                    evaluation2State, evaluationNagitive2State
                })
            });

            var searchEngine = TestUtils.GetBasicSearchEngine(parallelismMode, degreeOfParallelism);

            searchEngine.Search(startState, 5);
        }