/** * Calls the goal test of the problem and - if the goal test is effectively * a {@link SolutionChecker} - additionally checks, whether the solution is * acceptable. Solution checkers can be used to analyze several or all * solutions with only one search run. */ public static bool isGoalState(Problem p, Node n) { bool isGoal = false; GoalTest gt = p.getGoalTest(); if (gt.isGoalState(n.State)) { if (gt is SolutionChecker) { isGoal = ((SolutionChecker)gt).isAcceptableSolution( getSequenceOfActions(n), n.State); } else { isGoal = true; } } return(isGoal); }
public static bool isGoalState(Problem p, Node n) { bool isGoal = false; GoalTest gt = p.getGoalTest(); if (gt.isGoalState(n.getState())) { if (gt is SolutionChecker) { isGoal = ((SolutionChecker)gt).isAcceptableSolution( SearchUtils.actionsFromNodes(n.getPathFromRoot()), n .getState()); } 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 geneticAlgorithm(Set<String> population, FitnessFunction fitnessFn, GoalTest goalTest) { String bestIndividual = null; validatePopulation(population); clearInstrumentation(); setPopulationSize(population.Count); // repeat int cnt = 0; do { bestIndividual = ga(population, fitnessFn); cnt++; // until some individual is fit enough, or enough time has elapsed } while (!goalTest.isGoalState(bestIndividual)); setIterations(cnt); // return the best individual in population, according to FITNESS-FN return bestIndividual; }
// 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 geneticAlgorithm(Set <String> population, FitnessFunction fitnessFn, GoalTest goalTest) { String bestIndividual = null; validatePopulation(population); clearInstrumentation(); setPopulationSize(population.Count); // repeat int cnt = 0; do { bestIndividual = ga(population, fitnessFn); cnt++; // until some individual is fit enough, or enough time has elapsed } while (!goalTest.isGoalState(bestIndividual)); setIterations(cnt); // return the best individual in population, according to FITNESS-FN return(bestIndividual); }
/** * Returns <code>true</code> if the given state is a goal state. * * @param state * an object representing a state * * @return <code>true</code> if the given state is a goal state. */ public bool isGoalState(Object state) { return(goalTest.isGoalState(state)); }