Class SearchAlgos


  • public class SearchAlgos
    extends Object
    Class with search methods.
    Author:
    Herbert Praehofer
    • Field Detail

      • nodesVisited

        public static int nodesVisited
    • Constructor Detail

      • SearchAlgos

        public SearchAlgos()
    • Method Detail

      • depthFirstSearch

        public static <N> Optional<N> depthFirstSearch​(Function<N,​List<N>> succFn,
                                                       Predicate<N> goalFn,
                                                       N start)
        Implements a depth-first search algorithm.
        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.
        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,
                                                      Function<N,​Integer> weightingFn,
                                                      Predicate<N> goalFn,
                                                      N start)
        Implements a best-first search algorithm.
        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.