Class SearchAlgosGeneric


  • public class SearchAlgosGeneric
    extends Object
    Class implementing the generic version of the search algorithm.
    Author:
    Herbert Praehofer
    • Field Detail

      • nodesVisited

        public static int nodesVisited
    • Constructor Detail

      • SearchAlgosGeneric

        public SearchAlgosGeneric()
    • Method Detail

      • search

        public static <N,​C extends Collection<N>> Optional<N> search​(SearchAlgosGeneric.Controller<N,​C> controller,
                                                                           Function<N,​List<N>> successorFn,
                                                                           Predicate<N> goalFn,
                                                                           N start)
        Implements a generic search algorithm.
        Type Parameters:
        N - the type of the nodes
        C - the type of the collection used in the search algorithm
        Parameters:
        controller - the controller object for controlling the search
        successorFn - the function for the successors nodes of a node
        goalFn - the goal function
        start - the start node
        Returns:
        the found node in an optional, if exists, empty otherwise.
      • depthFirstSearch

        public static <N> Optional<N> depthFirstSearch​(Function<N,​List<N>> succFn,
                                                       Predicate<N> goalFn,
                                                       N start)
        Implements a depth-first search algorithm by the generic algorithm using a special controller.
        Type Parameters:
        N - the type of nodes
        Parameters:
        succFn - the successor function
        goalFn - the goal function
        start - the start node
        Returns:
        the found node in an optional, if exists, empty otherwise.
      • breadthFirstSearch

        public static <N> Optional<N> breadthFirstSearch​(Function<N,​List<N>> succFn,
                                                         Predicate<N> goalFn,
                                                         N start)
        Implements a breadth-first search algorithm by the generic algorithm using a special controller.
        Type Parameters:
        N - the type of nodes
        Parameters:
        succFn - the successor function
        goalFn - the goal function
        start - the start node
        Returns:
        the found node in an optional, if exists, empty otherwise.
      • bestFirstSearch

        public static <N> Optional<N> bestFirstSearch​(Function<N,​List<N>> succFn,
                                                      ToIntFunction<N> weightingFn,
                                                      Predicate<N> goalFn,
                                                      N start)
        Implements a best-first search algorithm by the generic algorithm using a special controller.
        Type Parameters:
        N - the type of nodes
        Parameters:
        succFn - the successor function
        weightingFn - the function for ordering the nodes
        goalFn - the goal function
        start - the start node
        Returns:
        the found node in an optional, if exists, empty otherwise.