/// <summary> /// Branches the specified searchable. /// </summary> /// <param name="searchable">The searchable.</param> /// <returns> /// a Search States Tree /// </returns> public TreeSearchResult <T> Branch(ISearchable <T> searchable) { TreeSearchResult <T> result = new TreeSearchResult <T>(searchable.GetInitialState()); // closed list - HashSet HashSet <State <T> > visited = new HashSet <State <T> >(); // opened list - RandomList RandomList <State <T> > pending = new RandomList <State <T> >(); pending.RandomInsert(searchable.GetInitialState()); while (pending.Count > 0) { State <T> currState = pending.RandomRemoval(); if (!visited.Contains(currState)) { foreach (State <T> state in searchable.GetReachableStatesFrom(currState)) { if (!visited.Contains(state)) { if (!pending.Contains(state)) { // found a brand new State pending.RandomInsert(state); result.Add(state, currState); } else if (this.RandomBool()) { // change the father of state in the tree result.RemoveLeaf(state); result.Add(state, currState); } } } visited.Add(currState); } } return(result); }