Skip to content

Commit

Permalink
extended API: separate method for normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
hdbeukel committed Aug 18, 2016
1 parent 2af5cf4 commit a6199f5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
52 changes: 50 additions & 2 deletions corehunter-base/src/main/java/org/corehunter/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Range<Double>> rangeList = ch.normalize(args);
// convert result
double[][] ranges = new double[rangeList.size()][2];
for(int o = 0; o < rangeList.size(); o++){
Range<Double> range = rangeList.get(o);
ranges[o][0] = range.getLower();
ranges[o][1] = range.getUpper();
}
return ranges;
}

/**
* Sample a core collection.
*
Expand All @@ -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 <code>true</code> no output is written to the console.
* @return Indices of selected items (zero-based).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void newBestSolution(Search<? extends SubsetSolution> 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
Expand Down

0 comments on commit a6199f5

Please sign in to comment.