aima.core.search.framework.PrioritySearch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
The newest version!
package aima.core.search.framework;
import java.util.Comparator;
import java.util.List;
import aima.core.agent.Action;
import aima.core.search.framework.problem.Problem;
import aima.core.search.framework.qsearch.QueueSearch;
/**
* Performs search by creating a priority queue based on a given
* Comparator
and feeding it to a given QueueSearch
* implementation which finally controls the simulated search space exploration.
*
* @author Ravi Mohan
* @author Ruediger Lunde
*/
public class PrioritySearch implements SearchForActions, SearchForStates {
private final QueueSearch implementation;
private final Comparator comparator;
public PrioritySearch(QueueSearch impl, Comparator comp) {
implementation = impl;
comparator = comp;
}
@Override
public List findActions(Problem p) {
implementation.getNodeExpander().useParentLinks(true);
Node node = implementation.findNode(p, QueueFactory.createPriorityQueue(comparator));
return node == null ? SearchUtils.failure() : SearchUtils.getSequenceOfActions(node);
}
@Override
public Object findState(Problem p) {
implementation.getNodeExpander().useParentLinks(false);
Node node = implementation.findNode(p, QueueFactory.createPriorityQueue(comparator));
return node == null ? null : node.getState();
}
public Comparator getComparator() {
return comparator;
}
@Override
public NodeExpander getNodeExpander() {
return implementation.getNodeExpander();
}
@Override
public Metrics getMetrics() {
return implementation.getMetrics();
}
}