Skip to content

Commit

Permalink
Allow use of extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
dhadka committed Dec 1, 2024
1 parent 6a8f57a commit 1013c56
Showing 1 changed file with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.moeaframework.algorithm.Algorithm;
import org.moeaframework.algorithm.AlgorithmException;
import org.moeaframework.algorithm.extension.Extension;
import org.moeaframework.algorithm.extension.Extensions;
import org.moeaframework.core.Solution;
import org.moeaframework.core.population.NondominatedPopulation;
Expand Down Expand Up @@ -72,7 +71,7 @@ public JMetalAlgorithmAdapter(
this.algorithm = algorithm;
this.problem = problem;
this.maxEvaluations = maxEvaluations;
this.extensions = new JMetalExtensions(this);
this.extensions = new Extensions(this);
}

@Override
Expand Down Expand Up @@ -117,7 +116,7 @@ public NondominatedPopulation getResult() {

@Override
public void initialize() {
// do nothing
extensions.onInitialize();
}

@Override
Expand All @@ -134,6 +133,8 @@ public void step() {
} catch (Exception e) {
throw new AlgorithmException(this, e);
}

extensions.onStep();
}
}

Expand All @@ -143,28 +144,17 @@ public boolean isTerminated() {
}

@Override
public void terminate() {
public void terminate() {
if (solutionSet == null) {
solutionSet = new ArrayList<T>();
}

extensions.onTerminate();
}

@Override
public Extensions getExtensions() {
return extensions;
}

private static class JMetalExtensions extends Extensions {

public JMetalExtensions(Algorithm algorithm) {
super(algorithm);
}

@Override
public void add(Extension extension) {
throw new UnsupportedOperationException("JMetal does not support extensions");
}

}

}

0 comments on commit 1013c56

Please sign in to comment.