Skip to content

Commit 51a25b0

Browse files
authored
Merge pull request #68 from fmohr/bug/hasco/preferredNodeEvaluator
Fixed problem of vanishing preferred node evaluator.
2 parents 146c5a7 + 2c96330 commit 51a25b0

4 files changed

Lines changed: 54 additions & 32 deletions

File tree

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
package jaicore.search.algorithms.standard.bestfirst;
22

3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import jaicore.logging.ToJSONStringUtil;
37
import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.AlternativeNodeEvaluator;
48
import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.INodeEvaluator;
59
import jaicore.search.core.interfaces.GraphGenerator;
610
import jaicore.search.probleminputs.GraphSearchWithSubpathEvaluationsInput;
711

812
public class StandardBestFirstFactory<N, A, V extends Comparable<V>> extends BestFirstFactory<GraphSearchWithSubpathEvaluationsInput<N, A, V>, N, A, V> {
9-
13+
1014
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));
1418
}
1519

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));
1822
}
1923

2024
public INodeEvaluator<N, V> getPreferredNodeEvaluator() {
21-
return preferredNodeEvaluator;
25+
return this.preferredNodeEvaluator;
2226
}
2327

24-
public void setPreferredNodeEvaluator(INodeEvaluator<N, V> preferredNodeEvaluator) {
28+
public void setPreferredNodeEvaluator(final INodeEvaluator<N, V> preferredNodeEvaluator) {
2529
this.preferredNodeEvaluator = preferredNodeEvaluator;
2630
}
27-
31+
2832
@Override
2933
public BestFirst<GraphSearchWithSubpathEvaluationsInput<N, A, V>, N, A, V> getAlgorithm() {
30-
if (getInput().getGraphGenerator() == null)
34+
if (this.getInput().getGraphGenerator() == null) {
3135
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) {
3338
throw new IllegalStateException("Cannot produce BestFirst searches before the node evaluator is set.");
34-
39+
}
40+
3541
/* 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()));
3945
}
4046
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+
}
4451
return search;
4552
}
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+
}
4660
}

JAICore/jaicore-search/src/main/java/jaicore/search/problemtransformers/GraphSearchProblemInputToGraphSearchWithSubpathEvaluationInputTransformerViaRDFS.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Random;
44
import java.util.function.Predicate;
55

6+
import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.AlternativeNodeEvaluator;
67
import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.INodeEvaluator;
78
import jaicore.search.algorithms.standard.bestfirst.nodeevaluation.RandomCompletionBasedNodeEvaluator;
89
import jaicore.search.probleminputs.GraphSearchWithPathEvaluationsInput;
@@ -17,7 +18,8 @@ public class GraphSearchProblemInputToGraphSearchWithSubpathEvaluationInputTrans
1718
private final int timeoutForSingleCompletionEvaluationInMS;
1819
private final int timeoutForNodeEvaluationInMS;
1920

20-
public GraphSearchProblemInputToGraphSearchWithSubpathEvaluationInputTransformerViaRDFS(INodeEvaluator<N, V> preferredNodeEvaluator, Predicate<N> preferredNodeEvaluatorForRandomCompletion, int seed, int numSamples, int timeoutForSingleCompletionEvaluationInMS, int timeoutForNodeEvaluationInMS) {
21+
public GraphSearchProblemInputToGraphSearchWithSubpathEvaluationInputTransformerViaRDFS(final INodeEvaluator<N, V> preferredNodeEvaluator, final Predicate<N> preferredNodeEvaluatorForRandomCompletion, final int seed,
22+
final int numSamples, final int timeoutForSingleCompletionEvaluationInMS, final int timeoutForNodeEvaluationInMS) {
2123
super();
2224
if (numSamples <= 0) {
2325
throw new IllegalArgumentException("Sample size has been set to " + numSamples + " but must be strictly positive!");
@@ -31,24 +33,30 @@ public GraphSearchProblemInputToGraphSearchWithSubpathEvaluationInputTransformer
3133
}
3234

3335
public INodeEvaluator<N, V> getPreferredNodeEvaluator() {
34-
return preferredNodeEvaluator;
36+
return this.preferredNodeEvaluator;
3537
}
3638

3739
public Predicate<N> getPrioritizedNodePredicatesForRandomCompletion() {
38-
return prioritizedNodesInRandomCompletion;
40+
return this.prioritizedNodesInRandomCompletion;
3941
}
4042

4143
public int getSeed() {
42-
return seed;
44+
return this.seed;
4345
}
4446

4547
public int getNumSamples() {
46-
return numSamples;
48+
return this.numSamples;
4749
}
4850

4951
@Override
50-
public GraphSearchWithSubpathEvaluationsInput<N, A, V> transform(GraphSearchWithPathEvaluationsInput<N, A, V> problem) {
51-
setNodeEvaluator(new RandomCompletionBasedNodeEvaluator<>(new Random(seed), numSamples, problem.getPathEvaluator(), timeoutForSingleCompletionEvaluationInMS, timeoutForNodeEvaluationInMS, prioritizedNodesInRandomCompletion));
52+
public GraphSearchWithSubpathEvaluationsInput<N, A, V> transform(final GraphSearchWithPathEvaluationsInput<N, A, V> problem) {
53+
RandomCompletionBasedNodeEvaluator<N, V> rdfsNodeEvaluator = new RandomCompletionBasedNodeEvaluator<>(new Random(this.seed), this.numSamples, problem.getPathEvaluator(), this.timeoutForSingleCompletionEvaluationInMS,
54+
this.timeoutForNodeEvaluationInMS, this.prioritizedNodesInRandomCompletion);
55+
if (this.preferredNodeEvaluator != null) {
56+
this.setNodeEvaluator(new AlternativeNodeEvaluator<>(this.preferredNodeEvaluator, rdfsNodeEvaluator));
57+
} else {
58+
this.setNodeEvaluator(rdfsNodeEvaluator);
59+
}
5260
return super.transform(problem);
5361
}
5462

softwareconfiguration/hasco/src/examples/java/hasco/examples/HASCOModelStatisticsObserverPluginExample.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414
import jaicore.basic.algorithm.exceptions.AlgorithmException;
1515
import jaicore.graphvisualizer.plugin.graphview.GraphViewPlugin;
1616
import jaicore.graphvisualizer.plugin.nodeinfo.NodeInfoGUIPlugin;
17-
import jaicore.graphvisualizer.window.GraphVisualizationWindow;
17+
import jaicore.graphvisualizer.window.AlgorithmVisualizationWindow;
1818
import jaicore.planning.hierarchical.algorithms.forwarddecomposition.graphgenerators.tfd.TFDNodeInfoGenerator;
1919
import jaicore.search.model.travesaltree.JaicoreNodeInfoGenerator;
2020
import javafx.application.Platform;
2121
import javafx.embed.swing.JFXPanel;
2222

2323
public class HASCOModelStatisticsObserverPluginExample {
24-
public static void main(String[] args) throws UnresolvableRequiredInterfaceException, IOException, InterruptedException, AlgorithmExecutionCanceledException, TimeoutException, AlgorithmException {
24+
public static void main(final String[] args) throws UnresolvableRequiredInterfaceException, IOException, InterruptedException, AlgorithmExecutionCanceledException, TimeoutException, AlgorithmException {
2525
HASCOViaFDAndBestFirstFactory<Double> hascoFactory = new HASCOViaFDAndBestFirstFactory<>(n -> 0.0);
2626
Random r = new Random();
27-
// hascoFactory.setProblemInput(new RefinementConfiguredSoftwareConfigurationProblem<>(new File("testrsc/simpleproblemwithtwocomponents.json"), "IFace", n -> System.currentTimeMillis() * 1.0));
27+
// hascoFactory.setProblemInput(new RefinementConfiguredSoftwareConfigurationProblem<>(new File("testrsc/simpleproblemwithtwocomponents.json"), "IFace", n -> System.currentTimeMillis() * 1.0));
2828
hascoFactory.setProblemInput(new RefinementConfiguredSoftwareConfigurationProblem<>(new File("testrsc/mediumrecursiveproblem.json"), "IFace", n -> r.nextDouble()));
2929
HASCOViaFDAndBestFirst<Double> hasco = hascoFactory.getAlgorithm();
3030
hasco.setNumCPUs(1);
3131
new JFXPanel();
32-
Platform.runLater(new GraphVisualizationWindow(hasco, new GraphViewPlugin(), new NodeInfoGUIPlugin<>(new JaicoreNodeInfoGenerator<>(new TFDNodeInfoGenerator())), new HASCOModelStatisticsPlugin()));
32+
Platform.runLater(new AlgorithmVisualizationWindow(hasco, new GraphViewPlugin(), new NodeInfoGUIPlugin<>(new JaicoreNodeInfoGenerator<>(new TFDNodeInfoGenerator())), new HASCOModelStatisticsPlugin()));
3333
hasco.call();
3434
}
3535
}
36-

softwareconfiguration/mlplan/src/examples/java/de/upb/crc901/mlplan/examples/MLPlanARFFExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import java.io.FileReader;
55
import java.util.List;
66
import java.util.NoSuchElementException;
7-
import java.util.Timer;
87
import java.util.concurrent.TimeUnit;
98

109
import de.upb.crc901.mlplan.core.MLPlan;
1110
import de.upb.crc901.mlplan.core.MLPlanBuilder;
1211
import de.upb.crc901.mlplan.gui.outofsampleplots.OutOfSampleErrorPlotPlugin;
1312
import de.upb.crc901.mlplan.multiclass.wekamlplan.weka.model.MLPipeline;
1413
import hasco.gui.statsplugin.HASCOModelStatisticsPlugin;
14+
import jaicore.basic.TimeOut;
1515
import jaicore.graphvisualizer.plugin.graphview.GraphViewPlugin;
1616
import jaicore.graphvisualizer.plugin.nodeinfo.NodeInfoGUIPlugin;
1717
import jaicore.graphvisualizer.plugin.solutionperformanceplotter.SolutionPerformanceTimelinePlugin;
@@ -48,7 +48,8 @@ public static void main(final String[] args) throws Exception {
4848
mlplan.setNumCPUs(6);
4949

5050
new JFXPanel();
51-
GraphVisualizationWindow window = new GraphVisualizationWindow(mlplan, new GraphViewPlugin(), new NodeInfoGUIPlugin<>(new JaicoreNodeInfoGenerator<>(new TFDNodeInfoGenerator())), new SearchRolloutHistogramPlugin<>(), new SolutionPerformanceTimelinePlugin(), new HASCOModelStatisticsPlugin(), new OutOfSampleErrorPlotPlugin(split.get(0), split.get(1)));
51+
AlgorithmVisualizationWindow window = new AlgorithmVisualizationWindow(mlplan, new GraphViewPlugin(), new NodeInfoGUIPlugin<>(new JaicoreNodeInfoGenerator<>(new TFDNodeInfoGenerator())), new SearchRolloutHistogramPlugin<>(),
52+
new SolutionPerformanceTimelinePlugin(), new HASCOModelStatisticsPlugin(), new OutOfSampleErrorPlotPlugin(split.get(0), split.get(1)));
5253
Platform.runLater(window);
5354

5455
try {

0 commit comments

Comments
 (0)