Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
        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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        // 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);
        }
Ejemplo n.º 8
0
 private bool IsGoalState( string state, IGoalTest goalTest )
 {
     return goalTest.IsGoalState( state );
 }
Ejemplo n.º 9
0
 public Problem(object initialState, IActionsFunction actionsFunction,
                IResultFunction resultFunction, IGoalTest goalTest)
     : this(initialState, actionsFunction, resultFunction, goalTest,
            new DefaultStepCostFunction())
 {
 }
Ejemplo n.º 10
0
 public SearchProblem(IGoalTest <S> goalTest, IStepCostFunction <A, S, C> stepCost, ISuccessorFunction <A, S> successor)
     : this(goalTest, stepCost, successor, null)
 {
 }
Ejemplo n.º 11
0
 public OnlineSearchProblem(IActionsFunction actionsFunction, IGoalTest goalTest)
     : this(actionsFunction, goalTest, new DefaultStepCostFunction())
 {
 }