Use TreeMap to have natural sorting
Create list of Problems from interface
This commit is contained in:
parent
e38111aafd
commit
1f81075aee
@ -10,10 +10,7 @@ import org.reflections.Reflections;
|
|||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Main implements OptimizationStateListener {
|
public class Main implements OptimizationStateListener {
|
||||||
|
|
||||||
@ -77,20 +74,34 @@ public class Main implements OptimizationStateListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Class<? extends InterfaceOptimizer>> createOptimizerList() {
|
public static Map<String, Class<? extends InterfaceOptimizer>> createOptimizerList() {
|
||||||
Map<String, Class<? extends InterfaceOptimizer>> optimizerList = new HashMap<String, Class<? extends InterfaceOptimizer>>();
|
Map<String, Class<? extends InterfaceOptimizer>> optimizerList = new TreeMap<String, Class<? extends InterfaceOptimizer>>();
|
||||||
|
|
||||||
Reflections reflections = new Reflections("eva2.optimization.strategies");
|
Reflections reflections = new Reflections("eva2.optimization.strategies");
|
||||||
Set<Class<? extends InterfaceOptimizer>> optimizers = reflections.getSubTypesOf(InterfaceOptimizer.class);
|
Set<Class<? extends InterfaceOptimizer>> optimizers = reflections.getSubTypesOf(InterfaceOptimizer.class);
|
||||||
for(Class<? extends InterfaceOptimizer> optimizer : optimizers) {
|
for(Class<? extends InterfaceOptimizer> optimizer : optimizers) {
|
||||||
// We only want instantiable classes.
|
// We only want instantiable classes.ya
|
||||||
if(optimizer.isInterface() || Modifier.isAbstract(optimizers.getClass().getModifiers())) {
|
if(optimizer.isInterface() || Modifier.isAbstract(optimizer.getModifiers())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
optimizerList.put(optimizer.getName(), optimizer);
|
optimizerList.put(optimizer.getSimpleName(), optimizer);
|
||||||
}
|
}
|
||||||
return optimizerList;
|
return optimizerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, Class<? extends InterfaceOptimizationProblem>> createProblemList() {
|
||||||
|
Map<String, Class<? extends InterfaceOptimizationProblem>> problemList = new TreeMap<String, Class<? extends InterfaceOptimizationProblem>>();
|
||||||
|
Reflections reflections = new Reflections("eva2.optimization.problems");
|
||||||
|
Set<Class<? extends InterfaceOptimizationProblem>> problems = reflections.getSubTypesOf(InterfaceOptimizationProblem.class);
|
||||||
|
for(Class<? extends InterfaceOptimizationProblem> problem : problems) {
|
||||||
|
// We only want instantiable classes.ya
|
||||||
|
if(problem.isInterface() || Modifier.isAbstract(problem.getModifiers())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
problemList.put(problem.getSimpleName(), problem);
|
||||||
|
}
|
||||||
|
return problemList;
|
||||||
|
}
|
||||||
|
|
||||||
public static void showHelp(Options options) {
|
public static void showHelp(Options options) {
|
||||||
HelpFormatter helpFormatter = new HelpFormatter();
|
HelpFormatter helpFormatter = new HelpFormatter();
|
||||||
helpFormatter.printHelp("eva2", "", options, "", true);
|
helpFormatter.printHelp("eva2", "", options, "", true);
|
||||||
@ -130,12 +141,11 @@ public class Main implements OptimizationStateListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void showProblemHelp() {
|
private static void showProblemHelp() {
|
||||||
System.out.println("Available Problems:");
|
Map<String, Class<? extends InterfaceOptimizationProblem>> problemList= createProblemList();
|
||||||
Reflections reflections = new Reflections("eva2.optimization.problems");
|
|
||||||
Set<Class<? extends InterfaceOptimizationProblem>> problemsList = reflections.getSubTypesOf(InterfaceOptimizationProblem.class);
|
|
||||||
for(Class<? extends InterfaceOptimizationProblem> problem : problemsList) {
|
|
||||||
|
|
||||||
System.out.printf("\t%s\n", problem.getSimpleName());
|
System.out.println("Available Problems:");
|
||||||
|
for(String name : problemList.keySet()) {
|
||||||
|
System.out.printf("\t%s\n", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user