public List <CandidateState> search(SortAlgorithmType pSortAlgorithmType = SortAlgorithmType.BSF) { List <ActionStateInterface> visited = new List <ActionStateInterface>(); CandidateState candidate = new CandidateState(this._initialState); List <CandidateState> pending = new List <CandidateState>() { candidate }; int i = 0; while (pending.Any()) { candidate = pSortAlgorithmType == SortAlgorithmType.DSF ? pending.Pop() : pending.Shift(); i++; if (i % 1000 == 0) { Console.WriteLine(i); } if (this._finalState.Any(state => state.Equals(candidate.ActionState))) { List <CandidateState> result = new List <CandidateState>(); while (candidate != null) { result.Add(candidate); candidate = candidate.ParentCandidateState; } result.Reverse(); return(result); } else { visited.Add(candidate.ActionState); List <CandidateState> successors = candidate.getSuccessors(); foreach (CandidateState successor in successors) { if (!visited.Any(state => state.Equals(successor.ActionState))) { pending.Add(successor); } } } } return(null); }
public List <CandidateState> getSuccessors() { List <string> list = this._actionsState.getAction(); List <CandidateState> successors = new List <CandidateState>(); foreach (string action in list) { ActionStateInterface state = this._actionsState.doAction(action); CandidateState successor = new CandidateState(state, this, action); this._ChildrenStates.Add(successor); successors.Add(successor); } return(successors); }
public CandidateState(ActionStateInterface pActionState, CandidateState pParentCandidateStatus = null, string pCurrentAction = null) { this._actionsState = pActionState; this._action = pCurrentAction; this._parentActionState = pParentCandidateStatus; }