public SearchProblem(IGoalTest <S> goalTest, IStepCostFunction <A, S, C> stepCost, ISuccessorFunction <A, S> successor, IHeuristicFunction <S, C> heuristicFn) { this.goalTest = goalTest; this.stepCost = stepCost; this.successorFn = successor; this.heuristicFn = heuristicFn; }
public Node FindSolution(IState initialConfiguration, IGoalTest goalTest) { HashSet <IState> explored = new HashSet <IState>(); frontier.Add(new Node(null, null, initialConfiguration)); while (!frontier.IsEmpty()) { Node node = frontier.Remove(); if (goalTest.IsGoal(node.State)) { return(node); } else { explored.Add(node.State); foreach (IAction action in node.State.GetApplicableActions()) { IState newState = node.State.GetActionResult(action); Node newNode = new Node(node, action, newState); if (!explored.Contains(newState) && !frontier.Contains(newNode)) { frontier.Add(newNode); } } } } return(null); }
public OnlineSearchProblem(IActionsFunction actionsFunction, IGoalTest goalTest, IStepCostFunction stepCostFunction) { this.ActionsFunction = actionsFunction; this.GoalTest = goalTest; this.StepCostFunction = stepCostFunction; }
public Problem(object initialState, IActionsFunction actionsFunction, IResultFunction resultFunction, IGoalTest goalTest, IStepCostFunction stepCostFunction) { this.InitialState = initialState; this.ActionsFunction = actionsFunction; this.ResultFunction = resultFunction; this.GoalTest = goalTest; this.StepCostFunction = stepCostFunction; }
public Problem( string initialState, MoveToActionsFunction actionsFunction, IResultFunction resultFunction, IGoalTest goalTest, IStepCostFunction stepCostFunction ) { m_initialState = initialState; m_actionsFunction = actionsFunction; m_resultFunction = resultFunction; m_goalTest = goalTest; m_stepCostFunction = stepCostFunction; }
public static bool IsGoalState(Problem p, Node n) { bool isGoal = false; IGoalTest gt = p.GoalTest; if (gt.IsGoalState(n.State)) { if (gt is ISolutionChecker) { isGoal = ((ISolutionChecker)gt).IsAcceptableSolution(ActionsFromNodes(n.GetPathFromRoot()), n.State); } else { isGoal = true; } } return(isGoal); }
// function GENETIC-ALGORITHM(population, FITNESS-FN) returns an individual // inputs: population, a Set of individuals // FITNESS-FN, a function that measures the fitness of an individual public string GetBestIndividual(ISet <string> population, IFitnessFunction fitnessFn, IGoalTest goalTest) { string bestIndividual = null; this.ValidatePopulation(population); this.ClearInstrumentation(); this.SetPopulationSize(population.Count); // repeat int cnt = 0; do { bestIndividual = this.Ga(population, fitnessFn); cnt++; // until some individual is fit enough, or enough time has elapsed } while (!goalTest.IsGoalState(bestIndividual)); this.SetIterations(cnt); // return the best individual in population, according to FITNESS-FN return(bestIndividual); }
private bool IsGoalState( string state, IGoalTest goalTest ) { return goalTest.IsGoalState( state ); }
public Problem(object initialState, IActionsFunction actionsFunction, IResultFunction resultFunction, IGoalTest goalTest) : this(initialState, actionsFunction, resultFunction, goalTest, new DefaultStepCostFunction()) { }
public SearchProblem(IGoalTest <S> goalTest, IStepCostFunction <A, S, C> stepCost, ISuccessorFunction <A, S> successor) : this(goalTest, stepCost, successor, null) { }
public OnlineSearchProblem(IActionsFunction actionsFunction, IGoalTest goalTest) : this(actionsFunction, goalTest, new DefaultStepCostFunction()) { }