diff --git a/corehunter-base/src/main/java/org/corehunter/API.java b/corehunter-base/src/main/java/org/corehunter/API.java index 9af01dc3..458a8034 100644 --- a/corehunter-base/src/main/java/org/corehunter/API.java +++ b/corehunter-base/src/main/java/org/corehunter/API.java @@ -379,6 +379,54 @@ public static CoreHunterArguments createArguments(CoreHunterData data, int size, /* Execution */ /* --------- */ + /** + * Get normalization ranges of all objectives in a multi-objective configuration. + * Executes a preliminary random descent search per objective (in parallel) to approximate the + * best solution in terms of each included objective. For an objective that is being maximized, + * the upper bound is set to the value of the best solution for that objective, while the lower + * bound is set to the Pareto minimum, i.e. the minimum value obtained when evaluating all optimal + * solutions with the considered objective. For an objective that is being minimized, the roles + * of minimum and maximum are interchanged. + * + * @param args Core Hunter arguments including data, objectives and subset size. + * @param mode Execution mode, one of "default" or "fast". Only affects the default + * stop conditions, not the used algorithm (always random descent). + * @param timeLimit Absolute runtime limit in seconds. + * If set to a negative value no time limit is used. + * @param maxTimeWithoutImprovement Maximum time without finding an improvement, in seconds. + * If set to a negative value, the default improvement time of + * the chosen execution mode is used: 10 seconds in default mode, + * 2 seconds in fast mode. + * @return Matrix containing normalization ranges. + * One row per objective, and two columns with lower and upper bound, respectively. + */ + public static double[][] getNormalizationRanges(CoreHunterArguments args, String mode, + int timeLimit, int maxTimeWithoutImprovement){ + // interpret arguments + CoreHunterExecutionMode exMode = CoreHunterExecutionMode.DEFAULT; + if (mode.equals("fast")) { + exMode = CoreHunterExecutionMode.FAST; + } + // create Core Hunter executor + CoreHunter ch = new CoreHunter(exMode); + if (timeLimit > 0) { + ch.setTimeLimit(1000 * timeLimit); // convert to milliseconds + } + if (maxTimeWithoutImprovement > 0) { + ch.setMaxTimeWithoutImprovement(1000 * maxTimeWithoutImprovement); // convert to milliseconds + } + // determine ranges + List> rangeList = ch.normalize(args); + // convert result + double[][] ranges = new double[rangeList.size()][2]; + for(int o = 0; o < rangeList.size(); o++){ + Range range = rangeList.get(o); + ranges[o][0] = range.getLower(); + ranges[o][1] = range.getUpper(); + } + return ranges; + } + /** * Sample a core collection. * @@ -388,8 +436,8 @@ public static CoreHunterArguments createArguments(CoreHunterData data, int size, * If set to a negative value no time limit is used. * @param maxTimeWithoutImprovement Maximum time without finding an improvement, in seconds. * If set to a negative value, the default improvement time of - * the chosen execution mode is used: 5 seconds in default mode, - * 1 second in fast mode. + * the chosen execution mode is used: 10 seconds in default mode, + * 2 seconds in fast mode. * @param silent If true no output is written to the console. * @return Indices of selected items (zero-based). */ diff --git a/corehunter-base/src/main/java/org/corehunter/listener/SimpleCoreHunterListener.java b/corehunter-base/src/main/java/org/corehunter/listener/SimpleCoreHunterListener.java index d0b1461a..e38ac555 100644 --- a/corehunter-base/src/main/java/org/corehunter/listener/SimpleCoreHunterListener.java +++ b/corehunter-base/src/main/java/org/corehunter/listener/SimpleCoreHunterListener.java @@ -72,7 +72,7 @@ public void newBestSolution(Search search, SubsetSolution newBestSolution, Evaluation newBestSolutionEvaluation, Validation newBestSolutionValidation) { - printStream.format("%sValue: %f%n", prefix, newBestSolutionEvaluation.getValue()); + printStream.format("%sCurrent value: %f%n", prefix, newBestSolutionEvaluation.getValue()); } @Override