|
1 | 1 | package jaicore.search.algorithms.standard.bestfirst; |
2 | 2 |
|
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.Map; |
| 5 | + |
| 6 | +import jaicore.logging.ToJSONStringUtil; |
3 | 7 | import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.AlternativeNodeEvaluator; |
4 | 8 | import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.INodeEvaluator; |
5 | 9 | import jaicore.search.core.interfaces.GraphGenerator; |
6 | 10 | import jaicore.search.probleminputs.GraphSearchWithSubpathEvaluationsInput; |
7 | 11 |
|
8 | 12 | public class StandardBestFirstFactory<N, A, V extends Comparable<V>> extends BestFirstFactory<GraphSearchWithSubpathEvaluationsInput<N, A, V>, N, A, V> { |
9 | | - |
| 13 | + |
10 | 14 | private INodeEvaluator<N, V> preferredNodeEvaluator; |
11 | | - |
12 | | - public void setNodeEvaluator(INodeEvaluator<N, V> nodeEvaluator) { |
13 | | - setProblemInput(new GraphSearchWithSubpathEvaluationsInput<>(getInput() != null ? getInput().getGraphGenerator() : null, nodeEvaluator)); |
| 15 | + |
| 16 | + public void setNodeEvaluator(final INodeEvaluator<N, V> nodeEvaluator) { |
| 17 | + this.setProblemInput(new GraphSearchWithSubpathEvaluationsInput<>(this.getInput() != null ? this.getInput().getGraphGenerator() : null, nodeEvaluator)); |
14 | 18 | } |
15 | 19 |
|
16 | | - public void setGraphGenerator(GraphGenerator<N, A> graphGenerator) { |
17 | | - setProblemInput(new GraphSearchWithSubpathEvaluationsInput<>(graphGenerator, getInput() != null ? getInput().getNodeEvaluator() : null)); |
| 20 | + public void setGraphGenerator(final GraphGenerator<N, A> graphGenerator) { |
| 21 | + this.setProblemInput(new GraphSearchWithSubpathEvaluationsInput<>(graphGenerator, this.getInput() != null ? this.getInput().getNodeEvaluator() : null)); |
18 | 22 | } |
19 | 23 |
|
20 | 24 | public INodeEvaluator<N, V> getPreferredNodeEvaluator() { |
21 | | - return preferredNodeEvaluator; |
| 25 | + return this.preferredNodeEvaluator; |
22 | 26 | } |
23 | 27 |
|
24 | | - public void setPreferredNodeEvaluator(INodeEvaluator<N, V> preferredNodeEvaluator) { |
| 28 | + public void setPreferredNodeEvaluator(final INodeEvaluator<N, V> preferredNodeEvaluator) { |
25 | 29 | this.preferredNodeEvaluator = preferredNodeEvaluator; |
26 | 30 | } |
27 | | - |
| 31 | + |
28 | 32 | @Override |
29 | 33 | public BestFirst<GraphSearchWithSubpathEvaluationsInput<N, A, V>, N, A, V> getAlgorithm() { |
30 | | - if (getInput().getGraphGenerator() == null) |
| 34 | + if (this.getInput().getGraphGenerator() == null) { |
31 | 35 | throw new IllegalStateException("Cannot produce BestFirst searches before the graph generator is set in the problem."); |
32 | | - if (getInput().getNodeEvaluator() == null) |
| 36 | + } |
| 37 | + if (this.getInput().getNodeEvaluator() == null) { |
33 | 38 | throw new IllegalStateException("Cannot produce BestFirst searches before the node evaluator is set."); |
34 | | - |
| 39 | + } |
| 40 | + |
35 | 41 | /* determine search problem */ |
36 | | - GraphSearchWithSubpathEvaluationsInput<N, A, V> problem = getInput(); |
37 | | - if (preferredNodeEvaluator != null) { |
38 | | - problem = new GraphSearchWithSubpathEvaluationsInput<N, A, V>(problem.getGraphGenerator(), new AlternativeNodeEvaluator<>(preferredNodeEvaluator, problem.getNodeEvaluator())); |
| 42 | + GraphSearchWithSubpathEvaluationsInput<N, A, V> problem = this.getInput(); |
| 43 | + if (this.preferredNodeEvaluator != null) { |
| 44 | + problem = new GraphSearchWithSubpathEvaluationsInput<N, A, V>(problem.getGraphGenerator(), new AlternativeNodeEvaluator<>(this.preferredNodeEvaluator, problem.getNodeEvaluator())); |
39 | 45 | } |
40 | 46 | BestFirst<GraphSearchWithSubpathEvaluationsInput<N, A, V>, N, A, V> search = new BestFirst<>(problem); |
41 | | - search.setTimeoutForComputationOfF(getTimeoutForFInMS(), getTimeoutEvaluator()); |
42 | | - if (getLoggerName() != null && getLoggerName().length() > 0) |
43 | | - search.setLoggerName(getLoggerName()); |
| 47 | + search.setTimeoutForComputationOfF(this.getTimeoutForFInMS(), this.getTimeoutEvaluator()); |
| 48 | + if (this.getLoggerName() != null && this.getLoggerName().length() > 0) { |
| 49 | + search.setLoggerName(this.getLoggerName()); |
| 50 | + } |
44 | 51 | return search; |
45 | 52 | } |
| 53 | + |
| 54 | + @Override |
| 55 | + public String toString() { |
| 56 | + Map<String, Object> fields = new HashMap<>(); |
| 57 | + fields.put("preferredNodeEvaluator", this.preferredNodeEvaluator); |
| 58 | + return ToJSONStringUtil.toJSONString(this.getClass().getSimpleName(), fields); |
| 59 | + } |
46 | 60 | } |
0 commit comments