Package at.jku.ssw.fp.sect04_3
Class SearchAlgosGeneric
- java.lang.Object
-
- at.jku.ssw.fp.sect04_3.SearchAlgosGeneric
-
public class SearchAlgosGeneric extends Object
Class implementing the generic version of the search algorithm.- Author:
- Herbert Praehofer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SearchAlgosGeneric.Controller<N,C extends Collection<N>>
The interface for the controller of the search algorithm.
-
Field Summary
Fields Modifier and Type Field Description static int
nodesVisited
-
Constructor Summary
Constructors Constructor Description SearchAlgosGeneric()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.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.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.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.
-
-
-
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 nodesC
- the type of the collection used in the search algorithm- Parameters:
controller
- the controller object for controlling the searchsuccessorFn
- the function for the successors nodes of a nodegoalFn
- the goal functionstart
- 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 functiongoalFn
- the goal functionstart
- 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 functiongoalFn
- the goal functionstart
- 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 functionweightingFn
- the function for ordering the nodesgoalFn
- the goal functionstart
- the start node- Returns:
- the found node in an optional, if exists, empty otherwise.
-
-